class ActiveSupport::Callbacks::Filters::After - activesupport-4.2.4 Documentation

# class ActiveSupport::Callbacks::Filters::After

### Public Class Methods

build(callback_sequence, user_callback, user_conditions, chain_config) click to toggle source

    # File lib/active_support/callbacks.rb, line 201
    def self.build(callback_sequence, user_callback, user_conditions, chain_config)
      if chain_config[:skip_after_callbacks_if_terminated]
        if chain_config.key?(:terminator) && user_conditions.any?
          halting_and_conditional(callback_sequence, user_callback, user_conditions)
        elsif chain_config.key?(:terminator)
          halting(callback_sequence, user_callback)
        elsif user_conditions.any?
          conditional callback_sequence, user_callback, user_conditions
        else
          simple callback_sequence, user_callback
        end
      else
        if user_conditions.any?
          conditional callback_sequence, user_callback, user_conditions
        else
          simple callback_sequence, user_callback
        end
      end
    end

### Private Class Methods

conditional(callback_sequence, user_callback, user_conditions) click to toggle source

    # File lib/active_support/callbacks.rb, line 247
    def self.conditional(callback_sequence, user_callback, user_conditions)
      callback_sequence.after do |env|
        target = env.target
        value  = env.value

        if user_conditions.all? { |c| c.call(target, value) }
          user_callback.call target, value
        end

        env
      end
    end

halting(callback_sequence, user_callback) click to toggle source

    # File lib/active_support/callbacks.rb, line 236
    def self.halting(callback_sequence, user_callback)
      callback_sequence.after do |env|
        unless env.halted
          user_callback.call env.target, env.value
        end

        env
      end
    end

halting_and_conditional(callback_sequence, user_callback, user_conditions) click to toggle source

    # File lib/active_support/callbacks.rb, line 221
    def self.halting_and_conditional(callback_sequence, user_callback, user_conditions)
      callback_sequence.after do |env|
        target = env.target
        value  = env.value
        halted = env.halted

        if !halted && user_conditions.all? { |c| c.call(target, value) }
          user_callback.call target, value
        end

        env
      end
    end

simple(callback_sequence, user_callback) click to toggle source

    # File lib/active_support/callbacks.rb, line 261
    def self.simple(callback_sequence, user_callback)
      callback_sequence.after do |env|
        user_callback.call env.target, env.value

        env
      end
    end