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 Naming/PredicateName



60
61
62
63
64
# File 'lib/acts_as_hashids/core.rb', line 60

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

#relationObject



66
67
68
69
70
# File 'lib/acts_as_hashids/core.rb', line 66

def relation
  r = super
  r.extend FinderMethods
  r
end

#with_hashids(*ids) ⇒ Object



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

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