activerecord-refinements 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,42 +8,31 @@ module ActiveRecord
8
8
  end
9
9
  end
10
10
 
11
- class WhereBlockEvaluator
12
- using ActiveRecord::Refinements::WhereBlockSyntax
13
-
14
- def initialize(table)
15
- @table = table
16
- end
17
-
18
- def evaluate(&block)
19
- col, op, val = instance_eval &block
20
- case op
21
- when :==
22
- @table[col].eq val
23
- when :!=
24
- @table[col].not_eq val
25
- when :=~
26
- @table[col].matches val
27
- when :>
28
- @table[col].gt val
29
- when :>=
30
- @table[col].gteq val
31
- when :<
32
- @table[col].lt val
33
- when :<=
34
- @table[col].lteq val
35
- else
36
- raise "unexpected op: #{op}"
37
- end
38
- end
39
- end
40
-
41
11
  module QueryMethods
42
12
  def where(opts = nil, *rest, &block)
43
13
  if block
44
- evaluator = ActiveRecord::Refinements::WhereBlockEvaluator.new(table)
14
+ col, op, val = Module.new { using ActiveRecord::Refinements::WhereBlockSyntax }.module_eval &block
15
+ arel_node = case op
16
+ when :==
17
+ table[col].eq val
18
+ when :!=
19
+ table[col].not_eq val
20
+ when :=~
21
+ table[col].matches val
22
+ when :>
23
+ table[col].gt val
24
+ when :>=
25
+ table[col].gteq val
26
+ when :<
27
+ table[col].lt val
28
+ when :<=
29
+ table[col].lteq val
30
+ else
31
+ raise "unexpected op: #{op}"
32
+ end
33
+
45
34
  clone.tap do |relation|
46
- relation.where_values += build_where(evaluator.evaluate(&block))
35
+ relation.where_values += build_where(arel_node)
47
36
  end
48
37
  else
49
38
  super
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module Refinements
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-28 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord