Module: ActsAsHashids::Methods::ClassMethods

Defined in:
lib/acts_as_hashids/methods.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_hashids(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/acts_as_hashids/methods.rb', line 8

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
    Hashids.new(hashids_secret, length)
  end
end