Class: OData::ActiveRecordSchema::Base

Inherits:
OData::AbstractSchema::Base show all
Defined in:
lib/o_data/active_record_schema/base.rb

Instance Attribute Summary

Attributes inherited from OData::AbstractSchema::Base

#entity_types, #namespace

Instance Method Summary collapse

Methods inherited from OData::AbstractSchema::Base

#Query, #associations, #inspect, #qualify, #to_json

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/o_data/active_record_schema/base.rb', line 12

def initialize(*args)
  super(*args)
  
  Dir.glob(RAILS_ROOT + '/app/models/*.rb').each { |file| require file }
  
  Object.subclasses_of(ActiveRecord::Base).collect { |active_record|
    self.EntityType(active_record, :reflect_on_associations => false)
  }.collect { |entity_type| 
    entity_type.active_record.reflect_on_all_associations.each do |reflection|
      entity_type.NavigationProperty(reflection)
    end
  }
end

Instance Method Details

#Association(*args) ⇒ Object



26
27
28
# File 'lib/o_data/active_record_schema/base.rb', line 26

def Association(*args)
  Association.new(self, *args)
end

#EntityType(*args) ⇒ Object



30
31
32
33
34
# File 'lib/o_data/active_record_schema/base.rb', line 30

def EntityType(*args)
  entity_type = EntityType.new(self, *args)
  self.entity_types << entity_type
  entity_type
end

#find_entity_type(options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/o_data/active_record_schema/base.rb', line 4

def find_entity_type(options = {})
  if options[:active_record]
    self.entity_types.find { |et| et.name == EntityType.name_for(options[:active_record]) }
  else
    super(options)
  end
end