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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MThkM2VkOTljMmQ4ZmIzNzc4YzE0NGZiN2U1ZGNjNWEyZDdhYzU0Mg==
4
+ Yzk4Mzk5MWIwNzE4NDQ4YWU0MTVkNGJiMWE5NzA3ZjlkMDk2ZTkyYw==
5
5
  data.tar.gz: !binary |-
6
- NDIwYmEwOWJlYTM3ODA3Y2Y0YmIzYzcxZTg0ZGE4Y2RjMzkxMDIzMA==
6
+ MDc1MTIxYmNlNmI4ZTIzZmI5NGIxM2U4OTQyYTliM2ZlYzQ0YjFiZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDkxMWE0M2Y3ZWQ3ZTc2OWVlNDMwZTJmZjM3YzhiY2ViYzFjOGU1Y2Q5MjEx
10
- NTg0ZWM2YTkzYzM4ZjY5OGNhNmJjY2VlZTBlN2NmNmU5NjNlMDA3NGFiNDA4
11
- YzZlYmE5ZjFiZTFiNGNmNGRiYmQzMmI0MDE4Yzc2MmExM2I0ZmE=
9
+ YWNhNWU3NzdkMDFiMDNiMzgxNGMxYjc3NTI4MzA5YWFmMTY0YTgzYTU3ZTVj
10
+ YmNiMzMzN2ZkMjA1NDRjMzhmNzc5M2Y5N2E3YjYxZWM4ODZiMWQxYjI3NDFk
11
+ ODk3YTQwMWE3YTk4MGQwN2JjZDg0M2UwMzMzMzhlODliNDMwYjI=
12
12
  data.tar.gz: !binary |-
13
- YjdlYmZmZmIxNWE2NGU3NGU1NWNlZGEwZTY1ZDM5NmI4ZmQyMzc5MGQyN2Vm
14
- NWQ0MWIwOTM3OTA1MWE3MWEzNWUwNDZkMTFiZTZkMjY4NzAzODMxNzg5NzNk
15
- MjAyZDMwMzZiZmVjNzgwODg5YjdhMDE3ZjhmMzIzMDNkOTJlZmE=
13
+ ZTE1YTlmMWY4YmUwMGE3MThiM2M5ZWYzNmNkZGY4ZGZiNDI4OGM4Mzk2NzUz
14
+ NjlmMzNhYTQ2Y2YzMzVkYzcwZjJkYjJjYmRhYTU4NWRmYzFjZjdhN2ZiM2Vj
15
+ ZTZkYTVhYmEwOTQxNjI4YjU1ZTA1NTY3MGZiYjhkN2I0YjI4NDI=
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /pkg
2
+ /doc
3
+ /test/db/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ ### 0.1.4
2
+
3
+ - Fix support for Ohm 1.x and Redis 3.x
4
+
5
+ ### 0.1.3
6
+
7
+ - Minor refactoring
8
+
9
+ ### 0.1.1, 0.1.2
10
+
11
+ - Style fixes
12
+
13
+ ### 0.1.0
14
+
15
+ - Initial release
data/lib/ohm/tallyable.rb CHANGED
@@ -45,15 +45,30 @@ module Ohm
45
45
  end
46
46
 
47
47
  def self.included(model)
48
- model.before(:delete, :_decrement_tallies)
49
- model.before(:save, :_decrement_tallies)
50
- model.after(:save, :_increment_tallies)
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) { |attribute| read_remote(attribute) }
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
- key.zrem(value) if key.zscore(value) == 0.0
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
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ohm-tallyable'
3
- s.version = '0.1.3'
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 = Dir["UNLICENSE", "README.md", "Rakefile", "lib/**/*.rb", "*.gemspec", "test/*.*"]
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.3
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-13 00:00:00.000000000 Z
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
- - UNLICENSE
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