module PadrinoFields::DataMapperWrapper::ClassMethods

Attributes

reflection[R]

Public Instance Methods

form_attribute_is_required?(attribute) click to toggle source
# 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() click to toggle source
# File lib/padrino-fields/orms/datamapper.rb, line 10
def form_attribute_validators; validators.contexts[:default]; end
form_column_type_for(attribute) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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