123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Deprecation::Deprecators

Relationships & Source Files
Inherits: Object
Defined in: activesupport/lib/active_support/deprecation/deprecators.rb

Overview

A managed collection of deprecators. Configuration methods, such as #behavior=, affect all deprecators in the collection. Additionally, the #silence method silences all deprecators in the collection for the duration of a given block.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newDeprecators

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 10

def initialize
  @options = {}
  @deprecators = {}
end

Instance Attribute Details

#behavior=(behavior) (writeonly)

Sets the deprecation warning behavior for all deprecators in this collection.

See ActiveSupport::Deprecation#behavior=.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 60

def behavior=(behavior)
  set_option(:behavior, behavior)
end

#debug=(debug) (writeonly)

Sets the debug flag for all deprecators in this collection.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 52

def debug=(debug)
  set_option(:debug, debug)
end

#disallowed_behavior=(disallowed_behavior) (writeonly)

Sets the disallowed deprecation warning behavior for all deprecators in this collection.

See ActiveSupport::Deprecation#disallowed_behavior=.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 68

def disallowed_behavior=(disallowed_behavior)
  set_option(:disallowed_behavior, disallowed_behavior)
end

#disallowed_warnings=(disallowed_warnings) (writeonly)

Sets the disallowed deprecation warnings for all deprecators in this collection.

See ActiveSupport::Deprecation#disallowed_warnings=.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 76

def disallowed_warnings=(disallowed_warnings)
  set_option(:disallowed_warnings, disallowed_warnings)
end

#silenced=(silenced) (writeonly)

Sets the silenced flag for all deprecators in this collection.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 47

def silenced=(silenced)
  set_option(:silenced, silenced)
end

Instance Method Details

#[](name)

Returns a deprecator added to this collection via #[]=.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 16

def [](name)
  @deprecators[name]
end

#[]=(name, deprecator)

Adds a given ActiveSupport.deprecator to this collection. The deprecator will be immediately configured with any options previously set on this collection.

deprecators = ActiveSupport::Deprecation::Deprecators.new
deprecators.debug = true

foo_deprecator = ActiveSupport::Deprecation.new("2.0", "Foo")
foo_deprecator.debug    # => false

deprecators[:foo] = foo_deprecator
deprecators[:foo].debug # => true
foo_deprecator.debug    # => true
[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 34

def []=(name, deprecator)
  apply_options(deprecator)
  @deprecators[name] = deprecator
end

#apply_options(deprecator) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 97

def apply_options(deprecator)
  @options.each do |name, value|
    deprecator.public_send("#{name}=", value)
  end
end

#each(&block)

Iterates over all deprecators in this collection. If no block is given, returns an Enumerator.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 41

def each(&block)
  return to_enum(__method__) unless block
  @deprecators.each_value(&block)
end

#set_option(name, value) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 92

def set_option(name, value)
  @options[name] = value
  each { |deprecator| deprecator.public_send("#{name}=", value) }
end

#silence(&block)

Silences all deprecators in this collection for the duration of the given block.

See ActiveSupport::Deprecation#silence.

[ GitHub ]

  
# File 'activesupport/lib/active_support/deprecation/deprecators.rb', line 84

def silence(&block)
  each { |deprecator| deprecator.begin_silence }
  block.call
ensure
  each { |deprecator| deprecator.end_silence }
end