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
|