Module: Volt::Actions

Included in:
ModelController
Defined in:
lib/volt/controllers/actions.rb

Defined Under Namespace

Modules: ClassMethods Classes: StopChainException

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



81
82
83
# File 'lib/volt/controllers/actions.rb', line 81

def self.included(base)
  base.send :extend, ClassMethods
end

Instance Method Details

#run_actions(group, action) ⇒ Object

To run the actions on a class, call #run_actions passing in the group and the action being called on. If the callback chain was stopped with #stop_chain, it will return true, otherwise false.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/volt/controllers/actions.rb', line 58

def run_actions(group, action)
  callbacks = self.class.send(:"#{group}_action_callbacks")

  filtered_callbacks = filter_actions_by_only_exclude(callbacks || [], action)

  begin
    filtered_callbacks.each do |callback|
      instance_eval(&callback)
    end

    return false
  rescue StopChainException => e
    return true
  end
end

#stop_chainObject

The stop chain method can be called inside of a callback and it will raise an exception under the hood which will stop the chain and evaluation from where stop_chain is called.

Raises:



77
78
79
# File 'lib/volt/controllers/actions.rb', line 77

def stop_chain
  raise StopChainException
end