Class: Garage::NestedFieldQuery::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/garage/nested_field_query.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields = {}) ⇒ Selector

Returns a new instance of Selector.



158
159
160
# File 'lib/garage/nested_field_query.rb', line 158

def initialize(fields = {})
  @fields = fields
end

Class Method Details

.build(fields) ⇒ Object

includes eager loading



142
143
144
145
146
147
148
# File 'lib/garage/nested_field_query.rb', line 142

def self.build(fields)
  if fields.present?
    build_parsed(Parser.parse(fields))
  else
    NestedFieldQuery::DefaultSelector.new
  end
end

.build_parsed(fields) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/garage/nested_field_query.rb', line 150

def self.build_parsed(fields)
  if fields.key? '*'
    FullSelector.new
  else
    self.new(fields)
  end
end

Instance Method Details

#[](name) ⇒ Object



162
163
164
165
166
167
168
# File 'lib/garage/nested_field_query.rb', line 162

def [](name)
  if @fields[name].nil?
    DefaultSelector.new
  else
    Selector.build_parsed(@fields[name])
  end
end

#canonicalObject



170
171
172
# File 'lib/garage/nested_field_query.rb', line 170

def canonical
  Builder.build(@fields)
end

#excludes?(field) ⇒ Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/garage/nested_field_query.rb', line 178

def excludes?(field)
  !@fields.has_key?('__default__') && !@fields.has_key?(field)
end

#includes?(field) ⇒ Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/garage/nested_field_query.rb', line 174

def includes?(field)
  @fields.has_key?(field)
end