Class: Frigate::Operation::Base
- Inherits:
-
Object
- Object
- Frigate::Operation::Base
- Defined in:
- lib/frigate/operation/base.rb
Overview
Is here initialize the whole operation class A bigger description will be available soon
Constant Summary collapse
- ALLOWED_ACTIONS =
[:create, :update]
Instance Attribute Summary collapse
-
#model_form ⇒ Object
readonly
Returns the value of attribute model_form.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
- .action(action) ⇒ Object
-
.form_class ⇒ Object
Initializes form class and serves as a getter method.
- .model(model_klass) ⇒ Object
-
.model_klass ⇒ Object
Serves as a getter method for model_klass class variable.
- .operation(&block) ⇒ Object
-
.operation_action ⇒ Object
Serves as a getter method for operation_action class variable.
-
.operation_block ⇒ Object
Serves as a getter method for operation_block class variable.
- .run(params, opts = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Base
constructor
A new instance of Base.
-
#run(params) ⇒ Frigate::Operations
Runs the whole operation mechanism.
Constructor Details
#initialize(opts = {}) ⇒ Base
Returns a new instance of Base.
59 60 61 |
# File 'lib/frigate/operation/base.rb', line 59 def initialize(opts={}) @opts = opts end |
Instance Attribute Details
#model_form ⇒ Object (readonly)
Returns the value of attribute model_form.
54 55 56 |
# File 'lib/frigate/operation/base.rb', line 54 def model_form @model_form end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
54 55 56 |
# File 'lib/frigate/operation/base.rb', line 54 def opts @opts end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
54 55 56 |
# File 'lib/frigate/operation/base.rb', line 54 def params @params end |
Class Method Details
.action(action) ⇒ Object
36 37 38 |
# File 'lib/frigate/operation/base.rb', line 36 def action(action) ALLOWED_ACTIONS.include?(action) ? (@operation_action = action.to_sym) : (raise ArgumentError.new('action is invalid')) end |
.form_class ⇒ Object
Initializes form class and serves as a getter method
10 11 12 |
# File 'lib/frigate/operation/base.rb', line 10 def form_class @form_class ||= Class.new(Frigate::Form::Base) end |
.model(model_klass) ⇒ Object
31 32 33 |
# File 'lib/frigate/operation/base.rb', line 31 def model(model_klass) @model_klass = model_klass end |
.model_klass ⇒ Object
Serves as a getter method for model_klass class variable
15 16 17 |
# File 'lib/frigate/operation/base.rb', line 15 def model_klass @model_klass ? @model_klass : (raise StandardError.new('@model_klass nil')) end |
.operation(&block) ⇒ Object
41 42 43 |
# File 'lib/frigate/operation/base.rb', line 41 def operation(&block) @operation_block = block end |
.operation_action ⇒ Object
Serves as a getter method for operation_action class variable
20 21 22 |
# File 'lib/frigate/operation/base.rb', line 20 def operation_action @operation_action ? @operation_action : (raise StandardError.new('@operation_action nil')) end |
.operation_block ⇒ Object
Serves as a getter method for operation_block class variable
25 26 27 28 |
# File 'lib/frigate/operation/base.rb', line 25 def operation_block # @operation_block.is_a?(Proc) ? @operation_block : (raise StandardError.new('operation block is not a Proc')) @operation_block end |
.run(params, opts = {}) ⇒ Object
49 50 51 |
# File 'lib/frigate/operation/base.rb', line 49 def run(params, opts={}) new(opts).run(params) end |
Instance Method Details
#run(params) ⇒ Frigate::Operations
Runs the whole operation mechanism
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/frigate/operation/base.rb', line 66 def run(params) @params = Hashie::Mash.new(params) # running actions case self.class.operation_action when :update @model_form = Action::Update.run(self, params) else @model_form = Action::Create.run(self, params) end self # return self end |