lib/camunda/model.rb in camunda-workflow-0.6.0 vs lib/camunda/model.rb in camunda-workflow-1.0.0
- old
+ new
@@ -1,53 +1,26 @@
-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
-
+require 'spyke/base'
+# This class in the main element of Spyke. It defines which API models will be bound to.
+class Camunda::Model < Spyke::Base
# 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|
+ with(base_path).where(params).first.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
+
+ def self.base_path
+ uri.sub("(:id)", '')
end
class RecordNotFound < StandardError
end
end