ohm-tallyable 0.1.3 → 0.1.4
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.
- checksums.yaml +8 -8
- data/.gitignore +3 -0
- data/CHANGELOG.md +15 -0
- data/lib/ohm/tallyable.rb +37 -6
- data/ohm-tallyable.gemspec +2 -2
- data/test/db/.empty +0 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Yzk4Mzk5MWIwNzE4NDQ4YWU0MTVkNGJiMWE5NzA3ZjlkMDk2ZTkyYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDc1MTIxYmNlNmI4ZTIzZmI5NGIxM2U4OTQyYTliM2ZlYzQ0YjFiZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWNhNWU3NzdkMDFiMDNiMzgxNGMxYjc3NTI4MzA5YWFmMTY0YTgzYTU3ZTVj
|
10
|
+
YmNiMzMzN2ZkMjA1NDRjMzhmNzc5M2Y5N2E3YjYxZWM4ODZiMWQxYjI3NDFk
|
11
|
+
ODk3YTQwMWE3YTk4MGQwN2JjZDg0M2UwMzMzMzhlODliNDMwYjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTE1YTlmMWY4YmUwMGE3MThiM2M5ZWYzNmNkZGY4ZGZiNDI4OGM4Mzk2NzUz
|
14
|
+
NjlmMzNhYTQ2Y2YzMzVkYzcwZjJkYjJjYmRhYTU4NWRmYzFjZjdhN2ZiM2Vj
|
15
|
+
ZTZkYTVhYmEwOTQxNjI4YjU1ZTA1NTY3MGZiYjhkN2I0YjI4NDI=
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/lib/ohm/tallyable.rb
CHANGED
@@ -45,15 +45,30 @@ module Ohm
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.included(model)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
unless new_callbacks?
|
49
|
+
model.before(:delete, :_decrement_tallies)
|
50
|
+
model.before(:save, :_decrement_tallies)
|
51
|
+
model.after(:save, :_increment_tallies)
|
52
|
+
end
|
52
53
|
model.extend(Macros)
|
53
54
|
end
|
54
55
|
|
56
|
+
private
|
57
|
+
def self.new_callbacks?
|
58
|
+
Ohm::Callbacks.protected_instance_methods.include?(:before_save)
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
55
62
|
def _decrement_tallies
|
56
|
-
_update_tallies(-1)
|
63
|
+
_update_tallies(-1) do |attribute|
|
64
|
+
if respond_to? :read_remote
|
65
|
+
read_remote(attribute)
|
66
|
+
else
|
67
|
+
# ugly, but better than using get and having
|
68
|
+
# to save and restore the old value
|
69
|
+
db.hget(key, attribute)
|
70
|
+
end
|
71
|
+
end
|
57
72
|
end
|
58
73
|
|
59
74
|
def _increment_tallies
|
@@ -67,9 +82,25 @@ module Ohm
|
|
67
82
|
|
68
83
|
if (value = yield(attribute))
|
69
84
|
key.zincrby(amount, value)
|
70
|
-
|
85
|
+
# need to convert zscore to_i because older versions
|
86
|
+
# return a double encoded in a string
|
87
|
+
key.zrem(value) if key.zscore(value).to_i == 0
|
71
88
|
end
|
72
89
|
end
|
73
90
|
end
|
91
|
+
|
92
|
+
if new_callbacks?
|
93
|
+
def before_delete
|
94
|
+
_decrement_tallies
|
95
|
+
end
|
96
|
+
|
97
|
+
def before_update
|
98
|
+
_decrement_tallies
|
99
|
+
end
|
100
|
+
|
101
|
+
def after_save
|
102
|
+
_increment_tallies
|
103
|
+
end
|
104
|
+
end
|
74
105
|
end
|
75
106
|
end
|
data/ohm-tallyable.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ohm-tallyable'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.4'
|
4
4
|
s.summary = "Ohm Tally Plugin"
|
5
5
|
s.description = "A tally plugin for Ohm that keeps counts of records for every value of an attribute"
|
6
6
|
s.author = "Federico Bond"
|
7
7
|
s.email = 'federico@educabilia.com'
|
8
|
-
s.files =
|
8
|
+
s.files = `git ls-files`.split("\n")
|
9
9
|
s.homepage = 'https://github.com/educabilia/ohm-tallyable'
|
10
10
|
s.license = 'UNLICENSE'
|
11
11
|
end
|
data/test/db/.empty
ADDED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm-tallyable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Bond
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A tally plugin for Ohm that keeps counts of records for every value of
|
14
14
|
an attribute
|
@@ -17,11 +17,14 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
-
|
20
|
+
- .gitignore
|
21
|
+
- CHANGELOG.md
|
21
22
|
- README.md
|
22
23
|
- Rakefile
|
24
|
+
- UNLICENSE
|
23
25
|
- lib/ohm/tallyable.rb
|
24
26
|
- ohm-tallyable.gemspec
|
27
|
+
- test/db/.empty
|
25
28
|
- test/test-tallyable.rb
|
26
29
|
- test/test.conf
|
27
30
|
homepage: https://github.com/educabilia/ohm-tallyable
|