class Blacksheep::Action

Transoformes key in object structures in different caseing (snake_case, pascal_case cucrrently)

@example

params = {
  attr: 1,
  _case: 'camel'
}

result_in_camel_case = Blacksheep::JsonTransformer.new(params).process_transformed do |converted_params_in_snake_case|
  do_something_with(converted_params_in_snake_case)
  #…
end

…alternative
transformer = Blacksheep::JsonTransformer.new(params)
converted_params_in_snake_case = transformer.transformed_params
...
result = do_something_with(converted_params_in_snake_case)
result_in_camel_case = transformer.transform_result(result)

@class Blacksheep::Action

Attributes

current_user[R]
options[R]
params[R]

Public Class Methods

add_decorator(decorator) click to toggle source

Adds a decorator to the list of decorated to be applied on Balcksheep::Actions @param decorator [type] [description]

@return [type] [description]

# File lib/blacksheep/action.rb, line 36
def add_decorator(decorator)
  decorators << decorator unless decorators.include?(decorator)
end
decorators() click to toggle source
# File lib/blacksheep/action.rb, line 27
def decorators
  @@decorators ||= []
end
new(*arguments, &block) click to toggle source
Calls superclass method
# File lib/blacksheep/action.rb, line 40
def new(*arguments, &block)
  instance = super

  decorators.each do |decorator|
    instance = decorator.new(instance)
  end

  instance
end

Public Instance Methods

action_result(data, status: :ok) click to toggle source
# File lib/blacksheep/action.rb, line 65
def action_result(data, status: :ok)
  ActionResult.new(data, status)
end
call(params, current_user: nil, **options) click to toggle source
# File lib/blacksheep/action.rb, line 51
def call(params, current_user: nil, **options)
  @params = params
  @current_user = current_user
  @options = options
end
perform(params, current_user: nil, **options, &block) click to toggle source
# File lib/blacksheep/action.rb, line 57
def perform(params, current_user: nil, **options, &block)
  @params = params
  @current_user = current_user
  @options = options

  block.call(params)
end