Sha256: d7ebe9bdce3355c36f72dca5a601048c2aae69ba984146a8dd2c4ac22d6d8a60
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
module Lolita module Configuration module Factory class Field class << self # There are three ways to add field. # *<tt>first</tt> - Pass name and type # Field.add(dbi,"name","type") # *<tt>second</tt> - Pass it through hash # Field.add(dbi,:name => "name", :type => "type") # *<tt>third</tt> - Pass dbi_field # Field.add(dbi,:dbi_field => dbi.fields.first) 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 alias :add :create def detect_association(dbi,name) dbi.associations[name.to_sym] end def field_class(name) ("Lolita::Configuration::Field::"+name.to_s.camelize).constantize end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lolita-3.2.0.rc.10 | lib/lolita/configuration/factory/field.rb |
lolita-3.2.0.rc.9 | lib/lolita/configuration/factory/field.rb |