mongoid-sleeping_king_studios 0.7.7 → 0.7.8

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: 2778187b766f4fd07bf7f8ae56c723f27d2ec021
4
- data.tar.gz: 8a1e1d93897f7b33437b59698a5130c9055c381a
3
+ metadata.gz: 2ed2311e927cfdbb0ce3dbf48993003c1a85dee3
4
+ data.tar.gz: d98b75d75cced592915a2501d4c3d4fded8e9499
5
5
  SHA512:
6
- metadata.gz: 5004564b79d8842b2efb3eca985aa412438ee3d3d7a1b5506a5507ddb63dd58477a9a798c1fc1136ba91b0c627090e6ba2017c031efec0af17f95fa83b786429
7
- data.tar.gz: cbb152f928cc5501fb97c327e0362517435cccf586644b750041967bebd2c7c64a21f063689fff300a2e1e8e029528df10c216dead5dbe884436723fd1471d73
6
+ metadata.gz: 89c269b96bc27a8c0896c352a97cc0719c0d2b4b9b53b55bf3ef20a06d037e0c68bcc928c06a17a6edeb30c64090cd2bedecd78b50a941eaa8a4865a5c3bce68
7
+ data.tar.gz: 307415e029fe67a4056bcbe19785cb467c8eed72524233e8368ff9040e407e00d8425ff8fd951a6786a2b1042fc5433687850bf82d7d2030ad2adf4a8cd38797
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.8
4
+
5
+ ### New Features
6
+
7
+ * Added ::value_to_slug, #generate_slug! and #to_slug helpers to Sluggable
8
+ concern.
9
+
3
10
  ## 0.7.7
4
11
 
5
12
  ### New Features
data/README.md CHANGED
@@ -174,6 +174,12 @@ short, url-friendly version.
174
174
 
175
175
  #### Helpers
176
176
 
177
+ ##### #generate_slug!
178
+
179
+ If the document's slug is blank, or if it does not match the base attribute
180
+ value, calculates the value from the base attribute and assigns it atomically.
181
+ Locked slugs (see the :lockable option) are unaffected.
182
+
177
183
  ##### ::slugify_all!
178
184
 
179
185
  (Class Method) Loops through all documents in the collection. If the document's
@@ -184,6 +190,15 @@ value from the base attribute and assigns it atomically. Locked slugs (see the
184
190
  Use this method to generate slugs when adding this concern to a model with
185
191
  existing documents.
186
192
 
193
+ ##### #to_slug
194
+
195
+ Converts the current value of the base attribute to a slug value, but returns
196
+ the converted value instead of changing the slug field.
197
+
198
+ ##### ::value_to_slug
199
+
200
+ (Class Method) Converts the provided string to a slug value.
201
+
187
202
  #### Options
188
203
 
189
204
  ##### Lockable
@@ -0,0 +1,19 @@
1
+ # Roadmap
2
+
3
+ The following updates are planned to be implemented in the near future:
4
+
5
+ ## HasTree
6
+
7
+ * Refactor concern name to BelongsToTree.
8
+ * Finish implementing support for using a custom field to determine the
9
+ ancestry identifiers, such as a title or slug.
10
+
11
+ ## Sluggable
12
+
13
+ * Refactor concern method from ::slugify to ::generates_slug.
14
+ * Add :as option to support custom slug field names, e.g.
15
+
16
+ generates_slug, :full_name, :as => :short_name
17
+
18
+ * Rename helper methods using slug field name, e.g. #to_short_name.
19
+ * Support multiple slug fields per model.
@@ -108,20 +108,36 @@ module Mongoid::SleepingKingStudios
108
108
  #
109
109
  # @since 0.7.7
110
110
  def self.define_helpers base, metadata
111
+ instance_methods = Module.new
112
+
113
+ instance_methods.send :define_method, :generate_slug! do
114
+ value = metadata.value_to_slug(send metadata.attribute)
115
+ if slug.blank?
116
+ self[:slug] = value
117
+ self.set :slug => value if persisted?
118
+ elsif slug != value && !(metadata.lockable? && slug_lock)
119
+ self[:slug] = value
120
+ self.set :slug => value if persisted?
121
+ end # if
122
+ end # method generate_slug!
123
+
124
+ instance_methods.send :define_method, :to_slug do
125
+ metadata.value_to_slug(send metadata.attribute)
126
+ end # method to_slug
127
+
128
+ base.include instance_methods
129
+
111
130
  # Define class-level helpers.
112
131
  class_methods = Module.new
113
132
 
114
133
  class_methods.send :define_method, :slugify_all! do
115
- all.each do |obj|
116
- value = metadata.value_to_slug(obj.send metadata.attribute)
117
- if obj.slug.blank?
118
- obj.set :slug => value
119
- elsif obj.slug != value && !(metadata.lockable? && obj.slug_lock)
120
- obj.set :slug => value
121
- end # if
122
- end # each
134
+ all.map &:generate_slug!
123
135
  end # class method slugify_all!
124
136
 
137
+ class_methods.send :define_method, :value_to_slug do |value|
138
+ metadata.value_to_slug(value)
139
+ end # class method value_to_slug
140
+
125
141
  base.extend class_methods
126
142
  end # module method define_helpers
127
143
 
@@ -171,6 +187,22 @@ module Mongoid::SleepingKingStudios
171
187
  #
172
188
  # @return [Boolean] True if the slug is locked; otherwise false.
173
189
 
190
+ # @!method generate_slug!
191
+ # If the document's slug is blank, or if it does not match the base
192
+ # attribute value, calculates the value from the base attribute and
193
+ # assigns it atomically. Locked slugs (see the :lockable option) are
194
+ # unaffected.
195
+ #
196
+ # @since 0.7.8
197
+
198
+ # @!method to_slug
199
+ # Converts the current value of the base attribute to a slug value, but
200
+ # returns the converted value instead of changing the slug field.
201
+ #
202
+ # @return [String] The converted string.
203
+ #
204
+ # @since 0.7.8
205
+
174
206
  # Class methods added to the base class via #extend.
175
207
  module ClassMethods
176
208
  # @overload slugify attribute, options = {}
@@ -202,6 +234,19 @@ module Mongoid::SleepingKingStudios
202
234
  #
203
235
  # Use this method to generate slugs when adding this concern to a model
204
236
  # with existing documents.
237
+ #
238
+ # @since 0.7.7
239
+
240
+ # @!method value_to_slug(value)
241
+ # Converts the provided string to a slug value. Delegates to
242
+ # metadata.value_to_slug, so overriding this method will not change how
243
+ # slugs are generated.
244
+ #
245
+ # @param [String] value The string to convert into a slug.
246
+ #
247
+ # @return [String] The converted string.
248
+ #
249
+ # @since 0.7.8
205
250
  end # module
206
251
  end # module
207
252
  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.7'
6
+ VERSION = '0.7.8'
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.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
@@ -135,6 +135,7 @@ files:
135
135
  - CHANGELOG.md
136
136
  - LICENSE
137
137
  - README.md
138
+ - ROADMAP.md
138
139
  - lib/mongoid/sleeping_king_studios.rb
139
140
  - lib/mongoid/sleeping_king_studios/concern.rb
140
141
  - lib/mongoid/sleeping_king_studios/concern/metadata.rb