Class: MuchSlug::HasSlugRegistry

Inherits:
Hash
  • Object
show all
Defined in:
lib/much-slug/has_slug_registry.rb

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Constructor Details

#initializeHasSlugRegistry

Returns a new instance of HasSlugRegistry.



5
6
7
# File 'lib/much-slug/has_slug_registry.rb', line 5

def initialize
  super{ |h, k| h[k] = Entry.new }
end

Instance Method Details

#register(attribute:, source:, preprocessor:, separator:, allow_underscores:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/much-slug/has_slug_registry.rb', line 9

def register(
      attribute:,
      source:,
      preprocessor:,
      separator:,
      allow_underscores:)
  (attribute || MuchSlug.default_attribute).to_s.tap do |a|
    if allow_underscores.nil?
      allow_underscores = MuchSlug.default_allow_underscores
    end

    entry = self[a]
    entry.source_proc       = source.to_proc
    entry.preprocessor_proc = (preprocessor || MuchSlug.default_preprocessor).to_proc
    entry.separator         = separator || MuchSlug.default_separator
    entry.allow_underscores = !!allow_underscores
  end
end