123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Callbacks::Filters::Before

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activesupport/lib/active_support/callbacks.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(user_callback, user_conditions, chain_config, filter, name) ⇒ Before

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 167

def initialize(user_callback, user_conditions, chain_config, filter, name)
  halted_lambda = chain_config[:terminator]
  @direct_terminator = halted_lambda.respond_to?(:call_direct)
  @user_callback, @user_conditions, @halted_lambda, @filter, @name = user_callback, user_conditions, halted_lambda, filter, name
  freeze
end

Instance Attribute Details

#filter (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 173

attr_reader :user_callback, :user_conditions, :halted_lambda, :filter, :name

#halted_lambda (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 173

attr_reader :user_callback, :user_conditions, :halted_lambda, :filter, :name

#name (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 173

attr_reader :user_callback, :user_conditions, :halted_lambda, :filter, :name

#user_callback (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 173

attr_reader :user_callback, :user_conditions, :halted_lambda, :filter, :name

#user_conditions (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 173

attr_reader :user_callback, :user_conditions, :halted_lambda, :filter, :name

Instance Method Details

#apply(callback_sequence)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 199

def apply(callback_sequence)
  callback_sequence.before(self)
end

#call(env)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 175

def call(env)
  target = env.target
  value  = env.value
  halted = env.halted

  if !halted && user_conditions.all? { |c| c.call(target, value) }
    # Terminators that implement call_direct receive the callback
    # and its arguments as-is, sparing the thunk that the classic
    # two-argument terminator interface requires allocating on
    # every callback invocation.
    env.halted = if @direct_terminator
      halted_lambda.call_direct(target, user_callback, value)
    else
      result_lambda = -> { user_callback.call target, value }
      halted_lambda.call(target, result_lambda)
    end
    if env.halted
      target.send :halted_callback_hook, filter, name
    end
  end

  env
end