class Frigate::Operation::Base

Is here initialize the whole operation class A bigger description will be available soon

Constants

ALLOWED_ACTIONS

Attributes

model_form[R]
opts[R]
params[R]

Public Class Methods

action(action) click to toggle source

@param [Symbol] action

# 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() click to toggle source

Initializes form class and serves as a getter method

# File lib/frigate/operation/base.rb, line 10
def form_class
        @form_class ||= Class.new(Frigate::Form::Base)
end
model(model_klass) click to toggle source

@param [Class] model_klass

# File lib/frigate/operation/base.rb, line 31
def model(model_klass)
        @model_klass = model_klass
end
model_klass() click to toggle source

Serves as a getter method for model_klass class variable

# File lib/frigate/operation/base.rb, line 15
def model_klass
        @model_klass ? @model_klass : (raise StandardError.new('@model_klass nil'))
end
new(opts={}) click to toggle source

@param [Hash] opts

# File lib/frigate/operation/base.rb, line 59
def initialize(opts={})
        @opts = opts
end
operation(&block) click to toggle source

@param [Proc] block

# File lib/frigate/operation/base.rb, line 41
def operation(&block)
        @operation_block = block
end
operation_action() click to toggle source

Serves as a getter method for operation_action class variable

# File lib/frigate/operation/base.rb, line 20
def operation_action
        @operation_action ? @operation_action : (raise StandardError.new('@operation_action nil'))
end
operation_block() click to toggle source

Serves as a getter method for operation_block class variable

# 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={}) click to toggle source

@param [Hash] params @param [Hash] opts

# File lib/frigate/operation/base.rb, line 49
def run(params, opts={})
        new(opts).run(params)
end

Public Instance Methods

run(params) click to toggle source

Runs the whole operation mechanism @param [Hash] params @return [Frigate::Operations] returns self

# 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