Sha256: cfdeb6f22b0992446e915d42399c2963445274421b8f80d63525578b8833ba0e
Contents?: true
Size: 822 Bytes
Versions: 22
Compression:
Stored size: 822 Bytes
Contents
require 'active_support' class LHS::Record module FindBy extend ActiveSupport::Concern module ClassMethods # Fetch some record by parameters def find_by(params = {}, options = nil) _find_by(params, options) rescue LHC::NotFound nil end # Raise if no record was found def find_by!(params = {}, options = nil) _find_by(params, options) end private def _find_by(params, options = {}) options ||= {} params = params.dup.merge(limit: 1) data = request(options.merge(params: params)) if data._proxy.is_a?(LHS::Collection) data.first || fail(LHC::NotFound.new('No item was found.', data._request.response)) else data._record.new(data) end end end end end
Version data entries
22 entries across 22 versions & 1 rubygems