Class: ParamsReady::Query::PredicateOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/params_ready/query/predicate_operator.rb

Direct Known Subclasses

ComparisonPredicateOperator, In

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_operator(name, altn, arel: nil, test: nil, inverse_of: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
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/params_ready/query/predicate_operator.rb', line 10

def self.define_operator(name, altn, arel: nil, test: nil, inverse_of: nil)
  define_singleton_method :name do
    name
  end

  define_singleton_method :altn do
    altn
  end

  if arel
    define_singleton_method :to_query do |attribute, value|
      attribute.send(arel, value)
    end
  end

  if test
    define_singleton_method :test do |record, attribute_name, value|
      attribute = record.send attribute_name
      attribute.send test, value
    end
  end

  define_singleton_method :inverse_of do
    inverse_of
  end

  unless PredicateRegistry.operator(self.name, Format.instance(:backend), true).nil?
    raise ParamsReadyError, "Operator name taken #{self.name}"
  end

  unless PredicateRegistry.operator(self.altn, Format.instance(:frontend), true).nil?
    raise ParamsReadyError, "Operator altn taken #{self.name}"
  end

  PredicateRegistry.register_operator_by_name self
  PredicateRegistry.register_operator_by_alt_name self
end

.dupObject



6
7
8
# File 'lib/params_ready/query/predicate_operator.rb', line 6

def self.dup
  self
end

Instance Method Details

#altnObject



48
49
50
# File 'lib/params_ready/query/predicate_operator.rb', line 48

def altn
  self.class.altn
end