Module: Volt::Actions

Included in:
HttpController, 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



86
87
88
# File 'lib/volt/controllers/actions.rb', line 86

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
73
74
75
76
77
# 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|
      case callback
      when Symbol
        send(callback)
      when Proc
        instance_eval(&callback)
      end
    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.



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

def stop_chain
  fail StopChainException
end