Module: Ooor::ReflectionOoor::ClassMethods

Defined in:
lib/ooor/reflection_ooor.rb

Instance Method Summary collapse

Instance Method Details

#columns_hash(view_fields = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ooor/reflection_ooor.rb', line 26

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ooor/reflection_ooor.rb', line 42

def create_reflection(name)
  reload_fields_definition()
  options = {}
  relation = all_fields[name]['relation']
  options[:class_name] = relation
  if many2one_associations.keys.include?(name)
    macro = :belongs_to
  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, options, nil)#active_record) #TODO active_record?
  self.reflections = self.reflections.merge(name => reflection)
  reflection
end

#reflect_on_association(association) ⇒ Object



59
60
61
62
63
# File 'lib/ooor/reflection_ooor.rb', line 59

def reflect_on_association(association)
  reflections[association] ||= create_reflection(association.to_s).tap do |reflection|
    reflection.session = session
  end
end

#reflectionsObject



18
19
20
# File 'lib/ooor/reflection_ooor.rb', line 18

def reflections
  @reflections ||= {}
end

#reflections=(reflections) ⇒ Object



22
23
24
# File 'lib/ooor/reflection_ooor.rb', line 22

def reflections=(reflections)
  @reflections = reflections
end