redpear 1.0.2 → 1.0.3

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43b9457346f8717f197abb7126edf776529ac0a7
4
- data.tar.gz: ba0cfb07aadfb5c6d9aed9a2a6db569e75d6472c
3
+ metadata.gz: cacc5c94b76adaeb44603c1a18f71463aa44d80f
4
+ data.tar.gz: 649491711dd699d7e6730dc10185558c95cdd87e
5
5
  SHA512:
6
- metadata.gz: eb419ed421012e2ddcf0a1d4075df2dc6b7e574a7a7bdb9dbb3d212876add05e4323ab4a3fce6e70cfff8840a9e6945afaacdcf658c6acd2155daacdd7a37d89
7
- data.tar.gz: c9a515798435daf015f72795356b388e9b4344bcbd307014974a2b726b6fada421410e426edc257029ebf52e73613a87e8c1adaefb1083c3a67fa68213e64690
6
+ metadata.gz: e0bac811996bae661d84db2017bfd47a17d442af9e81e864c49c6052e18576f3a9cd7284241057741330852d905d154eecd5c48b71b0ad469482f81cf7cf8775
7
+ data.tar.gz: e28106cc8bf5a052e66c5978765d504baf5cad398c033f9a52e51ba9d0fe8a1090e609bc8e80720fb1cec22c2bf117ee9141dcf0ce323505966e50abc6ca201a
data/lib/redpear/model.rb CHANGED
@@ -33,10 +33,10 @@ class Redpear::Model < Hash
33
33
 
34
34
  alias_method :create, :new
35
35
 
36
- # @param [Redis] define a custom connection
36
+ # @attr_writer [Redis] connection define a custom connection
37
37
  attr_writer :connection
38
38
 
39
- # @param [String] define a custom scope
39
+ # @attr_writer [String] scope define a custom scope
40
40
  attr_writer :scope
41
41
 
42
42
  # @return [Redis] the connection
@@ -90,6 +90,7 @@ class Redpear::Model < Hash
90
90
  end
91
91
 
92
92
  # Allocate an instance
93
+ # @param [String] id the ID of the record to allocate
93
94
  def instantiate(id)
94
95
  instance = allocate
95
96
  instance.send :store, 'id', id.to_s
@@ -257,14 +258,14 @@ class Redpear::Model < Hash
257
258
 
258
259
  # Cheap after create callback, override in subclasses and don't forget to
259
260
  # call `super()`.
260
- # @params [Hash] attrs attributes used on initialization
261
+ # @param [Hash] attrs attributes used on initialization
261
262
  def after_create(attrs)
262
263
  self.class.members.add(id)
263
264
  end
264
265
 
265
266
  # Cheap after save callback, override in subclasses and don't forget to
266
267
  # call `super()`.
267
- # @params [Hash] attrs attributes used on save
268
+ # @param [Hash] attrs attributes used on save
268
269
  def after_save(attrs)
269
270
  end
270
271
 
@@ -1,7 +1,9 @@
1
1
  # Stores the column information
2
2
  class Redpear::Schema::Collection < Array
3
3
 
4
- # @param [multiple] the column definition. Please see Redpear::Schema::Column#initialize
4
+ # @param [Class] klass
5
+ # @param [multiple] args the column definition.
6
+ # @see Redpear::Schema::Column#initialize
5
7
  def store(klass, *args)
6
8
  reset!
7
9
  klass.new(*args).tap do |col|
@@ -24,13 +26,13 @@ class Redpear::Schema::Collection < Array
24
26
  @indicies ||= to_a.select {|i| i.is_a?(Redpear::Schema::Index) }
25
27
  end
26
28
 
27
- # @param [String] the column name
29
+ # @param [String] name the column name
28
30
  # @return [Boolean] if name is part of the collection
29
31
  def include?(name)
30
32
  lookup.key?(name.to_s)
31
33
  end
32
34
 
33
- # @param [String] the column name
35
+ # @param [String] name the column name
34
36
  # @return [Redpear::Schema::Column] the column for the given name
35
37
  def [](name)
36
38
  lookup[name.to_s]
@@ -6,7 +6,7 @@ class Redpear::Schema::Index < Redpear::Schema::Column
6
6
  members record.send(name)
7
7
  end
8
8
 
9
- # @param [String] index value
9
+ # @param [String] value index value
10
10
  # @return [Redpear::Store::Set] the set holding the IDs for the given `foreign_key`
11
11
  def members(value)
12
12
  value = '_' if value.nil?
@@ -8,21 +8,21 @@ module Redpear::Schema
8
8
  @columns ||= Redpear::Schema::Collection.new
