Class: ActiveSupport::Callbacks::Callback

### Home Classes Methods

### In Files

- lib/active_support/callbacks.rb

### Parent

Object

### Methods

- ::new
- #_compile_per_key_options
- #_update_filter
- #clone
- #end
- #matches?
- #name
- #next_id
- #normalize_options!
- #recompile!
- #start

### Class/Module Index

Quicksearch

- ActiveSupport
- ActiveSupport::Autoload
- ActiveSupport::BacktraceCleaner
- ActiveSupport::Base64
- ActiveSupport::BasicObject
- ActiveSupport::Benchmarkable
- ActiveSupport::BufferedLogger
- ActiveSupport::BufferedLogger::Severity
- ActiveSupport::Cache
- ActiveSupport::Cache::CompressedMemCacheStore
- ActiveSupport::Cache::Entry
- ActiveSupport::Cache::FileStore
- ActiveSupport::Cache::MemCacheStore
- ActiveSupport::Cache::MemoryStore
- ActiveSupport::Cache::Store
- ActiveSupport::Cache::Strategy
- ActiveSupport::Cache::Strategy::LocalCache
- ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- ActiveSupport::Cache::SynchronizedMemoryStore
- ActiveSupport::Callbacks
- ActiveSupport::Callbacks::Callback
- ActiveSupport::Callbacks::CallbackChain
- ActiveSupport::Callbacks::ClassMethods
- ActiveSupport::Concern
- ActiveSupport::Configurable
- ActiveSupport::Configurable::ClassMethods
- ActiveSupport::Dependencies
- ActiveSupport::Dependencies::Reference
- ActiveSupport::Dependencies::WatchStack
- ActiveSupport::Deprecation
- ActiveSupport::DescendantsTracker
- ActiveSupport::Duration
- ActiveSupport::FileUpdateChecker
- ActiveSupport::Gzip
- ActiveSupport::Gzip::Stream
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::Inflector
- ActiveSupport::Inflector::Inflections
- ActiveSupport::InheritableOptions
- ActiveSupport::JSON
- ActiveSupport::JSON::Backends
- ActiveSupport::JSON::Backends::JSONGem
- ActiveSupport::JSON::Backends::Yajl
- ActiveSupport::JSON::Backends::Yaml
- ActiveSupport::JSON::Encoding
- ActiveSupport::JSON::Encoding::CircularReferenceError
- ActiveSupport::JSON::Encoding::Encoder
- ActiveSupport::JSON::Variable
- ActiveSupport::LogSubscriber
- ActiveSupport::LogSubscriber::TestHelper
- ActiveSupport::LogSubscriber::TestHelper::MockLogger
- ActiveSupport::Memoizable
- ActiveSupport::Memoizable::InstanceMethods
- ActiveSupport::MessageEncryptor
- ActiveSupport::MessageEncryptor::InvalidMessage
- ActiveSupport::MessageVerifier
- ActiveSupport::MessageVerifier::InvalidSignature
- ActiveSupport::Multibyte
- ActiveSupport::Multibyte::Chars
- ActiveSupport::Multibyte::EncodingError
- ActiveSupport::Multibyte::Unicode
- ActiveSupport::Multibyte::Unicode::Codepoint
- ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- ActiveSupport::Notifications
- ActiveSupport::Notifications::Event
- ActiveSupport::Notifications::Fanout
- ActiveSupport::Notifications::Instrumenter
- ActiveSupport::OrderedOptions
- ActiveSupport::Railtie
- ActiveSupport::Rescuable
- ActiveSupport::Rescuable::ClassMethods
- ActiveSupport::SafeBuffer
- ActiveSupport::SecureRandom
- ActiveSupport::StringInquirer
- ActiveSupport::TestCase
- ActiveSupport::Testing
- ActiveSupport::Testing::Assertions
- ActiveSupport::Testing::Declarative
- ActiveSupport::Testing::Isolation
- ActiveSupport::Testing::Isolation::Forking
- ActiveSupport::Testing::Isolation::MiniTest
- ActiveSupport::Testing::Isolation::Subprocess
- ActiveSupport::Testing::Isolation::TestUnit
- ActiveSupport::Testing::Pending
- ActiveSupport::Testing::Performance
- ActiveSupport::Testing::Performance::Benchmarker
- ActiveSupport::Testing::Performance::Metrics
- ActiveSupport::Testing::Performance::Metrics::Base
- ActiveSupport::Testing::Performance::Metrics::CpuTime
- ActiveSupport::Testing::Performance::Metrics::GcRuns
- ActiveSupport::Testing::Performance::Metrics::GcTime
- ActiveSupport::Testing::Performance::Metrics::Memory
- ActiveSupport::Testing::Performance::Metrics::Objects
- ActiveSupport::Testing::Performance::Metrics::ProcessTime
- ActiveSupport::Testing::Performance::Metrics::Time
- ActiveSupport::Testing::Performance::Metrics::WallTime
- ActiveSupport::Testing::Performance::Performer
- ActiveSupport::Testing::Performance::Profiler
- ActiveSupport::Testing::ProxyTestResult
- ActiveSupport::Testing::RemoteError
- ActiveSupport::Testing::SetupAndTeardown
- ActiveSupport::Testing::SetupAndTeardown::ClassMethods
- ActiveSupport::Testing::SetupAndTeardown::ForClassicTestUnit
- ActiveSupport::Testing::SetupAndTeardown::ForMiniTest
- ActiveSupport::TimeWithZone
- ActiveSupport::TimeZone
- ActiveSupport::XmlMini
- ActiveSupport::XmlMini_LibXMLSAX
- ActiveSupport::XmlMini_LibXMLSAX::HashBuilder
- ActiveSupport::XmlMini_NokogiriSAX
- ActiveSupport::XmlMini_NokogiriSAX::HashBuilder
- Test
- Test::Unit
- Test::Unit::Collector
- Test::Unit::Collector::ObjectSpace
- Object
- Object::HashWithIndifferentAccess
- Object::MissingSourceFile
- ERB
- ERB::Util
- I18n
- I18n::Railtie
- LoadError
- LoadError
- Logger
- Logger::SimpleFormatter
- Array
- Benchmark
- BigDecimal
- Class
- Date
- DateTime
- Enumerable
- FalseClass
- File
- Fixnum
- Float
- Hash
- Integer
- Kernel
- Module
- NameError
- NilClass
- Numeric
- Process
- Range
- Regexp
- String
- Symbol
- Time
- TrueClass

