lib/para/attribute_field/base.rb in para-0.4.0 vs lib/para/attribute_field/base.rb in para-0.5.0

- old
+ new

@@ -1,9 +1,10 @@ module Para module AttributeField class Base class_attribute :_field_options + cattr_accessor :_field_types attr_reader :model, :name, :type, :field_type, :field_method def self.field_option(key, method_name, options = {}) self._field_options ||= [] @@ -13,10 +14,33 @@ method_name: method_name, options: options }] end + # Registers the class as the responder for a given field type + # + # Example : + # + # # This will allow looking :my_field or :myfield up and instantiate + # # self as the field + # class MyField < Para::AttributeField::Base + # register :my_field, :myfield, self + # end + # + # + def self.register(*args) + attribute_class = args.pop + + args.each do |arg| + Base.field_types[arg] = attribute_class + end + end + + def self.field_types + @_field_types ||= {} + end + field_option :as, :field_type_name def initialize(model, options = {}) @model = model @name = options[:name] @@ -63,9 +87,13 @@ name end def attribute_column_path [name] + end + + def type?(type) + self.type.to_s == type.to_s end private def field_type_name