9
9
  end
10
10
 
11
- # @param [multiple] the column definition. Please see Redpear::Schema::Column#initialize
11
+ # @param [multiple] args the column definition. Please see Redpear::Schema::Column#initialize
12
12
  def column(*args)
13
13
  columns.store(Redpear::Schema::Column, self, *args).tap do |col|
14
14
  __define_attribute_accessors__(col)
15
15
  end
16
16
  end
17
17
 
18
- # @param [multiple] the index definition. Please see Redpear::Index#initialize
18
+ # @param [multiple] args the index definition. Please see Redpear::Index#initialize
19
19
  def index(*args)
20
20
  columns.store(Redpear::Schema::Index, self, *args).tap do |col|
21
21
  __define_attribute_accessors__(col)
22
22
  end
23
23
  end
24
24
 
25
- # @param [multiple] the sorted index definition. Please see Redpear::ZIndex#initialize
25
+ # @param [multiple] args the sorted index definition. Please see Redpear::ZIndex#initialize
26
26
  def score(*args)
27
27
  columns.store(Redpear::Schema::Score, self, *args).tap do |col|
28
28
  __define_attribute_accessors__(col)
@@ -1,5 +1,5 @@
1
1
  class Redpear::Store::Counter < Redpear::Store::Value
2
-
2
+
3
3
  # @return [Integer] the value
4
4
  def get
5
5
  case value = super
@@ -11,7 +11,7 @@ class Redpear::Store::Counter < Redpear::Store::Value
11
11
  end
12
12
 
13
13
  # Sets the value
14
- # @param [Integer] the value to set
14
+ # @param [Integer] value the value to set
15
15
  def set(value)
16
16
  super Kernel::Integer(value)
17
17
  end
@@ -81,6 +81,16 @@ class Redpear::Store::Lock < Redpear::Store::Base
81
81
  false
82
82
  end
83
83
 
84
+ # Tries to reserve a lock. Low-level method, please see #reserve
85
+ # for the high-level API.
86
+ #
87
+ # @param [Integer] seconds the number of seconds
88
+ # @return [Boolean] true if lock was reserved
89
+ def reserve?(seconds)
90
+ timestamp = to_time(seconds).to_f
91
+ lock_obtained?(timestamp) || expired_lock_obtained?(timestamp)
92
+ end
93
+
84
94
  # Reserves a lock and yields a transaction, but only if not reserved by
85
95
  # someone else. This is useful when processes can be triggered by concurrent
86
96
  # threads, but should only be executed once.
@@ -110,8 +120,7 @@ class Redpear::Store::Lock < Redpear::Store::Base
110
120
  # Clear the lock after execution, defaults to false
111
121
  # @yield [] processes the block within the lock
112
122
  def reserve(seconds, options = {})
113
- timestamp = to_time(seconds).to_f
114
- yield if lock_obtained?(timestamp) || expired_lock_obtained?(timestamp)
123
+ yield if reserve?(seconds)
115
124
  ensure
116
125
  purge! if options[:clear]
117
126
  end
@@ -152,4 +161,4 @@ class Redpear::Store::Lock < Redpear::Store::Base
152
161
  end
153
162
  end
154
163
 
155
- end
164
+ end
@@ -102,7 +102,7 @@ class Redpear::Store::Set < Redpear::Store::Enumerable
102
102
  alias_method :merge, :union
103
103
 
104
104
  # Store the result of a union in a new +target+ key
105
- # @param [Redpear::Store::Set] other
105
+ # @param [Redpear::Store::Set] target
106
106
  # The other set
107
107
  # @param [multiple] others
108
108
  # The other sets
@@ -112,7 +112,7 @@ class Redpear::Store::Set < Redpear::Store::Enumerable
112
112
  self.class.new target.to_s, conn
113
113
  end
114
114
 
115
- # @param [multiple] other
115
+ # @param [multiple] others
116
116
  # The other sets
117
117
  # @return [Array] the intersection +other+ set
118
118
  def inter(*others)
@@ -196,11 +196,10 @@ class Redpear::Store::SortedSet < Redpear::Store::Enumerable
196
196
  end
197
197
 
198
198
  # Store the result of a union in a new +target+ key
199
- # @param [Redpear::Store::Set] other
200
- # The other set
199
+ # @param [Redpear::Store::Set] target
200
+ # The target set
201
201
  # @param [multiple] others
202
- # The other sets
203
- # @param [Hash] options
202
+ # The other sets & options
204
203
  # @option [Array] weights
205
204
  # @option [Symbol] aggregate
206
205
  # @return [Redpear::Store::Set] the result set
