Module: AssetCloud::Callbacks

Extended by:
ActiveSupport::Concern
Included in:
AssetExtension
Defined in:
lib/asset_cloud/callbacks.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#callbacks_for(symbol) ⇒ Object



88
89
90
# File 'lib/asset_cloud/callbacks.rb', line 88

def callbacks_for(symbol)
  self.class._callbacks[symbol] || []
end

#execute_callback(symbol, callback, args) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/asset_cloud/callbacks.rb', line 70

def execute_callback(symbol, callback, args)
  case callback
  when Symbol
    send(callback, *args)
  when Proc, Method
    callback.call(self, *args)
  else
    if callback.respond_to?(symbol)
      callback.send(symbol, self, *args)
    else
      raise StandardError,
        "Callbacks must be a symbol denoting the method to call, " \
          "a string to be evaluated, a block to be invoked, " \
          "or an object responding to the callback method."
    end
  end
end

#execute_callbacks(symbol, args) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/asset_cloud/callbacks.rb', line 62

def execute_callbacks(symbol, args)
  callbacks_for(symbol).each do |callback|
    result = execute_callback(symbol, callback, args)
    return false if result == false
  end
  true
end