Sha256: 0265ac4fa9022caa7969608848fa1353575e4ec378686fe872d952e4d2014cae
Contents?: true
Size: 728 Bytes
Versions: 8
Compression:
Stored size: 728 Bytes
Contents
require 'active_support' class LHS::Record module FindBy extend ActiveSupport::Concern module ClassMethods # Fetch some record by parameters def find_by(params = {}) _find_by(params) rescue LHC::NotFound nil end # Raise if no record was found def find_by!(params = {}) _find_by(params) end private def _find_by(params) params = params.dup.merge(limit: 1) data = request(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_class.new(data) end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems