Class: ParamsReady::Query::PredicateRegistry

Inherits:
Object
  • Object
show all
Extended by:
Extensions::Registry
Defined in:
lib/params_ready/query/predicate.rb

Class Method Summary collapse

Methods included from Extensions::Registry

human_string, registry

Class Method Details

.find_operator(identifier, format, collision_check) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/params_ready/query/predicate.rb', line 175

def self.find_operator(identifier, format, collision_check)
  operator = operator_by(identifier, format)
  if operator.nil?
    name_as_string = identifier.to_s
    invertor = if format.alternative?
      'n_'
    else
      'not_'
    end
    if !collision_check && name_as_string.start_with?(invertor)
      bare_name = name_as_string[invertor.length..-1].to_sym
      inverted = PredicateRegistry.operator(bare_name, format)
      if inverted.nil?
        nil
      elsif inverted.inverse_of.nil?
        Not.new(inverted)
      else
        operator(inverted.inverse_of, format)
      end
    else
      nil
    end
  else
    operator
  end
end

.operator(identifier, format, collision_check = false) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/params_ready/query/predicate.rb', line 166

def self.operator(identifier, format, collision_check = false)
  operator = find_operator(identifier, format, collision_check)
  if operator.nil? && !collision_check
    raise("No such operator: #{identifier}")
  end

  operator
end

.operator_by(identifier, format) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/params_ready/query/predicate.rb', line 158

def self.operator_by(identifier, format)
  if format.alternative?
    @@operator_alt_names[identifier]
  else
    @@operator_names[identifier]
  end
end