diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/algebra/attributes/attribute.rb | 152 |
1 files changed, 116 insertions, 36 deletions
diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb index 64ea93d227..30e26f7584 100644 --- a/lib/arel/algebra/attributes/attribute.rb +++ b/lib/arel/algebra/attributes/attribute.rb @@ -82,44 +82,124 @@ module Arel include Congruence module Predications - methods = { - :eq => "Equality", - :not_eq => "Inequality", - :lt => "LessThan", - :lteq => "LessThanOrEqualTo", - :gt => "GreaterThan", - :gteq => "GreaterThanOrEqualTo", - :matches => "Match", - :not_matches => "NotMatch", - :in => "In", - :not_in => "NotIn" - } - - def self.predication(name, klass) - methods = { - :operator => " - def #{name}(other) - Predicates::#{klass}.new(self, other) - end - ", - :any => " - def #{name}_any(*others) - Predicates::Any.build(Predicates::#{klass}, self, *others) - end - ", - :all => " - def #{name}_all(*others) - Predicates::All.build(Predicates::#{klass}, self, *others) - end - " - } - [:operator, :any, :all].each do |method_name| - module_eval methods[method_name], __FILE__, __LINE__ - end + def eq(other) + Predicates::Equality.new(self, other) + end + + def eq_any(*others) + Predicates::Any.build(Predicates::Equality, self, *others) + end + + def eq_all(*others) + Predicates::All.build(Predicates::Equality, self, *others) + end + + def not_eq(other) + Predicates::Inequality.new(self, other) + end + + def not_eq_any(*others) + Predicates::Any.build(Predicates::Inequality, self, *others) + end + + def not_eq_all(*others) + Predicates::All.build(Predicates::Inequality, self, *others) + end + + def lt(other) + Predicates::LessThan.new(self, other) + end + + def lt_any(*others) + Predicates::Any.build(Predicates::LessThan, self, *others) + end + + def lt_all(*others) + Predicates::All.build(Predicates::LessThan, self, *others) + end + + def lteq(other) + Predicates::LessThanOrEqualTo.new(self, other) + end + + def lteq_any(*others) + Predicates::Any.build(Predicates::LessThanOrEqualTo, self, *others) + end + + def lteq_all(*others) + Predicates::All.build(Predicates::LessThanOrEqualTo, self, *others) + end + + def gt(other) + Predicates::GreaterThan.new(self, other) + end + + def gt_any(*others) + Predicates::Any.build(Predicates::GreaterThan, self, *others) + end + + def gt_all(*others) + Predicates::All.build(Predicates::GreaterThan, self, *others) + end + + def gteq(other) + Predicates::GreaterThanOrEqualTo.new(self, other) + end + + def gteq_any(*others) + Predicates::Any.build(Predicates::GreaterThanOrEqualTo, self, *others) + end + + def gteq_all(*others) + Predicates::All.build(Predicates::GreaterThanOrEqualTo, self, *others) + end + + def matches(other) + Predicates::Match.new(self, other) + end + + def matches_any(*others) + Predicates::Any.build(Predicates::Match, self, *others) + end + + def matches_all(*others) + Predicates::All.build(Predicates::Match, self, *others) + end + + def not_matches(other) + Predicates::NotMatch.new(self, other) + end + + def not_matches_any(*others) + Predicates::Any.build(Predicates::NotMatch, self, *others) + end + + def not_matches_all(*others) + Predicates::All.build(Predicates::NotMatch, self, *others) + end + + def in(other) + Predicates::In.new(self, other) + end + + def in_any(*others) + Predicates::Any.build(Predicates::In, self, *others) + end + + def in_all(*others) + Predicates::All.build(Predicates::In, self, *others) + end + + def not_in(other) + Predicates::NotIn.new(self, other) + end + + def not_in_any(*others) + Predicates::Any.build(Predicates::NotIn, self, *others) end - methods.each_pair do |method_name, class_name| - predication(method_name, class_name) + def not_in_all(*others) + Predicates::All.build(Predicates::NotIn, self, *others) end end include Predications |