Class: OData::AbstractSchema::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/o_data/abstract_query/base.rb,
lib/o_data/abstract_schema/base.rb

Direct Known Subclasses

OData::ActiveRecordSchema::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = "OData") ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/o_data/abstract_schema/base.rb', line 7

def initialize(namespace = "OData")
  @namespace = namespace

  @entity_types = []
end

Instance Attribute Details

#entity_typesObject

Returns the value of attribute entity_types.



5
6
7
# File 'lib/o_data/abstract_schema/base.rb', line 5

def entity_types
  @entity_types
end

#namespaceObject

Returns the value of attribute namespace.



4
5
6
# File 'lib/o_data/abstract_schema/base.rb', line 4

def namespace
  @namespace
end

Instance Method Details

#Association(*args) ⇒ Object



13
14
15
# File 'lib/o_data/abstract_schema/base.rb', line 13

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

#associationsObject



23
24
25
# File 'lib/o_data/abstract_schema/base.rb', line 23

def associations
  @entity_types.collect(&:navigation_properties).flatten.collect(&:association).uniq
end

#EntityType(*args) ⇒ Object



17
18
19
20
21
# File 'lib/o_data/abstract_schema/base.rb', line 17

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

#find_entity_type(options = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/o_data/abstract_schema/base.rb', line 27

def find_entity_type(options = {})
  if options[:name]
    self.entity_types.find { |et| et.name == options[:name].to_s }
  else
    nil
  end
end

#inspectObject



39
40
41
# File 'lib/o_data/abstract_schema/base.rb', line 39

def inspect
  "#<< #{namespace.to_s}(#{@entity_types.collect(&:name).join(', ')}) >>"
end

#qualify(str) ⇒ Object



35
36
37
# File 'lib/o_data/abstract_schema/base.rb', line 35

def qualify(str)
  namespace.to_s + '.' + str.to_s
end

#Query(*args) ⇒ Object



128
129
130
# File 'lib/o_data/abstract_query/base.rb', line 128

def Query(*args)
  OData::AbstractQuery::Base.new(self, *args)
end

#to_jsonObject



43
44
45
# File 'lib/o_data/abstract_schema/base.rb', line 43

def to_json
  { "d" => { "EntitySets" => @entity_types.collect(&:plural_name).sort } }.to_json
end