Class: ActiveRecord::Refinements::WhereBlockEvaluator
- Inherits:
-
Object
- Object
- ActiveRecord::Refinements::WhereBlockEvaluator
- Defined in:
- lib/activerecord-refinements.rb
Instance Method Summary collapse
- #evaluate(&block) ⇒ Object
-
#initialize(table) ⇒ WhereBlockEvaluator
constructor
A new instance of WhereBlockEvaluator.
Constructor Details
#initialize(table) ⇒ WhereBlockEvaluator
Returns a new instance of WhereBlockEvaluator.
17 18 19 |
# File 'lib/activerecord-refinements.rb', line 17 def initialize(table) @table = table end |
Instance Method Details
#evaluate(&block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/activerecord-refinements.rb', line 21 def evaluate(&block) col, op, val = instance_eval &block case op when :== @table[col].eq val when :!= @table[col].not_eq val when :=~ @table[col].matches val when :> @table[col].gt val when :>= @table[col].gteq val when :< @table[col].lt val when :<= @table[col].lteq val else raise "unexpected op: #{op}" end end |