lib/camunda/model.rb in camunda-workflow-0.1.3 vs lib/camunda/model.rb in camunda-workflow-0.1.4

- old
+ new

@@ -1,10 +1,13 @@ require 'her/model' +# This class in the main element of Her. It defines which API models will be bound to. class Camunda::Model include Her::Model + # We use a lambda so that this is evaluated after Camunda::Workflow.configuration is set api = lambda do + # Configuration for Her and Faraday requests and responses Her::API.new(url: File.join(Camunda::Workflow.configuration.engine_url)) do |c| c.path_prefix = Camunda::Workflow.configuration.engine_route_prefix # Request c.use Faraday::Request::Multipart c.use FaradayMiddleware::EncodeJson @@ -20,9 +23,25 @@ end end use_api api + # Returns result of find_by but raises an exception instead of returning nil + # @param params [Hash] query parameters + # @return [Camunda::Model] + # @raise [Camunda::Model::RecordNotFound] if query returns no results + def self.find_by!(params) + find_by(params).tap do |result| + raise Camunda::Model::RecordNotFound unless result + end + end + + # Returns the worker id + # @note default worker id is set in Camunda::Workflow.configuration + # @return [String] id of worker def self.worker_id Camunda::Workflow.configuration.worker_id + end + + class RecordNotFound < StandardError end end