Module: ErpIntegration::Fulfil::FinderMethods

Included in:
ApiResource
Defined in:
lib/erp_integration/fulfil/finder_methods.rb

Overview

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.

Examples:

$ ErpIntegration::SalesOrder.select(:id, :product).find(100)
=> <ErpIntegration::SalesOrder @id=100 @product=10 />

Instance Method Summary collapse

Instance Method Details

#find(id) ⇒ ApiResource

Looks up an individual resource based on resource’s ID.

Examples:

$ ErpIntegration::SalesOrder.find(100)
=> <ErpIntegration::SalesOrder @id=100 />

Parameters:

  • id (Integer)

    The ID of the API resource.

Returns:



25
26
27
# File 'lib/erp_integration/fulfil/finder_methods.rb', line 25

def find(id)
  find_by!(id: id) || raise(ResourceNotFound)
end

#find_by(args) ⇒ ApiResource|nil

Looks up an individual resource based on the given attributes.

Examples:

$ ErpIntegration::SalesOrder.find_by(product: 10)
=> <ErpIntegration::SalesOrder @id=100 />

Returns:



36
37
38
# File 'lib/erp_integration/fulfil/finder_methods.rb', line 36

def find_by(args)
  where(args).first
end

#find_by!(args) ⇒ ApiResource|nil

Looks up an individual resource based on the given attributes and raises an ‘ErpIntegration::ResourceNotFound` when the resource doesn’t exist.

Examples:

$ ErpIntegration::SalesOrder.find_by!(product: 10)
=> ErpIntegration::ResourceNotFound

Returns:



48
49
50
# File 'lib/erp_integration/fulfil/finder_methods.rb', line 48

def find_by!(args)
  find_by(args) || raise(ResourceNotFound)
end