Class: OData::AbstractQuery::Segments::PropertySegment

Inherits:
EntityTypeSegment show all
Defined in:
lib/o_data/abstract_query/segments/property_segment.rb

Instance Attribute Summary collapse

Attributes inherited from EntityTypeSegment

#entity_type

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, segment_name

Constructor Details

#initialize(query, entity_type, property) ⇒ PropertySegment

Returns a new instance of PropertySegment.



18
19
20
21
22
# File 'lib/o_data/abstract_query/segments/property_segment.rb', line 18

def initialize(query, entity_type, property)
  @property = property

  super(query, entity_type, @property.name)
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



5
6
7
# File 'lib/o_data/abstract_query/segments/property_segment.rb', line 5

def property
  @property
end

Class Method Details

.can_follow?(anOtherSegment) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.parse!(query, str) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/o_data/abstract_query/segments/property_segment.rb', line 7

def self.parse!(query, str)
  return nil if query.segments.empty?
  return nil unless query.segments.last.respond_to?(:entity_type)
  entity_type = query.segments.last.entity_type
  return nil if entity_type.nil?
  property = entity_type.properties.find { |p| p.name == str }
  return nil if property.blank?

  query.Segment(self, entity_type, property)
end

Instance Method Details

#countable?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/o_data/abstract_query/segments/property_segment.rb', line 32

def countable?
  false
end

#execute!(acc) ⇒ Object



36
37
38
39
40
41
# File 'lib/o_data/abstract_query/segments/property_segment.rb', line 36

def execute!(acc)
  # [acc].flatten.compact.collect { |one|
  #   [one, @property.value_for(one)]
  # }
  { @property => @property.value_for([acc].flatten.compact.first) }
end

#valid?(results) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid?(results)
  # results.is_a?(Array)
  !results.blank?
end