No matching classes.

# ActiveSupport::Callbacks::Callback

### Attributes

chain[RW]
filter[RW]
kind[RW]
klass[RW]
options[RW]
per_key[RW]
raw_filter[RW]

### Public Class Methods

new(chain, filter, kind, options, klass) click to toggle source

    # File lib/active_support/callbacks.rb, line 106
    def initialize(chain, filter, kind, options, klass)
      @chain, @kind, @klass = chain, kind, klass
      normalize_options!(options)

      @per_key              = options.delete(:per_key)
      @raw_filter, @options = filter, options
      @filter               = _compile_filter(filter)
      @compiled_options     = _compile_options(options)
      @callback_id          = next_id

      _compile_per_key_options
    end

### Public Instance Methods

_compile_per_key_options() click to toggle source

    # File lib/active_support/callbacks.rb, line 168
    def _compile_per_key_options
      key_options  = _compile_options(@per_key)

      @klass.class_eval           def _one_time_conditions_valid_#{@callback_id}?            true #{key_options[0]}          end, __FILE__, __LINE__ + 1
    end

_update_filter(filter_options, new_options) click to toggle source

    # File lib/active_support/callbacks.rb, line 153
    def _update_filter(filter_options, new_options)
      filter_options[:if].push(new_options[:unless]) if new_options.key?(:unless)
      filter_options[:unless].push(new_options[:if]) if new_options.key?(:if)
    end

clone(chain, klass) click to toggle source

    # File lib/active_support/callbacks.rb, line 119
    def clone(chain, klass)
      obj                  = super()
      obj.chain            = chain
      obj.klass            = klass
      obj.per_key          = @per_key.dup
      obj.options          = @options.dup
      obj.per_key[:if]     = @per_key[:if].dup
      obj.per_key[:unless] = @per_key[:unless].dup
      obj.options[:if]     = @options[:if].dup
      obj.options[:unless] = @options[:unless].dup
      obj
    end

end(key=nil, object=nil) click to toggle source

This will supply contents for around and after filters, but not before filters (for the backward pass).

    # File lib/active_support/callbacks.rb, line 234
    def end(key=nil, object=nil)
      return if key && !object.send("_one_time_conditions_valid_#{@callback_id}?")

      if @kind == :around || @kind == :after
        # if condition    # after_save :filter_name, :if => :condition
        #   filter_name
        # end
        if @kind == :after
          [@compiled_options[0], @filter, @compiled_options[1]].compact.join("\n")
        else
          "end"
        end
      end
    end

matches?(_kind, _filter) click to toggle source

    # File lib/active_support/callbacks.rb, line 149
    def matches?(_kind, _filter)
      @kind == _kind && @filter == _filter
    end

name() click to toggle source

    # File lib/active_support/callbacks.rb, line 141
    def name
      chain.name
    end

next_id() click to toggle source

    # File lib/active_support/callbacks.rb, line 145
    def next_id
      @@_callback_sequence += 1
    end

normalize_options!(options) click to toggle source

    # File lib/active_support/callbacks.rb, line 132
    def normalize_options!(options)
      options[:if] = Array.wrap(options[:if])
      options[:unless] = Array.wrap(options[:unless])

      options[:per_key] ||= {}
      options[:per_key][:if] = Array.wrap(options[:per_key][:if])
      options[:per_key][:unless] = Array.wrap(options[:per_key][:unless])
    end

recompile!(_options, _per_key) click to toggle source

    # File lib/active_support/callbacks.rb, line 158
    def recompile!(_options, _per_key)
      _update_filter(self.options, _options)
      _update_filter(self.per_key, _per_key)

      @callback_id      = next_id
      @filter           = _compile_filter(@raw_filter)
      @compiled_options = _compile_options(@options)
                          _compile_per_key_options
    end

start(key=nil, object=nil) click to toggle source

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

    # File lib/active_support/callbacks.rb, line 180
    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                result = #{@filter}                halted = (#{chain.config[:terminator]})              end

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.