Sha256: 7b192eb2a3d10571a291926e8137c030d74e6b474c852c81846df9e24b650c99

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

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

  def self.log_details?
    defined?(Rails) && Rails.env.development?
  end

  # 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
      c.use Faraday::Request::BasicAuthentication, Camunda::Workflow.configuration.camunda_user,
            Camunda::Workflow.configuration.camunda_password
      # Response
      c.use Faraday::Response::Logger, ActiveSupport::Logger.new($stdout), bodies: true if log_details?
      c.use Her::Middleware::FirstLevelParseJSON

      c.use Her::Middleware::SnakeCase
      # Adapter
      c.adapter :net_http

      # HTTP proxy
      c.proxy = Camunda::Workflow.configuration.http_proxy if Camunda::Workflow.configuration.http_proxy
    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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
camunda-workflow-0.6.0 lib/camunda/model.rb
camunda-workflow-0.5.0 lib/camunda/model.rb
camunda-workflow-0.4.1 lib/camunda/model.rb
camunda-workflow-0.4.0 lib/camunda/model.rb
camunda-workflow-0.3.3 lib/camunda/model.rb
camunda-workflow-0.3.2 lib/camunda/model.rb
camunda-workflow-0.3.1 lib/camunda/model.rb
camunda-workflow-0.3.0 lib/camunda/model.rb