Module: KB::FindOrCreatable::ClassMethods

Defined in:
lib/kb/models/concerns/find_or_creatable.rb

Instance Method Summary collapse

Instance Method Details

#find_or_create_by(attributes, additional_attributes) ⇒ Object



12
13
14
15
16
# File 'lib/kb/models/concerns/find_or_creatable.rb', line 12

def find_or_create_by(attributes, additional_attributes)
  all(attributes).first || new(create(additional_attributes.merge(attributes)), &:persist!)
rescue Faraday::Error => e
  raise KB::Error.from_faraday(e)
end