redpear 0.3.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,7 +42,7 @@ class Redpear::Column < String
42
42
 
43
43
  # @return [Boolean] true if the column is writable
44
44
  def writable?
45
- type != :counter
45
+ true
46
46
  end
47
47
 
48
48
  # @return [Boolean] true if the column is an index
@@ -0,0 +1,26 @@
1
+ module Redpear::Counters
2
+
3
+ # Increments the value of a counter attribute
4
+ # @param [String|Symbol] column
5
+ # The column name to increment
6
+ # @param [Integer] by
7
+ # Increment by this value
8
+ def increment!(column, by = 1)
9
+ return false unless persisted?
10
+
11
+ col = self.class.columns[column]
12
+ return false unless col && col.type == :counter
13
+
14
+ self[col.name] = nest.hincrby(col.name, by).to_i
15
+ end
16
+
17
+ # Decrements the value of a counter attribute
18
+ # @param [String|Symbol] column
19
+ # The column name to decrement
20
+ # @param [Integer] by
21
+ # Decrement by this value
22
+ def decrement!(column, by = 1)
23
+ increment!(column, -by)
24
+ end
25
+
26
+ end
data/lib/redpear/model.rb CHANGED
@@ -31,6 +31,7 @@ class Redpear::Model < Hash
31
31
  include Redpear::Namespace
32
32
  include Redpear::Persistence
33
33
  include Redpear::Expiration
34
+ include Redpear::Counters
34
35
  include Redpear::Schema
35
36
  include Redpear::Finders
36
37
 
data/lib/redpear.rb CHANGED
@@ -11,6 +11,7 @@ module Redpear
11
11
  autoload :Column
12
12
  autoload :Concern
13
13
  autoload :Connection
14
+ autoload :Counters
14
15
  autoload :Expiration
15
16
  autoload :Finders
16
17
  autoload :Index
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redpear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-02 00:00:00.000000000Z
12
+ date: 2011-11-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &16033840 !ruby/object:Gem::Requirement
16
+ requirement: &12980480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16033840
24
+ version_requirements: *12980480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nest
27
- requirement: &16033380 !ruby/object:Gem::Requirement
27
+ requirement: &12980020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16033380
35
+ version_requirements: *12980020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &16033000 !ruby/object:Gem::Requirement
38
+ requirement: &12979640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16033000
46
+ version_requirements: *12979640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &16062160 !ruby/object:Gem::Requirement
49
+ requirement: &12979180 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *16062160
57
+ version_requirements: *12979180
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &16061740 !ruby/object:Gem::Requirement
60
+ requirement: &12978760 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *16061740
68
+ version_requirements: *12978760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeredis
71
- requirement: &16061320 !ruby/object:Gem::Requirement
71
+ requirement: &12978340 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *16061320
79
+ version_requirements: *12978340
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: shoulda-matchers
82
- requirement: &16060900 !ruby/object:Gem::Requirement
82
+ requirement: &12977920 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *16060900
90
+ version_requirements: *12977920
91
91
  description: Simple, elegant & efficient ORM for Redis
92
92
  email: dimitrij@blacksquaremedia.com
93
93
  executables: []
@@ -108,6 +108,7 @@ files:
108
108
  - lib/redpear/model.rb
109
109
  - lib/redpear/index.rb
110
110
  - lib/redpear/schema.rb
111
+ - lib/redpear/counters.rb
111
112
  - lib/redpear/machinist.rb
112
113
  homepage: https://github.com/bsm/redpear
113
114
  licenses: []