norton 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee3da14bf4d8ec51e4e8d54c25ea0966c9c58d07
4
- data.tar.gz: 813138687ec12b2644a58057124bb2dec28ed932
3
+ metadata.gz: 52cebefc625bc8849d14c08a088a65213b46e8d5
4
+ data.tar.gz: 4b0b03f6c8ce33efd2ee204069f7f9591486c9ca
5
5
  SHA512:
6
- metadata.gz: abc487e4bcf8af8f0daec1bea18ac0a3ff6ae386a6af0b60e0b03f5513051967be3e0d5733296c8cf1cc80259c74e3805fa86406184357d8855a65d099e9ad5a
7
- data.tar.gz: fded12ea44ef90a3937e38ce58340f68c379ec713463cb9dd4c2daea8e96e3a267feba80f31a8724a2bd57393b34be389265dc4856de69ddc307226c089ad927
6
+ metadata.gz: 1186e9ab5f99dd6080ab6617c5f1ad1a860ab05ff200cec9da882c637246f32306b78bea44c0fce160ad644a692dcca2404c3abdd721fc32192670cb53c70c69
7
+ data.tar.gz: 1f779ccd40aab40c2c2b559cb5f3248668c2a9e64efcfb222feae13565da158a915a5894274636a3347cdefe35ffa7eace6d50daa0ee612c69d1cf649461ffc1
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Norton
2
2
 
3
- TODO: Write a gem description
4
-
5
3
  ## Installation
6
4
 
7
5
  Add this line to your application's Gemfile:
@@ -16,14 +14,81 @@ Or install it yourself as:
16
14
 
17
15
  $ gem install norton
18
16
 
17
+ ## Setup
18
+
19
+ You need to setup Norton with a redis connection,
20
+
21
+ `Norton.setup url: <some redis connection url> `
22
+
23
+ Norton use `ConnectionPool` to hold redis connections, so you could also specify a pool size and a timeout like below. By default `pool = 1` and `timeout = 2`.
24
+
25
+ `Norton.setup url: <some redis connection url>, pool: 5, timeout: 5`
26
+
19
27
  ## Usage
20
28
 
21
- TODO: Write usage instructions here
29
+ ### Counter
30
+
31
+ Simply include `Norton::Counter` in your model, and define a counter.
32
+
33
+ ```
34
+ class User < ActiveRecord::Base
35
+ include Norton::Counter
36
+
37
+ counter :total_likes_count
38
+ end
39
+ ```
40
+
41
+ - `users:<id>:total_likes_count` value will be created in redis to hold this counter.
42
+ - `user.total_likes_count=` to set the count to any number
43
+ - `user.incr_total_likes_count` to incr the counter by 1
44
+ - `user.decr_total_likes_count` to decr the counter by 1
45
+
46
+ You could also give a reset block:
47
+
48
+ ```
49
+ class User < ActiveRecord::Base
50
+ include Norton::Counter
51
+
52
+ counter :total_likes_count do
53
+ self.likes.count
54
+ end
55
+ end
56
+ ```
57
+
58
+ - `user.reset_total_likes_count` will evaluate the block and use the return value to set the counter
59
+
60
+
61
+ ### Timestamp
62
+
63
+ Simply include `Norton::Timestamp` in your model, and define a timestamp.
64
+
65
+ ```
66
+ class Note < ActiveRecord::Base
67
+ include Norton::Timestamp
68
+
69
+ timestamp :content_updated_at
70
+ end
71
+ ```
72
+
73
+ - `notes:<id>:content_updated_at` is created in redis to hold this timestamp
74
+ - `note.content_updated_at` is created to get the timestamp
75
+ - `note.touch_content_update_at` is created to update the timestamp to `Time.now.to_i`
76
+
77
+ You could specify callbacks along with condition Procs of when to touch the timestamp:
78
+
79
+ ```
80
+ class Note < ActiveRecord::Base
81
+ include Norton::Timestamp
82
+
83
+ timestamp :content_updated_at, before_save: Proc.new { title_changed? || content_changed? }
84
+ end
85
+ ```
22
86
 
87
+ In the case above, `note.touch_content_updated_at` will be called when `before_save` is fired and `title_changed? || content_changed?` is fulfilled.
23
88
  ## Contributing
24
89
 
25
90
  1. Fork it ( http://github.com/<my-github-username>/norton/fork )
26
91
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
92
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
93
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
94
+ 5. Create new Pull Request
@@ -40,4 +40,4 @@ module Norton
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Norton
2
- VERSION = "0.0.7"
3
- end
2
+ VERSION = "0.0.8"
3
+ end
data/norton.gemspec CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "redis", "~> 3.1.0"
22
22
  spec.add_dependency "connection_pool", "~> 2.1.0"
23
- spec.add_dependency "activesupport", "~> 4.1.8"
23
+ spec.add_dependency "activesupport", "~> 4.1"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.5"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "minitest", "~> 5.5.1"
28
- spec.add_development_dependency "activerecord", "~> 4.1.8"
28
+ spec.add_development_dependency "activerecord", "~> 4.1"
29
29
  spec.add_development_dependency "activerecord-nulldb-adapter"
30
- end
30
+ 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.7
4
+ version: 0.0.8
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-04-05 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 4.1.8
47
+ version: '4.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 4.1.8
54
+ version: '4.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 4.1.8
103
+ version: '4.1'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 4.1.8
110
+ version: '4.1'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: activerecord-nulldb-adapter
113
113
  requirement: !ruby/object:Gem::Requirement