Module: ActsAsHashids::Core::ClassMethods

Includes:
FinderMethods
Defined in:
lib/acts_as_hashids/core.rb

Instance Method Summary collapse

Methods included from FinderMethods

#find

Instance Method Details

#has_many(*args, &block) ⇒ Object

rubocop:disable Style/PredicateName



52
53
54
55
56
# File 'lib/acts_as_hashids/core.rb', line 52

def has_many(*args, &block) # rubocop:disable Style/PredicateName
  options = args.extract_options!
  options[:extend] = (options[:extend] || []).concat([FinderMethods])
  super(*args, options, &block)
end

#relationObject



58
59
60
61
62
# File 'lib/acts_as_hashids/core.rb', line 58

def relation
  r = super
  r.extend FinderMethods
  r
end

#with_hashids(*ids) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/acts_as_hashids/core.rb', line 44

def with_hashids(*ids)
  ids = ids.flatten
  decoded_ids = ids.map { |id| hashids.decode(id) }.flatten
  raise ActsAsHashids::Exception, "Decode error: #{ids.inspect}" if ids.size != decoded_ids.size

  where(primary_key => decoded_ids)
end