Module: PadrinoFields::DataMapperWrapper::ClassMethods
- Defined in:
- lib/padrino-fields/orms/datamapper.rb
Instance Attribute Summary collapse
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
Instance Method Summary collapse
- #form_attribute_is_required?(attribute) ⇒ Boolean
- #form_attribute_validators ⇒ Object
- #form_column_type_for(attribute) ⇒ Object
- #form_has_required_attributes?(reflection = nil) ⇒ Boolean
- #form_reflection_validators(reflection = nil) ⇒ Object
- #form_validators_on(attribute) ⇒ Object
Instance Attribute Details
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
8 9 10 |
# File 'lib/padrino-fields/orms/datamapper.rb', line 8 def reflection @reflection end |
Instance Method Details
#form_attribute_is_required?(attribute) ⇒ Boolean
16 17 18 |
# File 'lib/padrino-fields/orms/datamapper.rb', line 16 def form_attribute_is_required?(attribute) form_validators_on(attribute).find_all {|v| v.class == DataMapper::Validations::PresenceValidator }.any? end |
#form_attribute_validators ⇒ Object
10 |
# File 'lib/padrino-fields/orms/datamapper.rb', line 10 def form_attribute_validators; validators.contexts[:default]; end |
#form_column_type_for(attribute) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/padrino-fields/orms/datamapper.rb', line 30 def form_column_type_for(attribute) klass = properties.find_all {|p| p.name == attribute}.first.class if klass == DataMapper::Property::String :string elsif klass == DataMapper::Property::Text :text elsif [DataMapper::Property::Integer,DataMapper::Property::Decimal,DataMapper::Property::Float].include?(klass) :number elsif klass == DataMapper::Property::Boolean :boolean elsif [DataMapper::Property::Date,DataMapper::Property::DateTime].include?(klass) :date elsif klass == DataMapper::Property::Serial :serial else nil end end |
#form_has_required_attributes?(reflection = nil) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/padrino-fields/orms/datamapper.rb', line 24 def form_has_required_attributes?(reflection=nil) validators = form_attribute_validators validators += reflection_validators(reflection) if reflection validators.find_all {|v| v.class == DataMapper::Validations::PresenceValidator }.any? end |
#form_reflection_validators(reflection = nil) ⇒ Object
20 21 22 |
# File 'lib/padrino-fields/orms/datamapper.rb', line 20 def form_reflection_validators(reflection=nil) new.send(reflection).validators.contexts[:default] end |
#form_validators_on(attribute) ⇒ Object
12 13 14 |
# File 'lib/padrino-fields/orms/datamapper.rb', line 12 def form_validators_on(attribute) validators.contexts[:default].find_all {|v| v.field_name == attribute} end |