redtastic 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGFlYTFiMjY1ZmY5NDI3ZjQ5YWJmM2UzMTMyYzFhNGY1NThlNmFiZg==
4
+ YjQ3MDMwNWYyYjA3MDEzMjFlOWEwMmIwODljNTUyYTliOTlkNGQzMw==
5
5
  data.tar.gz: !binary |-
6
- ZmM3MzRmN2UyZWRmOGYzOTkwM2I4NDg1NzcxNWRiNDZlODQ2NmI3MA==
6
+ YmU4MjljYjQxZjRiZDhkMWVhZmViZGM3MDA0YjM1NmE4MTA3NmU3Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjJlMTI2OWQ4YjZiMjg2ZDBhZWYwMGI1NmNiNTI0MGI4NjViMjc2YTc5OWVk
10
- ZGJiYjAzODJmN2E2Y2UxNGJiYWM2ZGNkYWYxNTAwZjFjOGZhZmRkMmQxNmE4
11
- Njg3NGNkOWQwNjQwNDlhNjA0MmRjNDU2YTFhNzg0NjM2NDA3ZTA=
9
+ OGE4ZTVhMzY3MTczN2ZjMjMzY2U5NWZmYzNjZDgzMzA0YjZmMjJhOWJlODQ5
10
+ YmQyMmUxZTQ1ZWQ5OWY2ZmNhZTk4MTliMDhkYjMwNGRmZmJiN2FiOTgwMzFi
11
+ ZGY0ZGRlMjZkMThmYzNjZDNjMThiMmFhMWZlZGYzMDFiMDgwZjM=
12
12
  data.tar.gz: !binary |-
13
- NTIzMTBjOWY5NWNlNGJkMjUxMGNmYjk2NjQ2YzU5OTRmZTQ4OWEwNDRmODkx
14
- NmRkNWZkOTE1MTJiMmVmMmM3MjNiMTNjNDAzNzhhZWQyMDA5YzhiYWMzNTA4
15
- MTExZTI4OGRkYjQzNGU3ZGIyYzc4MDZkYzEyOTgxOTI0NzVhOTc=
13
+ OGE3N2QzNzUxNWUwZTlhNWM2MDlhMzE4MmQ2MDNmYTdjZDA4NjliOTgxN2Yz
14
+ N2ZmNzI2YmI5YTg2NGM3ZjUxYWU4N2QzOTExODAwNTM4NTVlYzQ5NTZhOTdi
15
+ MDliMTViYjM5NjA5OTNmODdmZTEzNzY5ZWZjZmM2YzllYThlZWY=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redtastic (0.2.2)
4
+ redtastic (0.3.0)
5
5
  activesupport
6
6
  redis
7
7
 
@@ -10,7 +10,12 @@ module Redtastic
10
10
  argv << params[:unique_id]
11
11
  Redtastic::ScriptManager.msadd(key_data[0], argv)
12
12
  else
13
- Redtastic::ScriptManager.hmincrby(key_data[0], key_data[1].unshift(1))
13
+ if params[:by].present?
14
+ increment_by = params[:by]
15
+ else
16
+ increment_by = 1
17
+ end
18
+ Redtastic::ScriptManager.hmincrby(key_data[0], key_data[1].unshift(increment_by))
14
19
  end
15
20
  end
16
21
 
@@ -21,7 +26,12 @@ module Redtastic
21
26
  argv << params[:unique_id]
22
27
  Redtastic::ScriptManager.msrem(key_data[0], argv)
23
28
  else
24
- Redtastic::ScriptManager.hmincrby(key_data[0], key_data[1].unshift(-1))
29
+ if params[:by].present?
30
+ decrement_by = params[:by]
31
+ else
32
+ decrement_by = 1
33
+ end
34
+ Redtastic::ScriptManager.hmincrby(key_data[0], key_data[1].unshift(-1*decrement_by))
25
35
  end
26
36
  end
27
37
 
@@ -1,3 +1,3 @@
1
1
  module Redtastic
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
data/spec/model_spec.rb CHANGED
@@ -63,6 +63,18 @@ describe Redtastic::Model do
63
63
  end
64
64
  end
65
65
 
66
+ context 'when specifying the \'by\' parameter' do
67
+ it 'increments the key by the given amount' do
68
+ Visits.increment(timestamp: @timestamp, id: @id, by: 5)
69
+ expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('5')
70
+ end
71
+
72
+ it 'allows for negative increments' do
73
+ Visits.increment(timestamp: @timestamp, id: @id, by: -5)
74
+ expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('-5')
75
+ end
76
+ end
77
+
66
78
  context 'a model with no resolution' do
67
79
  it 'increments the key' do
68
80
  NoResolutions.increment(id: @id)
@@ -85,17 +97,29 @@ describe Redtastic::Model do
85
97
  end
86
98
 
87
99
  describe '#decrement' do
88
- before do
89
- Redtastic::Connection.redis.hset(@day_key, @index, '1')
90
- Visits.decrement(timestamp: @timestamp, id: @id)
91
- end
92
-
93
100
  context 'a model with a resolution' do
101
+ before do
102
+ Redtastic::Connection.redis.hset(@day_key, @index, '1')
103
+ Visits.decrement(timestamp: @timestamp, id: @id)
104
+ end
105
+
94
106
  it 'decrements the key' do
95
107
  expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('0')
96
108
  end
97
109
  end
98
110
 
111
+ context 'when specifying the \'by\' parameter' do
112
+ it 'decrements the key by the given amount' do
113
+ Visits.decrement(timestamp: @timestamp, id: @id, by: 5)
114
+ expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('-5')
115
+ end
116
+
117
+ it 'allows for negative decrements' do
118
+ Visits.decrement(timestamp: @timestamp, id: @id, by: -5)
119
+ expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('5')
120
+ end
121
+ end
122
+
99
123
  context 'a model with no resolution' do
100
124
  before do
101
125
  Redtastic::Connection.redis.hset(@no_resolution_key, @index, '1')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe DiVita