Sha256: d55bdce22944f16b69b72e8c15e87567fd1882713f52267e55554bc95c2856b0
Contents?: true
Size: 893 Bytes
Versions: 8
Compression:
Stored size: 893 Bytes
Contents
require 'active_support' class LHS::Record module Find extend ActiveSupport::Concern module ClassMethods # Find a single uniqe record def find(args) data = if args.is_a? Hash find_with_parameters(args) else find_by_id(args) end return data unless data._record data._record.new(data) end private def find_with_parameters(params) data = request(params: params) if data._proxy.is_a?(LHS::Collection) fail LHC::NotFound.new('Requested unique item. Multiple were found.', data._request.response) if data.length > 1 data.first || fail(LHC::NotFound.new('No item was found.', data._request.response)) else data end end def find_by_id(id) request(params: { id: id }) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems