mongoid-sleeping_king_studios 0.7.4 → 0.7.5
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +8 -0
- data/lib/mongoid/sleeping_king_studios/orderable.rb +34 -8
- data/lib/mongoid/sleeping_king_studios/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29178b4032ba47697556efe5804600c73450fb69
|
|
4
|
+
data.tar.gz: 1df094986f9fba1e988117c46df89ae85b44134c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c492123648a5e294f516a5b06494ae133166ae1c8c565453dc427ab066479e88ab0c1ae1dfe30a234a294149cc64526eab701c61112c7314e8db83f84accad7a
|
|
7
|
+
data.tar.gz: 163787e59bc295cac492c8da46e21563c2f98cc441729c91f045149caa71d7cf814865740d92ff6e5fe970a4129b3c7e2aefcb5b6ca7d2aafc7fe8bbd289244d
|
data/CHANGELOG.md
CHANGED
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
|
-
|
|
112
|
-
|
|
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
|
-
|
|
117
|
-
|
|
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,
|
|
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
|
#
|
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
|
+
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:
|