class Lolita::Configuration::Factory::Field
Public Class Methods
create(dbi,*args,&block)
click to toggle source
There are three ways to add field. *first
- Pass name and type
Field.add(dbi,"name","type")
*second
- Pass it through hash
Field.add(dbi,:name => "name", :type => "type")
*third
- Pass dbi_field
Field.add(dbi,:dbi_field => dbi.fields.first)
# File lib/lolita/configuration/factory/field.rb, line 13 def create(dbi,*args,&block) options = args ? args.extract_options! : {} dbi_field = options[:dbi_field] name = args[0] || options[:name] || (dbi_field ? dbi_field.name : nil) dbi_field ||= dbi.field_by_name(name) dbi_field ||= dbi.field_by_association(name) association ||= detect_association(dbi,name) type = args[1] || options[:type] || (association ? :array : nil ) || (dbi_field ? dbi_field.type : nil) || :string options[:dbi_field] = dbi_field if !name || !type raise Lolita::FieldTypeError, "type not defined. Set is as second argument or as :dbi_field where value is Adapter::[ORM]::Field object." else field_class(type).new(dbi,name,type,options,&block) end end
Also aliased as: add
detect_association(dbi,name)
click to toggle source
# File lib/lolita/configuration/factory/field.rb, line 37 def detect_association(dbi,name) dbi.associations[name.to_s] end
field_class(name)
click to toggle source
# File lib/lolita/configuration/factory/field.rb, line 41 def field_class(name) ("Lolita::Configuration::Field::"+name.to_s.camelize).constantize end