Class: MuchSlug::HasSlugRegistry
- Inherits:
-
Hash
- Object
- Hash
- MuchSlug::HasSlugRegistry
- Defined in:
- lib/much-slug/has_slug_registry.rb
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
-
#initialize ⇒ HasSlugRegistry
constructor
A new instance of HasSlugRegistry.
- #register(attribute:, source:, preprocessor:, separator:, allow_underscores:) ⇒ Object
Constructor Details
#initialize ⇒ HasSlugRegistry
Returns a new instance of HasSlugRegistry.
8 9 10 |
# File 'lib/much-slug/has_slug_registry.rb', line 8 def initialize super(){ |h, k| h[k] = Entry.new } end |
Instance Method Details
#register(attribute:, source:, preprocessor:, separator:, allow_underscores:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/much-slug/has_slug_registry.rb', line 12 def register( attribute:, source:, preprocessor:, separator:, allow_underscores:) attribute = (attribute || MuchSlug.default_attribute).to_s source_proc = source.to_proc preprocessor_proc = (preprocessor || MuchSlug.default_preprocessor).to_proc separator ||= MuchSlug.default_separator allow_underscores = if allow_underscores.nil? MuchSlug.default_allow_underscores else !!allow_underscores end entry = self[attribute] entry.source_proc = source_proc entry.preprocessor_proc = preprocessor_proc entry.separator = separator entry.allow_underscores = allow_underscores attribute end |