method
start
v3.0.0 -
Show latest stable
- Class:
ActiveSupport::Callbacks::Callback
start(key=nil, object=nil)public
This will supply contents for before and around filters, and no contents for after filters (for the forward pass).
# File activesupport/lib/active_support/callbacks.rb, line 181
def start(key=nil, object=nil)
return if key && !object.send("_one_time_conditions_valid_#{@callback_id}?")
# options[0] is the compiled form of supplied conditions
# options[1] is the "end" for the conditional
#
if @kind == :before || @kind == :around
if @kind == :before
# if condition # before_save :filter_name, :if => :condition
# filter_name
# end
filter = "unless halted\nresult = \#{@filter}\nhalted = (\#{chain.config[:terminator]})\nend\n"
[@compiled_options[0], filter, @compiled_options[1]].compact.join("\n")
else
# Compile around filters with conditions into proxy methods
# that contain the conditions.
#
# For `around_save :filter_name, :if => :condition':
#
# def _conditional_callback_save_17
# if condition
# filter_name do
# yield self
# end
# else
# yield self
# end
# end
#
name = "_conditional_callback_#{@kind}_#{next_id}"
@klass.class_eval "def \#{name}(halted)\n\#{@compiled_options[0] || \"if true\"} && !halted\n\#{@filter} do\nyield self\nend\nelse\nyield self\nend\nend\n", __FILE__, __LINE__ + 1
"#{name}(halted) do"
end
end
end Related methods
- Instance methods
- _compile_per_key_options
- _update_filter
- clone
- end
- matches?
- name
- next_id
- normalize_options!
- recompile!
- start
- Class methods
- new
- Private methods
-
_compile_filter -
_compile_options -
_normalize_legacy_filter