Sha256: 03571839e8909939a644b127c19826c4e2e813e1de7a446b7a57ec51bdf71138

Contents?: true

Size: 878 Bytes

Versions: 1

Compression:

Stored size: 878 Bytes

Contents

require "much-slug"

module MuchSlug
  class HasSlugRegistry < ::Hash
    def initialize
      super{ |h, k| h[k] = Entry.new }
    end

    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

    class Entry
      attr_accessor :source_proc, :preprocessor_proc, :separator, :allow_underscores
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
much-slug-0.1.0 lib/much-slug/has_slug_registry.rb