instance method start

Ruby on Rails 3.0.20

Since v3.0.20 Last seen in v3.0.20

Signature

start(key=nil, object=nil)

This will supply contents for before and around filters, and no contents for after filters (for the forward pass).

Parameters

key opt = nil
object opt = nil
Source
# 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 = <<-RUBY_EVAL
              unless halted
                result = #{@filter}
                halted = (#{chain.config[:terminator]})
              end
            RUBY_EVAL

            [@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 <<-RUBY_EVAL,  __FILE__, __LINE__ + 1
               def #{name}(halted)
                #{@compiled_options[0] || "if true"} && !halted
                  #{@filter} do
                    yield self
                  end
                else
                  yield self
                end
              end
            RUBY_EVAL
            "#{name}(halted) do"
          end
        end
      end

Defined in activesupport/lib/active_support/callbacks.rb line 181 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Callbacks::Callback

Type at least 2 characters to search.

↑↓ navigate · open · esc close