Class: OData::Association::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/odata/association/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(entity) ⇒ Proxy

Returns a new instance of Proxy.



4
5
6
# File 'lib/odata/association/proxy.rb', line 4

def initialize(entity)
  @entity = entity
end

Instance Method Details

#[](association_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/odata/association/proxy.rb', line 8

def [](association_name)
  if associations[association_name].nil?
    raise ArgumentError, "unknown association: #{association_name}"
  elsif entity.links[association_name].nil?
    association = associations[association_name]
    association_end = association.ends.select {|details| details.entity_type != "#{namespace}.#{entity_type}"}.first
    raise RuntimeError, 'association ends undefined' if association_end.nil?
    if association_end.multiplicity == :many
      []
    else
      nil
    end
  else
    association_results(association_name)
  end
end

#sizeObject



25
26
27
# File 'lib/odata/association/proxy.rb', line 25

def size
  associations.size
end