@@ -214,8 +213,7 @@ class Redpear::Store::SortedSet < Redpear::Store::Enumerable
214
213
  # @param [String] target
215
214
  # The target key
216
215
  # @param [multiple] others
217
- # The other sets
218
- # @param [Hash] options
216
+ # The other sets & options
219
217
  # @option [Array] weights
220
218
  # @option [Symbol] aggregate
221
219
  # @return [Redpear::Store::SortedSet] the result set
@@ -15,7 +15,7 @@ class Redpear::Store::Value < Redpear::Store::Base
15
15
  end
16
16
 
17
17
  # Sets the value
18
- # @param [String] the value to set
18
+ # @param [String] value the value to set
19
19
  def set(value)
20
20
  conn.set(key, value)
21
21
  end
@@ -45,7 +45,7 @@ class Redpear::Store::Value < Redpear::Store::Base
45
45
  def ==(other)
46
46
  case value = self.value
47
47
  when Redis::Future
48
- value.instance_eval { @transformation = ->v { v == other } }
48
+ value.instance_eval { @transformation = Kernel.lambda {|v| v == other } }
49
49
  else
50
50
  value == other
51
51
  end
@@ -2,7 +2,7 @@ module Redpear
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,117 +1,145 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redpear
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-21 00:00:00.000000000 Z
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.5
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 3.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.0.5
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.1.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - '>='
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: shoulda-matchers
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: machinist
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: factory_girl
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - '>='
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: yard
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: coveralls
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
115
143
  - !ruby/object:Gem::Version
116
144
  version: '0'
117
145
  description: Simple, elegant & efficient ORM for Redis
@@ -120,29 +148,29 @@ executables: []
120
148
  extensions: []
121
149
  extra_rdoc_files: []
122
150
  files:
123
- - lib/redpear/schema.rb
124
- - lib/redpear/store/lock.rb
125
- - lib/redpear/store/set.rb
126
- - lib/redpear/store/base.rb
127
- - lib/redpear/store/value.rb
128
- - lib/redpear/store/sorted_set.rb
129
- - lib/redpear/store/enumerable.rb
130
- - lib/redpear/store/hash.rb
131
- - lib/redpear/store/counter.rb
132
- - lib/redpear/store/list.rb
151
+ - lib/redpear.rb
133
152
  - lib/redpear/concern.rb
134
- - lib/redpear/store.rb
135
153
  - lib/redpear/model.rb
136
- - lib/redpear/schema/column.rb
137
- - lib/redpear/schema/score.rb
138
- - lib/redpear/schema/index.rb
139
- - lib/redpear/schema/collection.rb
154
+ - lib/redpear/model/expiration.rb
140
155
  - lib/redpear/model/factory_girl.rb
141
156
  - lib/redpear/model/finders.rb
142
157
  - lib/redpear/model/machinist.rb
143
- - lib/redpear/model/expiration.rb
158
+ - lib/redpear/schema.rb
159
+ - lib/redpear/schema/collection.rb
160
+ - lib/redpear/schema/column.rb
161
+ - lib/redpear/schema/index.rb
162
+ - lib/redpear/schema/score.rb
163
+ - lib/redpear/store.rb
164
+ - lib/redpear/store/base.rb
165
+ - lib/redpear/store/counter.rb
166
+ - lib/redpear/store/enumerable.rb
167
+ - lib/redpear/store/hash.rb
168
+ - lib/redpear/store/list.rb
169
+ - lib/redpear/store/lock.rb
170
+ - lib/redpear/store/set.rb
171
+ - lib/redpear/store/sorted_set.rb
172
+ - lib/redpear/store/value.rb
144
173
  - lib/redpear/version.rb
145
- - lib/redpear.rb
146
174
  homepage: https://github.com/bsm/redpear
147
175
  licenses: []
148
176
  metadata: {}
@@ -152,17 +180,17 @@ require_paths:
152
180
  - lib
153
181
  required_ruby_version: !ruby/object:Gem::Requirement
154
182
  requirements:
155
- - - '>='
183
+ - - ">="
156
184
  - !ruby/object:Gem::Version
157
185
  version: 1.9.0
158
186
  required_rubygems_version: !ruby/object:Gem::Requirement
159
187
  requirements:
160
- - - '>='
188
+ - - ">="
161
189
  - !ruby/object:Gem::Version
162
190
  version: 1.3.6
163
191
  requirements: []
164
192
  rubyforge_project:
165
- rubygems_version: 2.1.5
193
+ rubygems_version: 2.2.1
166
194
  signing_key:
167
195
  specification_version: 4
168
196
  summary: Redpear, a Redis ORM