Class: SteelWheel::Handler
- Inherits:
-
Object
- Object
- SteelWheel::Handler
- Includes:
- ActiveModel::Validations, Nina
- Defined in:
- lib/steel_wheel/handler.rb
Overview
Base class that defines main flow
Direct Known Subclasses
Defined Under Namespace
Classes: Validator
Instance Attribute Summary collapse
-
#user_defined_callbacks ⇒ Object
readonly
Returns the value of attribute user_defined_callbacks.
Class Method Summary collapse
- .base_class_for(factory, flow: :main) ⇒ Object
- .define(flow: :main, &block) ⇒ Object
- .handle(input:, flow: :main, &block) ⇒ Object
Instance Method Summary collapse
- #handle(input:, flow: :main) {|object| ... } ⇒ Object
-
#initialize(&callbacks) ⇒ Handler
constructor
A new instance of Handler.
- #on_command_created(command) ⇒ Object
- #on_failure(flow) ⇒ Object
- #on_params_created(params) ⇒ Object
- #on_query_created(query) ⇒ Object
- #on_response_created(response) ⇒ Object
- #on_success(flow) ⇒ Object
Constructor Details
#initialize(&callbacks) ⇒ Handler
Returns a new instance of Handler.
46 47 48 |
# File 'lib/steel_wheel/handler.rb', line 46 def initialize(&callbacks) @user_defined_callbacks = callbacks end |
Instance Attribute Details
#user_defined_callbacks ⇒ Object (readonly)
Returns the value of attribute user_defined_callbacks.
9 10 11 |
# File 'lib/steel_wheel/handler.rb', line 9 def user_defined_callbacks @user_defined_callbacks end |
Class Method Details
.base_class_for(factory, flow: :main) ⇒ Object
74 75 76 |
# File 'lib/steel_wheel/handler.rb', line 74 def self.base_class_for(factory, flow: :main) builders[flow].abstract_factory.factories[factory].instance_variable_get(:@base_class) end |
.define(flow: :main, &block) ⇒ Object
18 19 20 |
# File 'lib/steel_wheel/handler.rb', line 18 def self.define(flow: :main, &block) builders[flow].subclass(&block) end |
.handle(input:, flow: :main, &block) ⇒ Object
78 79 80 |
# File 'lib/steel_wheel/handler.rb', line 78 def self.handle(input:, flow: :main, &block) new.handle(input: input, flow: flow, &block) end |
Instance Method Details
#handle(input:, flow: :main) {|object| ... } ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/steel_wheel/handler.rb', line 82 def handle(input:, flow: :main, &block) object = configure_builder(flow).wrap(delegate: true) { |i| i.params(input) } yield(object) if block Validator.run(object) object.success? ? on_success(object) : on_failure(object) object end |
#on_command_created(command) ⇒ Object
58 59 60 |
# File 'lib/steel_wheel/handler.rb', line 58 def on_command_created(command) # NOOP end |
#on_failure(flow) ⇒ Object
66 67 68 |
# File 'lib/steel_wheel/handler.rb', line 66 def on_failure(flow) # NOOP end |
#on_params_created(params) ⇒ Object
50 51 52 |
# File 'lib/steel_wheel/handler.rb', line 50 def on_params_created(params) # NOOP end |
#on_query_created(query) ⇒ Object
54 55 56 |
# File 'lib/steel_wheel/handler.rb', line 54 def on_query_created(query) # NOOP end |
#on_response_created(response) ⇒ Object
62 63 64 |
# File 'lib/steel_wheel/handler.rb', line 62 def on_response_created(response) # NOOP end |
#on_success(flow) ⇒ Object
70 71 72 |
# File 'lib/steel_wheel/handler.rb', line 70 def on_success(flow) # NOOP end |