Module: HaveCode::ARCode::OptionalClassMethods

Defined in:
lib/have-code/ar_code.rb

Instance Method Summary collapse

Instance Method Details

#find_by_code(code) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/have-code/ar_code.rb', line 17

def find_by_code(code)
  return nil unless code.is_a? String
  cipher = read_inheritable_attribute(:have_code_cipher)
  candidate_id = cipher.decipher code.to_i(36)
  object = self.find candidate_id
  return object if object.code == code
  return nil
rescue
  nil
end