lib/volt/models/field_helpers.rb in volt-0.9.5.pre3 vs lib/volt/models/field_helpers.rb in volt-0.9.5.pre4
- old
+ new
@@ -34,17 +34,20 @@
module ClassMethods
# field lets you declare your fields instead of using the underscore syntax.
# An optional class restriction can be passed in.
- def field(name, klass = nil, auto_cast = true)
+ def field(name, klass = nil, options = {})
if klass && !VALID_FIELD_CLASSES.include?(klass)
klass_names = VALID_FIELD_CLASSES.map(&:to_s).join(', ')
msg = "valid field types is currently limited to #{klass_names}"
fail FieldHelpers::InvalidFieldClass, msg
end
+ self.fields_data ||= {}
+ self.fields_data[name] = [klass, options]
+
if klass
# Add type validation, execpt for String, since anything can be a string.
unless klass == String
validate name, type: klass
end
@@ -67,8 +70,9 @@
end
end
end
def self.included(base)
+ base.class_attribute :fields_data
base.send :extend, ClassMethods
end
end