Class: OData::AbstractQuery::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/o_data/abstract_query/segment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, value) ⇒ Segment

Returns a new instance of Segment.



14
15
16
17
18
19
# File 'lib/o_data/abstract_query/segment.rb', line 14

def initialize(query, value)
  @query = query
  @value = value
  
  raise Errors::InvalidSegmentContext.new(@query, self) unless can_follow?(@query.segments.last)
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



4
5
6
# File 'lib/o_data/abstract_query/segment.rb', line 4

def query
  @query
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/o_data/abstract_query/segment.rb', line 4

def value
  @value
end

Class Method Details

.can_follow?(anOtherSegment) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/o_data/abstract_query/segment.rb', line 21

def self.can_follow?(anOtherSegment)
  # self (Segment class) can_follow? anOtherSegment (instance of Segment class)
  false
end

.parse!(query, str) ⇒ Object



6
7
8
# File 'lib/o_data/abstract_query/segment.rb', line 6

def self.parse!(query, str)
  nil
end

.segment_nameObject



10
11
12
# File 'lib/o_data/abstract_query/segment.rb', line 10

def self.segment_name
  name.to_s.demodulize.sub(/Segment$/, '')
end

Instance Method Details

#can_follow?(anOtherSegment) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/o_data/abstract_query/segment.rb', line 26

def can_follow?(anOtherSegment)
  self.class.can_follow?(anOtherSegment)
end

#execute!(acc) ⇒ Object



30
31
32
# File 'lib/o_data/abstract_query/segment.rb', line 30

def execute!(acc)
  acc
end

#inspectObject



34
35
36
# File 'lib/o_data/abstract_query/segment.rb', line 34

def inspect
  "#<< #{@query.schema.namespace.to_s}(#{self.class.segment_name}: #{self.value.inspect}) >>"
end

#valid?(results) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/o_data/abstract_query/segment.rb', line 38

def valid?(results)
  !results.blank?
end