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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdf704d77a580357657db281c7fd5021045fcd5c2b7cca9f32f6f468cf33d895
4
- data.tar.gz: 995fc538958ecf0ae7b1ce67cb81498e4223b3538782cc036a9763eefa1c0e4f
3
+ metadata.gz: fc2bd819b79ff41a6fe04c425c2dd21243bf4250f12d75dfe2fa4d2fea926ae1
4
+ data.tar.gz: 21b1aafaa43ca42f633072d722f9d35e6dbc21a1594195228a22df884c7f65b3
5
5
  SHA512:
6
- metadata.gz: fd373216be05945333cc1ddd6850892151549db1e887cc64ce462ae4f98ee4e86b698e34d591b71f6fd667f5cb65ae8a3634a175a9186f88ee3c97035fcc06af
7
- data.tar.gz: d62fc13e0f3151f338314d79e7664267812b2de7f5a70ef6e1ba5fbb24ae550a569bf7266858906ee8f7502387aa76bf7687b9f8cf3c73a6a65a0a584213604f
6
+ metadata.gz: fd9094457874a4c7a629e007747c6931367a67655d2c343f9aab91ee3c160340250c08119267e4dd3a576a043bd8b8ba5e22413f13deb6602640715a5e927316
7
+ data.tar.gz: 776c13331c63092e759103488cd55b4feabd36697909c90a9aabdc108d437c0b32475a572f9e5fdb262b1bcac42ce1ede6e9a279bc9d8d4be431116ceae3b386
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- schnecke (0.3.0)
4
+ schnecke (0.4.0)
5
5
  activerecord (> 4.2.0)
6
6
  activesupport (> 4.2.0)
7
7
 
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:
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Schnecke
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
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.3.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-03 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler