activerecord-futures 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ module ActiveRecord
3
3
  include QueryRecording
4
4
 
5
5
  def self.original_calculation_methods
6
- [:count, :average, :minimum, :maximum, :sum, :calculate, :pluck]
6
+ [:count, :average, :minimum, :maximum, :sum, :calculate]
7
7
  end
8
8
 
9
9
  def self.future_calculation_methods
@@ -14,6 +14,12 @@ module ActiveRecord
14
14
  FutureRelation.new(self)
15
15
  end
16
16
 
17
+ def future_pluck(*args, &block)
18
+ exec = lambda { pluck(*args, &block) }
19
+ query = record_query(&exec)
20
+ FutureCalculationArray.new(self, query, exec)
21
+ end
22
+
17
23
  method_table = Hash[future_calculation_methods.zip(original_calculation_methods)]
18
24
 
19
25
  # define a "future_" method for each calculation method
@@ -21,14 +27,8 @@ module ActiveRecord
21
27
  method_table.each do |future_method, method|
22
28
  define_method(future_method) do |*args, &block|
23
29
  exec = lambda { send(method, *args, &block) }
24
- query, type = record_query(&exec)
25
-
26
- case type
27
- when :value
28
- FutureCalculationValue.new(self, query, exec)
29
- when :all
30
- FutureCalculationArray.new(self, query, exec)
31
- end
30
+ query = record_query(&exec)
31
+ FutureCalculationValue.new(self, query, exec)
32
32
  end
33
33
  end
34
34
  end
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  connection = ConnectionProxy.new(@klass.connection)
9
9
  @klass = KlassProxy.new(@klass, connection)
10
10
  yield
11
- [connection.recorded_query, connection.query_type]
11
+ connection.recorded_query
12
12
  ensure
13
13
  @klass = orig_klass
14
14
  end
@@ -31,7 +31,7 @@ module ActiveRecord
31
31
 
32
32
  class ConnectionProxy < Proxy
33
33
  attr_reader :connection
34
- attr_accessor :recorded_query, :query_type
34
+ attr_accessor :recorded_query
35
35
 
36
36
  def initialize(connection)
37
37
  super(connection)
@@ -39,13 +39,11 @@ module ActiveRecord
39
39
  end
40
40
 
41
41
  def select_value(arel, name = nil)
42
- self.query_type = :value
43
42
  self.recorded_query = arel.to_sql
44
43
  nil
45
44
  end
46
45
 
47
46
  def select_all(arel, name = nil, binds = [])
48
- self.query_type = :all
49
47
  self.recorded_query = arel.to_sql
50
48
  []
51
49
  end
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module Futures
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -67,31 +67,31 @@ describe "future_count method" do
67
67
  Comment.create(post: post_2)
68
68
  end
69
69
 
70
- describe "#to_a" do
71
- let(:calling_to_a) { -> { count.to_a } }
70
+ describe "#value" do
71
+ let(:calling_value) { -> { count.value } }
72
72
 
73
73
  specify do
74
- calling_to_a.should exec(1).query
74
+ calling_value.should exec(1).query
75
75
  end
76
76
 
77
77
  specify do
78
- calling_to_a.should exec_query(count_sql)
78
+ calling_value.should exec_query(count_sql)
79
79
  end
80
80
 
81
- specify { count.to_a[post_1.id].should eq 2 }
82
- specify { count.to_a[post_2.id].should eq 3 }
81
+ specify { count.value[post_1.id].should eq 2 }
82
+ specify { count.value[post_2.id].should eq 3 }
83
83
 
84
84
  context "executing it twice" do
85
85
  before do
86
- count.to_a
86
+ count.value
87
87
  end
88
88
 
89
89
  specify do
90
- calling_to_a.should exec(0).queries
90
+ calling_value.should exec(0).queries
91
91
  end
92
92
 
93
- specify { count.to_a[post_1.id].should eq 2 }
94
- specify { count.to_a[post_2.id].should eq 3 }
93
+ specify { count.value[post_1.id].should eq 2 }
94
+ specify { count.value[post_2.id].should eq 3 }
95
95
  end
96
96
  end
97
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-futures
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: 2013-04-30 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord