Module: Rad::Callbacks::ClassMethods

Defined in:
lib/rad/support/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#set_callback(callback_name, type, *executor_or_options, &block) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/rad/support/callbacks.rb', line 141

def set_callback callback_name, type, *executor_or_options, &block   
  # parsing arguments
  type, callback_name = type.to_s, callback_name.to_s
  opt = executor_or_options.extract_options!        
  "You can't provide both method name and block for filter!" if block and !executor_or_options.empty?
  executor = block || executor_or_options.first

  type.must_be.in %w{before around after}
  executor.must_be.defined
  
  # creating callback
  callback = case type
  when 'before' then BeforeCallback.new
  when 'around' then AroundCallback.new
  when 'after' then AfterCallback.new
  end            

  callback.executor = executor
  callback.terminator = opt.delete :terminator
  callback.conditions = opt

  callbacks[callback_name] ||= []
  callbacks[callback_name] << callback
end