Class: OData::AbstractQuery::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, segments = [], options = []) ⇒ Base

Returns a new instance of Base.



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

def initialize(schema, segments = [], options = [])
  @schema = schema
  
  @segments = segments
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

#segmentsObject (readonly)

Returns the value of attribute segments.



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

def segments
  @segments
end

Instance Method Details

#execute!Object



60
61
62
# File 'lib/o_data/abstract_query/base.rb', line 60

def execute!
  _execute!
end

#inspectObject



14
15
16
# File 'lib/o_data/abstract_query/base.rb', line 14

def inspect
  "#<< #{@schema.namespace.to_s}(#{self.to_uri.inspect}) >>"
end

#Option(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/o_data/abstract_query/base.rb', line 33

def Option(*args)
  option_class = begin
    if args.first.is_a?(Symbol) || args.first.is_a?(String)
      "OData::AbstractQuery::Options::#{args.shift.to_s}Option".constantize
    else
      args.shift
    end
  end
  
  option = option_class.new(self, *args)
  
  @options << option
  option
end

#query_stringObject



52
53
54
# File 'lib/o_data/abstract_query/base.rb', line 52

def query_string
  @options.collect { |o| "#{o.key.to_s}=#{o.value.to_s}" }.join('&')
end

#resource_pathObject



48
49
50
# File 'lib/o_data/abstract_query/base.rb', line 48

def resource_path
  @segments.collect(&:value).join('/')
end

#Segment(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/o_data/abstract_query/base.rb', line 18

def Segment(*args)
  segment_class = begin
    if args.first.is_a?(Symbol) || args.first.is_a?(String)
      "OData::AbstractQuery::Segments::#{args.shift.to_s}Segment".constantize
    else
      args.shift
    end
  end
  
  segment = segment_class.new(self, *args)
  
  @segments << segment
  segment
end

#to_uriObject



56
57
58
# File 'lib/o_data/abstract_query/base.rb', line 56

def to_uri
  [resource_path, query_string].reject(&:blank?).join('?')
end