Class: OData::AbstractQuery::Options::ExpandOption

Inherits:
OData::AbstractQuery::Option show all
Defined in:
lib/o_data/abstract_query/options/expand_option.rb

Instance Attribute Summary collapse

Attributes inherited from BasicOption

#key, #query

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OData::AbstractQuery::Option

#applies_to?, #option_name

Methods inherited from BasicOption

#inspect, #option_name

Constructor Details

#initialize(query, navigation_property_paths = {}, navigation_property_paths_str = nil) ⇒ ExpandOption

TODO: remove navigation_property_paths_str



12
13
14
15
16
17
# File 'lib/o_data/abstract_query/options/expand_option.rb', line 12

def initialize(query, navigation_property_paths = {}, navigation_property_paths_str = nil)
  @navigation_property_paths = navigation_property_paths
  @navigation_property_paths_str = navigation_property_paths_str
  
  super(query, self.class.option_name)
end

Instance Attribute Details

Returns the value of attribute navigation_property_paths.



9
10
11
# File 'lib/o_data/abstract_query/options/expand_option.rb', line 9

def navigation_property_paths
  @navigation_property_paths
end

Returns the value of attribute navigation_property_paths_str.



9
10
11
# File 'lib/o_data/abstract_query/options/expand_option.rb', line 9

def navigation_property_paths_str
  @navigation_property_paths_str
end

Class Method Details

.applies_to?(query) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/o_data/abstract_query/options/expand_option.rb', line 19

def self.applies_to?(query)
  return false if query.segments.empty?
  (query.segments.last.is_a?(OData::AbstractQuery::Segments::CollectionSegment) || query.segments.last.is_a?(OData::AbstractQuery::Segments::NavigationPropertySegment))
end

.option_nameObject



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

def self.option_name
  '$expand'
end

.parse!(query, key, value = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/o_data/abstract_query/options/expand_option.rb', line 24

def self.parse!(query, key, value = nil)
  return nil unless key == self.option_name
  
  if query.segments.last.respond_to?(:navigation_property)
    navigation_property = query.segments.last.navigation_property
    
    raise OData::AbstractQuery::Errors::InvalidOptionValue.new(query, self.option_name) if navigation_property.to_end.polymorphic?
  end
  
  if query.segments.last.respond_to?(:entity_type)
    entity_type = query.segments.last.entity_type
    
    navigation_property_paths = value.to_s.split(/\s*,\s*/).inject({}) { |acc, path| 
      segments = path.split('/')
      reflect_on_navigation_property_path(query, acc, entity_type, segments.shift, segments)
      acc
    }
    
    query.Option(self, navigation_property_paths, value.to_s)
  else
    raise OData::AbstractQuery::Errors::InvalidOptionContext.new(query, self.option_name) unless value.blank?
  end
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/o_data/abstract_query/options/expand_option.rb', line 48

def valid?
  # TODO: replace with validation
  true
end

#valueObject



53
54
55
# File 'lib/o_data/abstract_query/options/expand_option.rb', line 53

def value
  "'" + @navigation_property_paths_str.gsub(/\s+/, '') + "'"
end