active_permalink 0.1.0 → 0.2.0
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 +5 -5
- data/README.md +1 -5
- data/lib/active_permalink.rb +2 -3
- data/lib/active_permalink/generator.rb +12 -13
- data/lib/active_permalink/loader.rb +2 -2
- data/lib/active_permalink/permalink.rb +0 -4
- data/lib/active_permalink/{sluggable.rb → querying.rb} +12 -12
- data/lib/active_permalink/version.rb +1 -1
- metadata +9 -10
- data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e97292918ed86b8b4f35528c3ad2af732fce12271b76b13847700fbfc82b8fdf
|
4
|
+
data.tar.gz: 899e0657462da00c685560076368fc988f607d2c7d77e3f1e01cc692803e4f34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 821a04f9468ecdde47b33485745b44229b3fde119765e35cbb5520db3170e67e7cdf31d600f7c62367de0476d2201bb991632a571f9a6685387d80366884ffd5
|
7
|
+
data.tar.gz: a223244a92a8dddc3525e1b763dbbafe07b122ea9d63e713ff80c6d02d2a2b4fe03e825704068bad3b1796fcd70410dfae40bb5de286a0940108f80b8735f798
|
data/README.md
CHANGED
@@ -32,12 +32,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/active-permalink.
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/active-permalink.
|
36
36
|
|
37
37
|
## License
|
38
38
|
|
39
39
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
-
|
41
|
-
## Code of Conduct
|
42
|
-
|
43
|
-
Everyone interacting in the ActivePermalink project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hardpixel/active-permalink/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/active_permalink.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
+
require 'stringex'
|
1
2
|
require 'active_record'
|
2
3
|
require 'active_delegate'
|
3
|
-
require 'babosa'
|
4
4
|
require 'active_permalink/version'
|
5
5
|
|
6
6
|
module ActivePermalink
|
7
7
|
extend ActiveSupport::Autoload
|
8
8
|
|
9
|
-
# Autoload base modules
|
10
9
|
autoload :Permalink
|
11
10
|
autoload :Generator
|
12
|
-
autoload :
|
11
|
+
autoload :Querying
|
13
12
|
autoload :Loader
|
14
13
|
end
|
15
14
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module ActivePermalink
|
2
2
|
class Generator
|
3
|
-
def initialize(record, field, old_value, new_value, options={})
|
3
|
+
def initialize(record, field, old_value, new_value, options = {})
|
4
4
|
@record = record
|
5
5
|
@field = field
|
6
6
|
@old_value = old_value
|
7
7
|
@new_value = new_value
|
8
8
|
@options = options
|
9
|
-
@translit = options[:transliterations]
|
10
9
|
@scope = options.fetch :scope, :global
|
11
10
|
end
|
12
11
|
|
@@ -15,7 +14,7 @@ module ActivePermalink
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def slug_from_column
|
18
|
-
@column_slug ||= slug_candidates.
|
17
|
+
@column_slug ||= slug_candidates.to_s.to_url
|
19
18
|
end
|
20
19
|
|
21
20
|
def scope_unique_slug
|
@@ -30,25 +29,25 @@ module ActivePermalink
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def deactivate_old_permalink
|
33
|
-
|
34
|
-
parameters = { slug: @old_value, active: true }
|
35
|
-
permalink = @record.old_permalinks.rewhere(parameters).first
|
32
|
+
return if @record.active_permalink.new_record?
|
36
33
|
|
37
|
-
|
38
|
-
|
34
|
+
parameters = { slug: @old_value, active: true }
|
35
|
+
permalink = @record.old_permalinks.rewhere(parameters).first
|
36
|
+
|
37
|
+
permalink.update_column(:active, false) unless permalink.nil?
|
39
38
|
end
|
40
39
|
|
41
40
|
def reassign_old_permalink
|
42
41
|
permalink = @record.old_permalinks.find_by(slug: slug_from_column)
|
42
|
+
return if permalink.nil?
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
permalink
|
47
|
-
end
|
44
|
+
permalink.update(active: true)
|
45
|
+
permalink
|
48
46
|
end
|
49
47
|
|
50
48
|
def build_new_permalink
|
51
|
-
|
49
|
+
parameters = { slug: scope_unique_slug, scope: @scope, active: true }
|
50
|
+
@record.build_active_permalink(parameters)
|
52
51
|
end
|
53
52
|
|
54
53
|
def new_permalink
|
@@ -3,9 +3,9 @@ module ActivePermalink
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
class_methods do
|
6
|
-
def has_permalink(field, options={})
|
6
|
+
def has_permalink(field, options = {})
|
7
7
|
include ActiveDelegate
|
8
|
-
include
|
8
|
+
include Querying
|
9
9
|
|
10
10
|
assoc_opts = { as: :sluggable, class_name: 'ActivePermalink::Permalink', dependent: :destroy }
|
11
11
|
has_many :permalinks, assoc_opts
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module ActivePermalink
|
2
2
|
class Permalink < ActiveRecord::Base
|
3
|
-
# Set table name
|
4
3
|
self.table_name = 'permalinks'
|
5
4
|
|
6
|
-
# Set default scope
|
7
5
|
default_scope { order created_at: :desc }
|
8
6
|
|
9
|
-
# Set custom scopes
|
10
7
|
scope :global, -> { where scope: :global }
|
11
8
|
|
12
|
-
# Belongs associations
|
13
9
|
belongs_to :sluggable, polymorphic: true, optional: true
|
14
10
|
end
|
15
11
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
module ActivePermalink
|
2
|
-
module
|
2
|
+
module Querying
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
class_methods do
|
6
6
|
def find_by_slug(value)
|
7
|
-
|
7
|
+
_find_by_permalink_slug(value)
|
8
8
|
end
|
9
9
|
|
10
10
|
def find_by_slug!(value)
|
11
|
-
|
11
|
+
_find_by_permalink_slug(value, true)
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def _find_by_permalink_slug(value, raise_error = false)
|
17
|
+
method = raise_error ? :find_by! : :find_by
|
18
|
+
record = includes(:permalinks).send(method, permalinks: { slug: value })
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
record
|
20
|
+
unless record.nil?
|
21
|
+
record.found_by_slug = value
|
25
22
|
end
|
23
|
+
|
24
|
+
record
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def found_by_slug
|
@@ -38,7 +38,7 @@ module ActivePermalink
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def needs_redirect?
|
41
|
-
found_by_slug?
|
41
|
+
found_by_slug? && found_by_slug != slug
|
42
42
|
end
|
43
43
|
|
44
44
|
def old_slugs
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_permalink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonian Guveli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: stringex
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +101,6 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- CODE_OF_CONDUCT.md
|
105
104
|
- Gemfile
|
106
105
|
- LICENSE.txt
|
107
106
|
- README.md
|
@@ -110,7 +109,7 @@ files:
|
|
110
109
|
- lib/active_permalink/generator.rb
|
111
110
|
- lib/active_permalink/loader.rb
|
112
111
|
- lib/active_permalink/permalink.rb
|
113
|
-
- lib/active_permalink/
|
112
|
+
- lib/active_permalink/querying.rb
|
114
113
|
- lib/active_permalink/version.rb
|
115
114
|
- lib/generators/active_permalink/install_generator.rb
|
116
115
|
- lib/generators/active_permalink/templates/migration.rb
|
@@ -134,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
133
|
version: '0'
|
135
134
|
requirements: []
|
136
135
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.7.7
|
138
137
|
signing_key:
|
139
138
|
specification_version: 4
|
140
139
|
summary: Add permalinks to ActiveRecord models
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at jonian@hardpixel.eu. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|