Class: ActionMan::Base
- Inherits:
-
Object
- Object
- ActionMan::Base
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/action_man/base.rb
Constant Summary collapse
- RESULT_TYPES =
%i[success failure].freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
- .after(*filters) ⇒ Object
- .after_failure(*filters) ⇒ Object
- .after_success(*filters) ⇒ Object
- .before ⇒ Object
- .model(name) ⇒ Object
- .param(name) ⇒ Object
- .params(*names) ⇒ Object
Instance Method Summary collapse
- #executable? ⇒ Boolean
-
#initialize(model) ⇒ Base
constructor
A new instance of Base.
- #run(params = {}) ⇒ Object
Constructor Details
#initialize(model) ⇒ Base
Returns a new instance of Base.
80 81 82 83 |
# File 'lib/action_man/base.rb', line 80 def initialize(model) @model = model @params = {} end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
17 18 19 |
# File 'lib/action_man/base.rb', line 17 def args @args end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
17 18 19 |
# File 'lib/action_man/base.rb', line 17 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
17 18 19 |
# File 'lib/action_man/base.rb', line 17 def params @params end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
17 18 19 |
# File 'lib/action_man/base.rb', line 17 def result @result end |
Class Method Details
.after(*filters) ⇒ Object
26 27 28 29 |
# File 'lib/action_man/base.rb', line 26 def after(*filters, &) (filters) set_callback(:execute, :after, *filters, &) end |
.after_failure(*filters) ⇒ Object
36 37 38 39 |
# File 'lib/action_man/base.rb', line 36 def after_failure(*filters, &) (filters, on: :failure) set_callback(:execute, :after, *filters, &) end |
.after_success(*filters) ⇒ Object
31 32 33 34 |
# File 'lib/action_man/base.rb', line 31 def after_success(*filters, &) (filters, on: :success) set_callback(:execute, :after, *filters, &) end |
.before ⇒ Object
22 23 24 |
# File 'lib/action_man/base.rb', line 22 def before(...) set_callback(:execute, :before, ...) end |
.model(name) ⇒ Object
51 52 53 54 55 |
# File 'lib/action_man/base.rb', line 51 def model(name) define_method(name) do model end end |
.param(name) ⇒ Object
41 42 43 44 45 |
# File 'lib/action_man/base.rb', line 41 def param(name) define_method(name) do params[name] end end |
.params(*names) ⇒ Object
47 48 49 |
# File 'lib/action_man/base.rb', line 47 def params(*names) names.each { |name| param(name) } end |
Instance Method Details
#executable? ⇒ Boolean
85 86 87 |
# File 'lib/action_man/base.rb', line 85 def executable? true end |
#run(params = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/action_man/base.rb', line 89 def run(params={}) @params = params if executable? run_execute elsif exception_if_not_executable raise NotExecutable else Result.failure end end |