mongoid-sleeping_king_studios 0.7.4 → 0.7.5

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: 2cecfeaed22c4e05ac78539fe9bb2682e4fbc3b7
4
- data.tar.gz: 8534f60f040e4b8c21725e15e20d1109bf141cfe
3
+ metadata.gz: 29178b4032ba47697556efe5804600c73450fb69
4
+ data.tar.gz: 1df094986f9fba1e988117c46df89ae85b44134c
5
5
  SHA512:
6
- metadata.gz: 4c69faf4df40ad27f95e41a94e8ebc4a9da64ed9713002855a88335f8d835f83335e57eb335bd8889e199e17d951e64c84f31a6f6822c1c5886a51ab35b8ed7b
7
- data.tar.gz: 453227de6bf3d50c1db4b0cf0fae1656baa646702024ed52af811526a89b258c50e5a9b55a14a165a9127009db52650570eda7018cff8edbe4abc20c37372145
6
+ metadata.gz: c492123648a5e294f516a5b06494ae133166ae1c8c565453dc427ab066479e88ab0c1ae1dfe30a234a294149cc64526eab701c61112c7314e8db83f84accad7a
7
+ data.tar.gz: 163787e59bc295cac492c8da46e21563c2f98cc441729c91f045149caa71d7cf814865740d92ff6e5fe970a4129b3c7e2aefcb5b6ca7d2aafc7fe8bbd289244d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.5
4
+
5
+ ## New Features
6
+
7
+ * Add #first and #last helpers to Orderable concern.
8
+
3
9
  ## 0.7.4
4
10
 
5
11
  * Remove bson_ext dependency.
data/README.md CHANGED
@@ -108,6 +108,14 @@ via the :as option (see below). For example, providing :as =>
108
108
  :alphabetical_order will generate helpers \#next_alphabetical,
109
109
  \#prev_alphabetical, and ::reorder_alphabetical!.
110
110
 
111
+ ##### \#first_ordering_name
112
+
113
+ Finds the first document, based on the stored ordering values.
114
+
115
+ ##### \#last_ordering_name
116
+
117
+ Finds the last document, based on the stored ordering values.
118
+
111
119
  ##### \#next_ordering_name
112
120
 
113
121
  Finds the next document, based on the stored ordering values.
@@ -107,20 +107,26 @@ module Mongoid::SleepingKingStudios
107
107
  # @param [Metadata] metadata The metadata for the relation.
108
108
  def self.define_helpers base, metadata
109
109
  base_name = metadata.field_name.to_s.gsub(/_order\z/,'')
110
+ filtered = metadata.filter_criteria(base)
111
+
112
+ base.send :define_method, :"first_#{base_name}" do
113
+ filtered.order_by(metadata.field_name.asc).limit(1).first
114
+ end # method
115
+
116
+ base.send :define_method, :"last_#{base_name}" do
117
+ filtered.order_by(metadata.field_name.desc).limit(1).first
118
+ end # method
110
119
 
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
120
+ base.send :define_method, :"next_#{base_name}" do
121
+ filtered.order_by(metadata.field_name.asc).where(metadata.field_name.gt => send(metadata.field_name)).limit(1).first
114
122
  end # method
115
123
 
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
124
+ base.send :define_method, :"prev_#{base_name}" do
125
+ filtered.order_by(metadata.field_name.desc).where(metadata.field_name.lt => send(metadata.field_name)).limit(1).first
119
126
  end # method
120
127
 
121
- name = :"reorder_#{base_name}!"
122
128
  meta = class << base; self; end
123
- meta.send :define_method, name do
129
+ meta.send :define_method, :"reorder_#{base_name}!" do
124
130
  base.update_all(metadata.field_name => nil)
125
131
 
126
132
  criteria = metadata.sort_criteria(base)
@@ -181,6 +187,26 @@ module Mongoid::SleepingKingStudios
181
187
  # result in a class method ::reorder_alphabetical!.
182
188
  end # module
183
189
 
190
+ # @!method first_ordering_name
191
+ # Finds the first document, based on the stored ordering values.
192
+ #
193
+ # The generated name of this method will depend on the sort params or the
194
+ # :as option provided. For example, :as => :alphabetical_order will
195
+ # result in an instance method #first_alphabetical.
196
+ #
197
+ # @return [Mongoid::Document, nil] The first document in the order, or
198
+ # nil if there are no documents in the collection.
199
+
200
+ # @!method last_ordering_name
201
+ # Finds the last document, based on the stored ordering values.
202
+ #
203
+ # The generated name of this method will depend on the sort params or the
204
+ # :as option provided. For example, :as => :alphabetical_order will
205
+ # result in an instance method #last_alphabetical.
206
+ #
207
+ # @return [Mongoid::Document, nil] The last document in the order, or nil
208
+ # if there are no documents in the collection.
209
+
184
210
  # @!method next_ordering_name
185
211
  # Finds the next document, based on the stored ordering values.
186
212
  #
@@ -3,6 +3,6 @@
3
3
  module Mongoid
4
4
  module SleepingKingStudios
5
5
  # The current version of the gem.
6
- VERSION = '0.7.4'
6
+ VERSION = '0.7.5'
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.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
@@ -177,3 +177,4 @@ signing_key:
177
177
  specification_version: 4
178
178
  summary: A collection of Mongoid concerns and extensions.
179
179
  test_files: []
180
+ has_rdoc: