Class: OData::AbstractSchema::EntityType

Inherits:
SchemaObject show all
Defined in:
lib/o_data/abstract_schema/entity_type.rb

Direct Known Subclasses

OData::ActiveRecordSchema::EntityType

Instance Attribute Summary collapse

Attributes inherited from SchemaObject

#name, #schema

Instance Method Summary collapse

Methods inherited from SchemaObject

#<=>, #plural_name, #qualified_name, #singular_name

Methods included from Comparable

#compare, #sort

Constructor Details

#initialize(schema, name) ⇒ EntityType

Returns a new instance of EntityType.



8
9
10
11
12
13
14
15
# File 'lib/o_data/abstract_schema/entity_type.rb', line 8

def initialize(schema, name)
  super(schema, name)

  @properties = []
  @key_property = nil

  @navigation_properties = []
end

Instance Attribute Details

#key_propertyObject

Returns the value of attribute key_property.



17
18
19
# File 'lib/o_data/abstract_schema/entity_type.rb', line 17

def key_property
  @key_property
end

Returns the value of attribute navigation_properties.



6
7
8
# File 'lib/o_data/abstract_schema/entity_type.rb', line 6

def navigation_properties
  @navigation_properties
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

Instance Method Details

#exists?(key_value) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/o_data/abstract_schema/entity_type.rb', line 46

def exists?(key_value)
  !!find_one(key_value)
end

#find_all(key_values = {}) ⇒ Object



37
38
39
# File 'lib/o_data/abstract_schema/entity_type.rb', line 37

def find_all(key_values = {})
  []
end

#find_one(key_value) ⇒ Object



41
42
43
44
# File 'lib/o_data/abstract_schema/entity_type.rb', line 41

def find_one(key_value)
  return nil if @key_property.blank?
  find_all(@key_property => key_value).first
end

#href_for(one) ⇒ Object



50
51
52
# File 'lib/o_data/abstract_schema/entity_type.rb', line 50

def href_for(one)
  collection_name + '(' + primary_key_for(one) + ')'
end

#inspectObject



59
60
61
# File 'lib/o_data/abstract_schema/entity_type.rb', line 59

def inspect
  "#<< #{qualified_name.to_s}(#{[@properties, @navigation_properties].flatten.collect { |p| "#{p.name.to_s}: #{p.return_type.to_s}" }.join(', ')}) >>"
end


31
32
33
34
35
# File 'lib/o_data/abstract_schema/entity_type.rb', line 31

def NavigationProperty(*args)
  navigation_property = NavigationProperty.new(self.schema, self, *args)
  @navigation_properties << navigation_property
  navigation_property
end

#primary_key_for(one) ⇒ Object



54
55
56
57
# File 'lib/o_data/abstract_schema/entity_type.rb', line 54

def primary_key_for(one)
  return nil if @key_property.blank?
  @key_property.value_for(one)
end

#Property(*args) ⇒ Object



25
26
27
28
29
# File 'lib/o_data/abstract_schema/entity_type.rb', line 25

def Property(*args)
  property = Property.new(self.schema, self, *args)
  @properties << property
  property
end