schnecke 0.3.0 → 0.4.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +38 -0
- data/lib/schnecke/schnecke.rb +1 -1
- data/lib/schnecke/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc2bd819b79ff41a6fe04c425c2dd21243bf4250f12d75dfe2fa4d2fea926ae1
|
|
4
|
+
data.tar.gz: 21b1aafaa43ca42f633072d722f9d35e6dbc21a1594195228a22df884c7f65b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd9094457874a4c7a629e007747c6931367a67655d2c343f9aab91ee3c160340250c08119267e4dd3a576a043bd8b8ba5e22413f13deb6602640715a5e927316
|
|
7
|
+
data.tar.gz: 776c13331c63092e759103488cd55b4feabd36697909c90a9aabdc108d437c0b32475a572f9e5fdb262b1bcac42ce1ede6e9a279bc9d8d4be431116ceae3b386
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -59,6 +59,44 @@ obj.assign_slug
|
|
|
59
59
|
obj.reassign_slug
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
### Using a method to define a slug source
|
|
63
|
+
|
|
64
|
+
There are times when the source of the slug needs to be set based on some other values (e.g. a parent object, random number, etc). In this case, simply define a method that is to be used to set the soure of the slug. This method can be public, protected, or private.
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
class SomeObject
|
|
68
|
+
include Schnecke
|
|
69
|
+
slug :parent_slug
|
|
70
|
+
|
|
71
|
+
belongs_to :parent_object
|
|
72
|
+
|
|
73
|
+
protected
|
|
74
|
+
|
|
75
|
+
def parent_slug
|
|
76
|
+
parent_object.slug
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Just like if one is using a plain old attributes, one can mix and match methods and attributes if the slug is to be derived from multiple sources
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
class SomeObject
|
|
85
|
+
include Schnecke
|
|
86
|
+
slug [:name, :parent_slug]
|
|
87
|
+
|
|
88
|
+
belongs_to :parent_object
|
|
89
|
+
|
|
90
|
+
protected
|
|
91
|
+
|
|
92
|
+
def parent_slug
|
|
93
|
+
parent_object.slug
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
And this will take the `:name` attribute and the result from `parent_slug` and create a slug from the two things combined.
|
|
99
|
+
|
|
62
100
|
### Slug column
|
|
63
101
|
|
|
64
102
|
By default it is assumed that the generated slug will be assigned to the `slug` attribute of the model. If one needs to place the slug in a different columm, this can be done by defining the `column` attribute:
|
data/lib/schnecke/schnecke.rb
CHANGED
|
@@ -189,7 +189,7 @@ module Schnecke
|
|
|
189
189
|
def validate_slug_source
|
|
190
190
|
source = arrayify(schnecke_config[:slug_source])
|
|
191
191
|
source.each do |attr|
|
|
192
|
-
unless respond_to?(attr)
|
|
192
|
+
unless respond_to?(attr, true)
|
|
193
193
|
raise ArgumentError,
|
|
194
194
|
"Source '#{attr}' does not exist."
|
|
195
195
|
end
|
data/lib/schnecke/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: schnecke
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Patrick R. Schmid
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-10-
|
|
11
|
+
date: 2022-10-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|