norton 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +32 -0
- data/LICENSE +22 -0
- data/README.md +1 -1
- data/lib/norton/counter.rb +12 -4
- data/lib/norton/timestamp.rb +1 -1
- data/lib/norton/version.rb +1 -1
- data/lib/norton.rb +1 -1
- data/spec/norton/counter_spec.rb +38 -0
- data/spec/norton/timestamp_spec.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a890e200767cb913b8bc0824fdc136c58a40b4b5
|
4
|
+
data.tar.gz: dd7aeb45e6d96b162575fc20dc64ea0e357ff364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3dee1ab4a58f39edc79359aad0a944a84deb4ed1ee11810bccbe723331660a2555be585a47e8e1aa4d46248e97b1dac0e39e7ef79b9dd4398be5c1da1e2a67c
|
7
|
+
data.tar.gz: 633fe0fc1c20d5458985cd7d948c519d1dcff6d254631e66c8573a11ddc7bc782aad97bd3f057be9f7f95355d0752d6a92d388e0efd2da12bced38ccfbd2e5da
|
data/.gitignore
CHANGED
@@ -17,3 +17,35 @@ spec/reports
|
|
17
17
|
test/tmp
|
18
18
|
test/version_tmp
|
19
19
|
tmp
|
20
|
+
/.config
|
21
|
+
/coverage/
|
22
|
+
/InstalledFiles
|
23
|
+
/pkg/
|
24
|
+
/spec/reports/
|
25
|
+
/test/tmp/
|
26
|
+
/test/version_tmp/
|
27
|
+
/tmp/
|
28
|
+
|
29
|
+
## Specific to RubyMotion:
|
30
|
+
.dat*
|
31
|
+
.repl_history
|
32
|
+
build/
|
33
|
+
|
34
|
+
## Documentation cache and generated files:
|
35
|
+
/.yardoc/
|
36
|
+
/_yardoc/
|
37
|
+
/doc/
|
38
|
+
/rdoc/
|
39
|
+
|
40
|
+
## Environment normalisation:
|
41
|
+
/.bundle/
|
42
|
+
/lib/bundler/man/
|
43
|
+
|
44
|
+
# for a library or gem, you might want to ignore these files since the code is
|
45
|
+
# intended to run in multiple environments; otherwise, check them in:
|
46
|
+
# Gemfile.lock
|
47
|
+
# .ruby-version
|
48
|
+
# .ruby-gemset
|
49
|
+
|
50
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
+
.rvmrc
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Larry Zhao
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -26,4 +26,4 @@ TODO: Write usage instructions here
|
|
26
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
27
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
29
|
+
5. Create new Pull Request
|
data/lib/norton/counter.rb
CHANGED
@@ -9,10 +9,10 @@ module Norton
|
|
9
9
|
# @param touches={} [type] [description]
|
10
10
|
#
|
11
11
|
# @return [type] [description]
|
12
|
-
def counter(name, options
|
12
|
+
def counter(name, options, &blk)
|
13
13
|
define_method(name) do
|
14
14
|
Norton.redis.with do |conn|
|
15
|
-
conn.
|
15
|
+
conn.get("#{self.class.to_s.pluralize.downcase}:#{self.id}:#{name}").try(:to_i) || 0
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -34,15 +34,23 @@ module Norton
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
define_method("reset_#{name}") do
|
38
|
+
count = instance_eval(&blk)
|
39
|
+
|
40
|
+
Norton.redis.with do |conn|
|
41
|
+
conn.set("#{self.class.to_s.pluralize.downcase}:#{self.id}:#{name}", count)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
37
45
|
# Add Increment callback
|
38
|
-
unless options[:incr].
|
46
|
+
unless options[:incr].nil?
|
39
47
|
options[:incr].each do |callback|
|
40
48
|
self.send callback, proc{ instance_eval("incr_#{name}".to_sym) }
|
41
49
|
end
|
42
50
|
end
|
43
51
|
|
44
52
|
# Add Decrement callback
|
45
|
-
unless options[:decr].
|
53
|
+
unless options[:decr].nil?
|
46
54
|
options[:decr].each do |callback|
|
47
55
|
self.send callback, proc{ instance_eval("decr_#{name}".to_sym) }
|
48
56
|
end
|
data/lib/norton/timestamp.rb
CHANGED
@@ -12,7 +12,7 @@ module Norton
|
|
12
12
|
def timestamp(name, touches={})
|
13
13
|
define_method(name) do
|
14
14
|
Norton.redis.with do |conn|
|
15
|
-
conn.
|
15
|
+
conn.get("#{self.class.to_s.pluralize.downcase}:#{self.id}:#{name}").try(:to_i) || Time.now.to_i
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/norton/version.rb
CHANGED
data/lib/norton.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Dummy
|
4
|
+
include Norton::Counter
|
5
|
+
|
6
|
+
counter :candies_count, {} do
|
7
|
+
# puts 'hahaha'
|
8
|
+
candies
|
9
|
+
end
|
10
|
+
|
11
|
+
def id
|
12
|
+
Random.rand(10000)
|
13
|
+
end
|
14
|
+
|
15
|
+
def candies
|
16
|
+
15
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe Norton::Counter do
|
21
|
+
describe "reset counter" do
|
22
|
+
it 'should set candies_count' do
|
23
|
+
dummy = Dummy.new
|
24
|
+
dummy.reset_candies_count
|
25
|
+
|
26
|
+
dummy.candies_count.must_equal 15
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "assign value to counter" do
|
31
|
+
it 'should be able to assign a value to the counter' do
|
32
|
+
dummy = Dummy.new
|
33
|
+
dummy.candies_count = 200
|
34
|
+
|
35
|
+
dummy.candies_count.must_equal 200
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -131,6 +131,7 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- ".gitignore"
|
133
133
|
- Gemfile
|
134
|
+
- LICENSE
|
134
135
|
- LICENSE.txt
|
135
136
|
- README.md
|
136
137
|
- Rakefile
|
@@ -139,6 +140,7 @@ files:
|
|
139
140
|
- lib/norton/timestamp.rb
|
140
141
|
- lib/norton/version.rb
|
141
142
|
- norton.gemspec
|
143
|
+
- spec/norton/counter_spec.rb
|
142
144
|
- spec/norton/timestamp_spec.rb
|
143
145
|
- spec/norton_spec.rb
|
144
146
|
- spec/spec_helper.rb
|
@@ -168,6 +170,7 @@ specification_version: 4
|
|
168
170
|
summary: Provide simple helpers on persist values in redis for performance. Works
|
169
171
|
with ActiveRecord.
|
170
172
|
test_files:
|
173
|
+
- spec/norton/counter_spec.rb
|
171
174
|
- spec/norton/timestamp_spec.rb
|
172
175
|
- spec/norton_spec.rb
|
173
176
|
- spec/spec_helper.rb
|