Class: SkinnyControllers::Operation::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/skinny_controllers/operation/default.rb

Instance Attribute Summary

Attributes inherited from Base

#_lookup, #action, #association_name, #authorized_via_parent, #current_user, #model_key, #options, #params, #params_for_action

Instance Method Summary collapse

Methods inherited from Base

#allowed?, #allowed_for?, #association_name_from_object, call, #check_allowed!, #id_from_params, #initialize, #lookup, #policy_for, run

Methods included from ModelHelpers

#find_model, #model, #model_from_id, #model_from_named_id, #model_from_params, #model_from_parent, #model_from_scope, #model_param_name, #model_params, #sanitized_params, #scoped_model

Constructor Details

This class inherits a constructor from SkinnyControllers::Operation::Base

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/skinny_controllers/operation/default.rb', line 5

def run
  # Note that for explicitly defined operations,
  # There should be a different operation for each
  # action.
  #
  # e.g.:
  #  - EventOperations::Create
  #  - EventOperations::Update
  #  - EventOperations::Destroy
  if creating?
    @model = model_class.new(model_params)

    check_allowed!

    @model.save
    return @model
  end

  check_allowed!

  if updating?
    model.update(model_params)
  elsif destroying?
    model.destroy
  end

  model
end