Module: Ooor::ReflectionOoor::ClassMethods
- Defined in:
- lib/ooor/reflection_ooor.rb
Instance Method Summary collapse
- #columns_hash(view_fields = nil) ⇒ Object
- #create_reflection(name) ⇒ Object
- #reflect_on_association(association) ⇒ Object
Instance Method Details
#columns_hash(view_fields = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ooor/reflection_ooor.rb', line 14 def columns_hash(view_fields=nil) if view_fields || !@t.columns_hash view_fields ||= {} reload_fields_definition() @t.columns_hash ||= {} @t.fields.each do |k, field| unless @t.associations_keys.index(k) @t.columns_hash[k] = field.merge({type: to_rails_type(view_fields[k] && view_fields[k]['type'] || field['type'])}) end end @t.columns_hash else @t.columns_hash end end |
#create_reflection(name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ooor/reflection_ooor.rb', line 30 def create_reflection(name) reload_fields_definition() = {} if many2one_associations.keys.include?(name) macro = :belongs_to relation = many2one_associations[name]['relation'] #TODO prefix? const_get(relation) [:class_name] = relation #TODO or pass it camelized already? elsif many2many_associations.keys.include?(name) macro = :has_and_belongs_to_many elsif one2many_associations.keys.include?(name) macro = :has_many end reflection = Reflection::AssociationReflection.new(macro, name, , nil)#active_record) #TODO active_record? # case macro # when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many # klass = options[:through] ? ThroughReflection : AssociationReflection # reflection = klass.new(macro, name, options, active_record) # when :composed_of # reflection = AggregateReflection.new(macro, name, options, active_record) # end self.reflections = self.reflections.merge(name => reflection) reflection end |
#reflect_on_association(association) ⇒ Object
56 57 58 59 60 |
# File 'lib/ooor/reflection_ooor.rb', line 56 def reflect_on_association(association) reflections[association] ||= create_reflection(association.to_s).tap do |reflection| reflection.connection = connection end end |