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 165

def initialize(user_callback, user_conditions, chain_config, filter, name)
  halted_lambda = chain_config[:terminator]
  @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 170

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

#halted_lambda (readonly)

[ GitHub ]

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

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

#name (readonly)

[ GitHub ]

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

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

#user_callback (readonly)

[ GitHub ]

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

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

#user_conditions (readonly)

[ GitHub ]

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

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 188

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

#call(env)

[ GitHub ]

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

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

  if !halted && user_conditions.all? { |c| c.call(target, value) }
    result_lambda = -> { user_callback.call target, value }
    env.halted = halted_lambda.call(target, result_lambda)
    if env.halted
      target.send :halted_callback_hook, filter, name
    end
  end

  env
end