multirow_counter 0.0.1 → 0.0.2

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.
@@ -17,11 +17,11 @@ module MultirowCounter
17
17
  define_method("multirow_counter_#{counter_name}", &getter)
18
18
 
19
19
  # define increment method
20
- define_method("increment_#{counter_name}") do
20
+ define_method("increment_#{counter_name}") do |incr = 1|
21
21
  counter_relation = const.where(class_name.foreign_key => id)
22
22
  randomly_selected_counter_row = rand(num_rows) + 1
23
23
 
24
- counter_relation.where(:counter_id => randomly_selected_counter_row).limit(1).update_all("value = value+1")
24
+ counter_relation.where(:counter_id => randomly_selected_counter_row).limit(1).update_all("value = value+#{Integer(incr)}")
25
25
  end
26
26
  end
27
27
  end
@@ -23,6 +23,11 @@ describe MultirowCounter do
23
23
  assert_equal 10, @shop.version
24
24
  end
25
25
 
26
+ it "supports batch increments" do
27
+ @shop.increment_version(10)
28
+ assert_equal 10, @shop.version
29
+ end
30
+
26
31
  it "should not send all increments to the same row" do
27
32
  10.times { @shop.increment_version }
28
33
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multirow_counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-16 00:00:00.000000000 Z
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2158458500 !ruby/object:Gem::Requirement
16
+ requirement: &2180916380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2158458500
24
+ version_requirements: *2180916380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mysql2
27
- requirement: &2158458060 !ruby/object:Gem::Requirement
27
+ requirement: &2180915820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2158458060
35
+ version_requirements: *2180915820
36
36
  description: Typically SQL is not a great place to store a counter that is incremented
37
37
  often. For instance if you're counting the number of visits to a page by incrementing
38
38
  a SQL column and that page gets popular then there's a good chance that the SQL