Class: Blacksheep::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/blacksheep/action.rb

Overview

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

Examples:

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)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



24
25
26
# File 'lib/blacksheep/action.rb', line 24

def current_user
  @current_user
end

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/blacksheep/action.rb', line 24

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



24
25
26
# File 'lib/blacksheep/action.rb', line 24

def params
  @params
end

Class Method Details

.add_decorator(decorator) ⇒ type

Adds a decorator to the list of decorated to be applied on Balcksheep::Actions

Parameters:

  • decorator (type)
    description

Returns:

  • (type)
    description


36
37
38
# File 'lib/blacksheep/action.rb', line 36

def add_decorator(decorator)
  decorators << decorator unless decorators.include?(decorator)
end

.decoratorsObject



27
28
29
# File 'lib/blacksheep/action.rb', line 27

def decorators
  @@decorators ||= []
end

.new(*arguments, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/blacksheep/action.rb', line 40

def new(*arguments, &block)
  instance = super

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

  instance
end

Instance Method Details

#action_result(data, status: :ok) ⇒ Object



65
66
67
# File 'lib/blacksheep/action.rb', line 65

def action_result(data, status: :ok)
  ActionResult.new(data, status)
end

#call(params, current_user: nil, **options) ⇒ Object



51
52
53
54
55
# 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) ⇒ Object



57
58
59
60
61
62
63
# 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