acts_as_permalink 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/lib/acts_as_permalink.rb +4 -1
- data/lib/acts_as_permalink/version.rb +1 -1
- data/lib/config.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79b83c3c0ba10ccec249d1c405e3698cdd970576
|
4
|
+
data.tar.gz: 049e0167743b55c9b3859362fe2815ba68dc1fb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f110218a78e430d5f6bfa50809856727c90db58a0356f683d2a6b02e85cd5d6c3e0a961e8f0503a7b2d53c9b8fbc0585048321adfa10fde4ff5d5e44adcebc8
|
7
|
+
data.tar.gz: 634054054c3f9b20f7db283ced3b00f72833dda4b90cb6e466fd9e4358c12b1ce34ea99d60c927a08c9e3c7d90b6fccb69c4d7a4c7be8ce61c011866fac05121
|
data/README.md
CHANGED
@@ -47,11 +47,12 @@ post_path(@post) # "/post/the_name_of_post_here"
|
|
47
47
|
|
48
48
|
The `title` and `permalink` fields can be overridden with the following options:
|
49
49
|
|
50
|
-
from:
|
51
|
-
to:
|
52
|
-
max_length:
|
53
|
-
underscore:
|
54
|
-
scope:
|
50
|
+
from: :title # Name of the active record column or function used to generate the permalink
|
51
|
+
to: :permalink # Name of the column where the permalink will be stored
|
52
|
+
max_length: 60 # Maximum number of characters the permalink will be
|
53
|
+
underscore: false # Prefer using the `_` character as a replacement over the default `-`
|
54
|
+
scope: nil # Make the permalink unique scoped to a particular attribute
|
55
|
+
allow_update: false # Allow the permalink column to be updated
|
55
56
|
|
56
57
|
So, for example you have want to store your permalink in a column called `path_name` and you want to generate your permalink using first and last name, and you want to restrict it to 40 characters, and scope the permalink by organization, your model would look like:
|
57
58
|
|
@@ -77,6 +78,8 @@ $ bundle exec rspec
|
|
77
78
|
|
78
79
|
## Changelog
|
79
80
|
|
81
|
+
* 1.2.0 -- Add the `allow_update` flag. (by @garethson)
|
82
|
+
|
80
83
|
* 1.1.0 -- Allow the option to `scope: :column_id` for uniquness.
|
81
84
|
|
82
85
|
* 1.0.3 -- Update tests to use DatabaseCleaner, and bump some dependency versions.
|
data/lib/acts_as_permalink.rb
CHANGED
@@ -11,7 +11,10 @@ module Acts
|
|
11
11
|
self.acts_as_permalink_config = Acts::Permalink::Config.new(options)
|
12
12
|
|
13
13
|
before_validation :update_permalink, on: :create
|
14
|
-
|
14
|
+
|
15
|
+
unless self.acts_as_permalink_config.allow_update
|
16
|
+
attr_readonly self.acts_as_permalink_config.to
|
17
|
+
end
|
15
18
|
|
16
19
|
if self.acts_as_permalink_config.scope
|
17
20
|
validates self.acts_as_permalink_config.to, uniqueness: {scope: self.acts_as_permalink_config.scope}
|
data/lib/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Acts
|
2
2
|
module Permalink
|
3
3
|
class Config
|
4
|
-
attr_reader :to, :from, :separator, :max_length, :scope
|
4
|
+
attr_reader :to, :from, :separator, :max_length, :scope, :allow_update
|
5
5
|
|
6
6
|
def initialize(options={})
|
7
7
|
@config = options.with_indifferent_access
|
@@ -13,6 +13,7 @@ module Acts
|
|
13
13
|
|
14
14
|
@max_length = @config[:max_length].to_i rescue 0
|
15
15
|
@max_length = 60 unless @max_length > 0
|
16
|
+
@allow_update = !!@config[:allow_update]
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_permalink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin McPhillips
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.4.5.1
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Automatically manage permalink fields for ActiveRecord models in Rails.
|