Sha256: 487c84292f8cbc91fdd4c4876d7780d41ec18bf70b9ac89916df915da569a659

Contents?: true

Size: 687 Bytes

Versions: 7

Compression:

Stored size: 687 Bytes

Contents

require_relative 'core'

module ActsAsHashids
  module Methods
    extend ActiveSupport::Concern

    module ClassMethods
      def acts_as_hashids(options = {})
        include ActsAsHashids::Core unless ancestors.include?(ActsAsHashids::Core)

        define_singleton_method :hashids_secret do
          secret = options[:secret]
          (secret.respond_to?(:call) ? instance_exec(&secret) : secret) || base_class.name
        end

        define_singleton_method :hashids do
          length = options[:length] || 8
          alphabet = options[:alphabet] || Hashids::DEFAULT_ALPHABET
          Hashids.new(hashids_secret, length, alphabet)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
acts_as_hashids-0.2.0 lib/acts_as_hashids/methods.rb
acts_as_hashids-0.1.9 lib/acts_as_hashids/methods.rb
acts_as_hashids-0.1.8 lib/acts_as_hashids/methods.rb
acts_as_hashids-0.1.6 lib/acts_as_hashids/methods.rb
acts_as_hashids-0.1.5 lib/acts_as_hashids/methods.rb
acts_as_hashids-0.1.4 lib/acts_as_hashids/methods.rb
acts_as_hashids-0.1.3 lib/acts_as_hashids/methods.rb