Module: HumanError::Persistable::ClassMethods

Defined in:
lib/human_error/persistable.rb

Instance Method Summary collapse

Instance Method Details

#find(*ids) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/human_error/persistable.rb', line 4

def find(*ids)
  super
rescue ActiveRecord::RecordNotFound => e
  ids = case e.message
        when /\ACouldn't find .* without an ID\z/
          []
        when /\ACouldn't find .* with \'.*\'=([a-f0-9\-]+)/
          [Regexp.last_match(1)]
        when /\ACouldn't find all .* with \'.*\': ((?:[a-f0-9\-]+(?:, )?)+)/
          Regexp.last_match(1).split(', ')
        end

  raise HumanError::Errors::ResourceNotFoundError.new(
    resource_name: Persistable.human_error_resource_name(self),
    resource_id:   ids)
end