Class: Lolita::Configuration::Factory::Field
- Defined in:
- lib/lolita/configuration/factory/field.rb
Class Method Summary collapse
-
.create(dbi, *args, &block) ⇒ Object
(also: add)
There are three ways to add field.
- .detect_association(dbi, name) ⇒ Object
- .field_class(name) ⇒ Object
Class Method Details
.create(dbi, *args, &block) ⇒ Object Also known as: add
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lolita/configuration/factory/field.rb', line 13 def create(dbi,*args,&block) = args ? args. : {} dbi_field = [:dbi_field] name = args[0] || [: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] || [:type] || (association ? :array : nil ) || (dbi_field ? dbi_field.type : nil) || :string [: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,,&block) end end |
.detect_association(dbi, name) ⇒ Object
37 38 39 |
# File 'lib/lolita/configuration/factory/field.rb', line 37 def detect_association(dbi,name) dbi.associations[name.to_s] end |
.field_class(name) ⇒ Object
41 42 43 |
# File 'lib/lolita/configuration/factory/field.rb', line 41 def field_class(name) ("Lolita::Configuration::Field::"+name.to_s.camelize).constantize end |