lib/ballast/concerns/common.rb in ballast-2.0.1 vs lib/ballast/concerns/common.rb in ballast-2.1.0

- old
+ new

@@ -5,9 +5,19 @@ module Ballast module Concerns # A concern to handle common tasks in an application. module Common + # Executes a service. + # + # @param klass [Service] The service to execute. + # @param operation [String] The operation to invoke. + # @param kwargs [Hash] Parameters passed to the service. + # @return [Service::Response] The result of the invocation. + def perform_service(klass, operation = :perform, **kwargs) + @result = klass.new(self).call(operation, params: params, **kwargs) + end + # Checks if the current request wants JSON or JSONP as response. # # @return [Boolean] `true` if the request is JSON(P), `false` otherwise. def json? [:json, :jsonp].include?(request.format.to_sym) || params[:json].to_boolean