sluggable-rails 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sluggable/core_ext.rb +1 -22
- data/lib/sluggable/rails.rb +1 -0
- data/lib/sluggable/rails/concern.rb +28 -0
- data/lib/sluggable/rails/definitions.rb +6 -0
- data/lib/sluggable/rails/slug.rb +1 -1
- data/lib/sluggable/rails/slugs.rb +3 -1
- data/lib/sluggable/rails/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c38b59bf2edd9acb8300d9e37832e4120939b864f2f65d1f9702a8f49c12aabe
|
4
|
+
data.tar.gz: 277eb4281f2b13f19120873d0eab09bb1075c618d5ab7488f5a11f097f24aab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7bea5adb515c009394a298ffbf4853aa5f46e555f3f40bd8a2eefbaec110e9bf75d077b216a6320b354937aeab735b3ce8304ddea7cd99dec1812a10b3ef437
|
7
|
+
data.tar.gz: 771331ee4fcb571f7ee2b161e4f2aa55a956e1cf0eddcbe52692f89a98dd1093170126e0906a4ad59bc4bd820af713e379878f09ab1f60664991dcdb19b0a332
|
data/lib/sluggable/core_ext.rb
CHANGED
@@ -1,24 +1,3 @@
|
|
1
|
-
ActiveRecord::Base.instance_eval do
|
2
|
-
before_save :update_slugs
|
3
|
-
|
4
|
-
def has_slug(attribute = :slug, by:, separator: '-', scope: nil)
|
5
|
-
slug_definitions.add attribute, origin: by, separator: separator, scope: scope
|
6
|
-
validates attribute, presence: true, uniqueness: scope.present? ? { scope: scope } : true
|
7
|
-
end
|
8
|
-
|
9
|
-
def slug_definitions
|
10
|
-
@slug_definitions ||= Sluggable::Rails::Definitions.new
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
1
|
ActiveRecord::Base.class_eval do
|
15
|
-
|
16
|
-
self.class.slug_definitions.slugs from: self
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def update_slugs
|
22
|
-
slugs.each { |slug| slug.update if slug.needs_an_update? }
|
23
|
-
end
|
2
|
+
include Sluggable::Rails::Concern
|
24
3
|
end
|
data/lib/sluggable/rails.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Sluggable::Rails::Concern
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
before_validation :update_slugs
|
6
|
+
end
|
7
|
+
|
8
|
+
def slugs
|
9
|
+
self.class.slug_definitions.slugs from: self
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def has_slug(attribute = :slug, by:, separator: '-', scope: nil)
|
14
|
+
slug_definitions.add attribute, origin: by, separator: separator, scope: scope
|
15
|
+
validates attribute, presence: true, uniqueness: scope.present? ? { scope: scope } : true
|
16
|
+
end
|
17
|
+
|
18
|
+
def slug_definitions
|
19
|
+
@slug_definitions ||= Sluggable::Rails::Definitions.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def update_slugs
|
26
|
+
slugs.each { |slug| slug.update if slug.needs_an_update? }
|
27
|
+
end
|
28
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class Sluggable::Rails::Definitions
|
2
|
+
include Enumerable
|
3
|
+
|
2
4
|
def initialize
|
3
5
|
@definitions = {}
|
4
6
|
end
|
@@ -16,4 +18,8 @@ class Sluggable::Rails::Definitions
|
|
16
18
|
@definitions.each { |_, definition| slugs.add definition, from }
|
17
19
|
slugs
|
18
20
|
end
|
21
|
+
|
22
|
+
def each(&block)
|
23
|
+
@definitions.each &block
|
24
|
+
end
|
19
25
|
end
|
data/lib/sluggable/rails/slug.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Sluggable::Rails::Slugs
|
2
|
+
include Enumerable
|
3
|
+
|
2
4
|
def initialize
|
3
5
|
@slugs = []
|
4
6
|
end
|
@@ -7,7 +9,7 @@ class Sluggable::Rails::Slugs
|
|
7
9
|
@slugs << Sluggable::Rails::Slug.new(definition, record)
|
8
10
|
end
|
9
11
|
|
10
|
-
def each
|
12
|
+
def each(&block)
|
11
13
|
@slugs.each &block
|
12
14
|
end
|
13
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sluggable-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Dargelos
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- Rakefile
|
52
52
|
- lib/sluggable/core_ext.rb
|
53
53
|
- lib/sluggable/rails.rb
|
54
|
+
- lib/sluggable/rails/concern.rb
|
54
55
|
- lib/sluggable/rails/definition.rb
|
55
56
|
- lib/sluggable/rails/definitions.rb
|
56
57
|
- lib/sluggable/rails/slug.rb
|