Class: OData::AbstractQuery::Segments::LinksSegment

Inherits:
OData::AbstractQuery::Segment show all
Includes:
Countable
Defined in:
lib/o_data/abstract_query/segments/links_segment.rb

Instance Attribute Summary

Attributes inherited from OData::AbstractQuery::Segment

#query, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Countable

included

Methods inherited from OData::AbstractQuery::Segment

#can_follow?, #inspect

Constructor Details

#initialize(query) ⇒ LinksSegment

Returns a new instance of LinksSegment.



21
22
23
# File 'lib/o_data/abstract_query/segments/links_segment.rb', line 21

def initialize(query)
  super(query, self.class.segment_name)
end

Class Method Details

.can_follow?(anOtherSegment) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/o_data/abstract_query/segments/links_segment.rb', line 25

def self.can_follow?(anOtherSegment)
  if anOtherSegment.is_a?(Class)
    anOtherSegment == CollectionSegment || anOtherSegment == NavigationPropertySegment
  else
    (anOtherSegment.is_a?(CollectionSegment) || anOtherSegment.is_a?(NavigationPropertySegment)) # && anOtherSegment.countable?
  end
end

.countable?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/o_data/abstract_query/segments/links_segment.rb', line 17

def self.countable?
  true
end

.parse!(query, str) ⇒ Object



7
8
9
10
11
# File 'lib/o_data/abstract_query/segments/links_segment.rb', line 7

def self.parse!(query, str)
  return nil unless str.to_s == segment_name

  query.Segment(self)
end

.segment_nameObject



13
14
15
# File 'lib/o_data/abstract_query/segments/links_segment.rb', line 13

def self.segment_name
  "$links"
end

Instance Method Details

#execute!(acc) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/o_data/abstract_query/segments/links_segment.rb', line 33

def execute!(acc)
  [acc].flatten.compact.collect { |one|
    if entity_type = self.query.schema.entity_types.find { |et| et.name == one.class.name }
      [one, entity_type.plural_name + '(' + entity_type.primary_key_for(one).to_s + ')']
    else
      [one, nil]
    end
  }
end

#valid?(results) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/o_data/abstract_query/segments/links_segment.rb', line 43

def valid?(results)
  results.all? { |pair| !pair[1].blank? }
end