mongoid-sleeping_king_studios 0.7.0 → 0.7.1

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: 218763356e4b6bc56393162ae45be295d7ccc478
4
- data.tar.gz: 3fa4cfd1063e65e22322c5be1b183a6f04f10fc7
3
+ metadata.gz: fdbcd42bc1fb3604aaf7be52d70f408408af12b4
4
+ data.tar.gz: 05958760903d551da4b9789b2357ce27fb3df707
5
5
  SHA512:
6
- metadata.gz: 1c2f385e2cc2184c33009e5907a15b8b052780dfbe90345dfa3bc9679a637e955df9acac88f2d429a207d53ba738d491db5d8ab491b2e4fa170b95f885803367
7
- data.tar.gz: 7b579653a20b03b32db94736019d9c0caec715884948b9eff640397cae9d518c3f364d47c25e09a4bb2795151531f7f35316940aca01ee01629b1a4dd3c669d0
6
+ metadata.gz: 7440b1410fcef46d1c2e35c9e813253d492faa2b4a92b5b880e2ca620edc6acd2b62e7146863c3b1d3f01c6683bcbd085dca6a125226a5f353093f15e891eb1e
7
+ data.tar.gz: c51b962818822ec95937220a58f5a6189e10d239abf8237017e4bcf42e809a18c9089823601f3379c99adac5c9e61eca3fb389cca3a752123d5fba870c6d21e0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.1
4
+
5
+ * Add #next and #prev helpers to Orderable concern.
6
+
3
7
  ## 0.7.0
4
8
 
5
9
  * Add Orderable concern.
data/README.md CHANGED
@@ -102,14 +102,27 @@ The ::cache_ordering method accepts a subset of the params for an Origin
102
102
 
103
103
  #### Helpers
104
104
 
105
- Creating an ordering cache also creates the following helpers:
105
+ Creating an ordering cache also creates the following helpers. The name of the
106
+ generated helpers will depend on the sort params provided, or the name given
107
+ via the :as option (see below). For example, providing :as =>
108
+ :alphabetical_order will generate helpers \#next_alphabetical,
109
+ \#prev_alphabetical, and ::reorder_alphabetical!.
110
+
111
+ ##### \#next_ordering_name
112
+
113
+ Finds the next document, based on the stored ordering values.
114
+
115
+ ##### \#prev_ordering_name
116
+
117
+ Finds the previous document, based on the stored ordering values.
106
118
 
107
119
  ##### ::reorder_ordering_name!
108
120
 
109
- Loops through the collection and sets each item's field to the appropriate
110
- ordered index. Normally, this is handled on item save, but this helper allows
111
- a bulk update of the collection when adding the concern to an existing model,
112
- or if data corruption or other issues have broken the existing values.
121
+ (Class Method) Loops through the collection and sets each item's field to the
122
+ appropriate ordered index. Normally, this is handled on item save, but this
123
+ helper allows a bulk update of the collection when adding the concern to an
124
+ existing model, or if data corruption or other issues have broken the existing
125
+ values.
113
126
 
114
127
  #### Options
115
128
 
@@ -106,7 +106,19 @@ module Mongoid::SleepingKingStudios
106
106
  # @param [Class] base The base class into which the concern is mixed in.
107
107
  # @param [Metadata] metadata The metadata for the relation.
108
108
  def self.define_helpers base, metadata
109
- name = :"reorder_#{metadata.field_name.to_s.gsub(/_order\z/,'')}!"
109
+ base_name = metadata.field_name.to_s.gsub(/_order\z/,'')
110
+
111
+ name = :"next_#{base_name}"
112
+ base.send :define_method, name do
113
+ base.order_by(metadata.field_name.asc).where(metadata.field_name.gt => send(metadata.field_name)).limit(1).first
114
+ end # method
115
+
116
+ name = :"prev_#{base_name}"
117
+ base.send :define_method, name do
118
+ base.order_by(metadata.field_name.desc).where(metadata.field_name.lt => send(metadata.field_name)).limit(1).first
119
+ end # method
120
+
121
+ name = :"reorder_#{base_name}!"
110
122
  meta = class << base; self; end
111
123
  meta.send :define_method, name do
112
124
  base.update_all(metadata.field_name => nil)
@@ -166,7 +178,27 @@ module Mongoid::SleepingKingStudios
166
178
  #
167
179
  # The generated name of this method will depend on the sort params or
168
180
  # the :as option provided. For example, :as => :alphabetical_order will
169
- # result in a class method ::reorder_alphabetical!
181
+ # result in a class method ::reorder_alphabetical!.
170
182
  end # module
183
+
184
+ # @!method next_ordering_name
185
+ # Finds the next document, based on the stored ordering values.
186
+ #
187
+ # The generated name of this method will depend on the sort params or the
188
+ # :as option provided. For example, :as => :alphabetical_order will
189
+ # result in an instance method #next_alphabetical.
190
+ #
191
+ # @return [Mongoid::Document, nil] The next document in the order, or nil
192
+ # if there are no more documents in the collection.
193
+
194
+ # @!method prev_ordering_name
195
+ # Finds the previous document, based on the stored ordering values.
196
+ #
197
+ # The generated name of this method will depend on the sort params or the
198
+ # :as option provided. For example, :as => :alphabetical_order will
199
+ # result in an instance method #prev_alphabetical.
200
+ #
201
+ # @return [Mongoid::Document, nil] The previous document in the order, or
202
+ # nil if there are no prior documents in the collection.
171
203
  end # module
172
204
  end # module
@@ -3,6 +3,6 @@
3
3
  module Mongoid
4
4
  module SleepingKingStudios
5
5
  # The current version of the gem.
6
- VERSION = '0.7.0'
6
+ VERSION = '0.7.1'
7
7
  end # module
8
8
  end # module
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-sleeping_king_studios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith