Class: Blacksheep::Action
- Inherits:
-
Object
- Object
- Blacksheep::Action
- Defined in:
- lib/blacksheep/action.rb
Overview
Transoformes key in object structures in different caseing (snake_case, pascal_case cucrrently)
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.add_decorator(decorator) ⇒ type
Adds a decorator to the list of decorated to be applied on Balcksheep::Actions.
- .decorators ⇒ Object
- .new(*arguments, &block) ⇒ Object
Instance Method Summary collapse
- #action_result(data, status: :ok) ⇒ Object
- #call(params, current_user: nil, **options) ⇒ Object
- #perform(params, current_user: nil, **options, &block) ⇒ Object
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
24 25 26 |
# File 'lib/blacksheep/action.rb', line 24 def current_user @current_user end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/blacksheep/action.rb', line 24 def @options end |
#params ⇒ Object (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
36 37 38 |
# File 'lib/blacksheep/action.rb', line 36 def add_decorator(decorator) decorators << decorator unless decorators.include?(decorator) end |
.decorators ⇒ Object
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, **) @params = params @current_user = current_user @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, **, &block) @params = params @current_user = current_user @options = block.call(params) end |