Module: SkinnyControllers::Diet

Extended by:
ActiveSupport::Concern
Defined in:
lib/skinny_controllers/diet.rb

Constant Summary collapse

ALLOWED_OPTIONS =
[
  :model_class, :parent_class,
  :asociation_name,
  :model_params_key
].freeze

Instance Method Summary collapse

Instance Method Details

#_lookupObject



58
59
60
61
62
63
64
# File 'lib/skinny_controllers/diet.rb', line 58

def _lookup
  @_lookup ||= Lookup.from_controller(
    controller_class: self.class,
    verb:             verb_for_action,
    model_class:      _options[:model_class]
  )
end

#_optionsObject



54
55
56
# File 'lib/skinny_controllers/diet.rb', line 54

def _options
  self.class.options || {}
end

#create_operation(user:, params_for_action: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/skinny_controllers/diet.rb', line 22

def create_operation(user:, params_for_action: nil)
  operation_class.new(
    user,
    params,
    params_for_action,
    action_name,
    _lookup,
    _options
  )
end

#modelActiveRecord::Base

abstraction for operation.run useful when there is no logic needed for deciding what to do with an operation or if there is no logic to decide which operation to use

Returns:

  • (ActiveRecord::Base)

    the model



72
73
74
# File 'lib/skinny_controllers/diet.rb', line 72

def model
  @model ||= operation.run
end

#operationObject

TODO: what if we want multiple operations per action?

Returns:

  • an instance of the operation with default parameters



36
37
38
39
40
41
42
43
44
# File 'lib/skinny_controllers/diet.rb', line 36

def operation
  @operation ||= operation_class.new(
    current_user,
    params, params_for_action,
    action_name,
    _lookup,
    _options
  )
end

#operation_classClass

Assumes the operation name from the controller name

Examples:

SomeObjectsController => Operation::SomeObject::Action

Returns:

  • (Class)

    the operation class for the model and verb



50
51
52
# File 'lib/skinny_controllers/diet.rb', line 50

def operation_class
  _lookup.operation_class
end