Sha256: f1391f540eceda8a6a23fc9de84209319562583a1e9d4f7b788776edfbcd83af
Contents?: true
Size: 1.82 KB
Versions: 50
Compression:
Stored size: 1.82 KB
Contents
# frozen_string_literal: true module ErpIntegration module Fulfil # The `FinderMethods` add various, simplistic lookup methods to find API resources. # These methods should be the last method in the chain as it will invoke the HTTP # request to Fulfil immediately. # # If you need more attributes than the default ID attribute for an ApiResource # to be returned, add the `select` method before the finder method is being called # in your application code. # # @example # $ ErpIntegration::SalesOrder.select(:id, :product).find(100) # => <ErpIntegration::SalesOrder @id=100 @product=10 /> module FinderMethods # Looks up an individual resource based on resource's ID. # # @example # $ ErpIntegration::SalesOrder.find(100) # => <ErpIntegration::SalesOrder @id=100 /> # # @param id [Integer] The ID of the API resource. # @return [ApiResource] The found resource in Fulfil. def find(id) find_by!(id: id) || raise(ResourceNotFound) end # Looks up an individual resource based on the given attributes. # # @example # $ ErpIntegration::SalesOrder.find_by(product: 10) # => <ErpIntegration::SalesOrder @id=100 /> # # @return [ApiResource|nil] The found resource in Fulfil. def find_by(args) where(args).first end # Looks up an individual resource based on the given attributes and raises # an `ErpIntegration::ResourceNotFound` when the resource doesn't exist. # # @example # $ ErpIntegration::SalesOrder.find_by!(product: 10) # => ErpIntegration::ResourceNotFound # # @return [ApiResource|nil] The found resource in Fulfil. def find_by!(args) find_by(args) || raise(ResourceNotFound) end end end end
Version data entries
50 entries across 50 versions & 1 rubygems