active_permalink 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: da5262296637cea151a12211bbff29a02fdf70ef
4
- data.tar.gz: 9a9c55ff2ded150edd62fa0e9fe65de96f4e528e
2
+ SHA256:
3
+ metadata.gz: e97292918ed86b8b4f35528c3ad2af732fce12271b76b13847700fbfc82b8fdf
4
+ data.tar.gz: 899e0657462da00c685560076368fc988f607d2c7d77e3f1e01cc692803e4f34
5
5
  SHA512:
6
- metadata.gz: 6319685df9f33bb57a64b3e99f13575c23e427caf4427f249f6ed9c25a795cd6bfe045e7a260541f8d84424b3f0452b51f67d465f603e4cc761092ebf04d4cb5
7
- data.tar.gz: '04388c30e998ca73cbeca70c729862207c4d21983fa22054887582571d4420d43ddfb1c0be7b99a5086af3bdeae58510cef6d8bd23179f9f1d8f2e0b0eacfbd4'
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. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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).
@@ -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 :Sluggable
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.to_slug.normalize(transliterations: @translit).to_s
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
- unless @record.active_permalink.new_record?
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
- permalink.update_column(:active, false) unless permalink.nil?
38
- end
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
- unless permalink.nil?
45
- permalink.update(active: true)
46
- permalink
47
- end
44
+ permalink.update(active: true)
45
+ permalink
48
46
  end
49
47
 
50
48
  def build_new_permalink
51
- @record.build_active_permalink(slug: scope_unique_slug, scope: @scope, active: true)
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 Sluggable
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 Sluggable
2
+ module Querying
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  class_methods do
6
6
  def find_by_slug(value)
7
- _find_by_permalinks_slug(value)
7
+ _find_by_permalink_slug(value)
8
8
  end
9
9
 
10
10
  def find_by_slug!(value)
11
- _find_by_permalinks_slug(value, true)
11
+ _find_by_permalink_slug(value, true)
12
12
  end
13
13
 
14
14
  private
15
15
 
16
- def _find_by_permalinks_slug(value, raise_error=false)
17
- method = raise_error ? :find_by! : :find_by
18
- record = includes(:permalinks).send(method, permalinks: { slug: value })
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
- unless record.nil?
21
- record.found_by_slug = value
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? and found_by_slug != slug
41
+ found_by_slug? && found_by_slug != slug
42
42
  end
43
43
 
44
44
  def old_slugs
@@ -1,3 +1,3 @@
1
1
  module ActivePermalink
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.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: 2017-11-14 00:00:00.000000000 Z
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.1'
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.1'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: babosa
42
+ name: stringex
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
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: '1.0'
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/sluggable.rb
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.6.13
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/