activesupport 3.1.0.rc4 → 3.1.0.rc5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

@@ -1,12 +1,12 @@
1
1
  module ActiveSupport
2
- # Many backtraces include too much information that's not relevant for the context. This makes it hard to find the signal
3
- # in the backtrace and adds debugging time. With a BacktraceCleaner, you can setup filters and silencers for your particular
4
- # context, so only the relevant lines are included.
2
+ # Backtraces often include many lines that are not relevant for the context under review. This makes it hard to find the
3
+ # signal amongst the backtrace noise, and adds debugging time. With a BacktraceCleaner, filters and silencers are used to
4
+ # remove the noisy lines, so that only the most relevant lines remain.
5
5
  #
6
- # If you need to reconfigure an existing BacktraceCleaner, like the one in Rails, to show as much as possible, you can always
7
- # call BacktraceCleaner#remove_silencers! Also, if you need to reconfigure an existing BacktraceCleaner so that it does not
8
- # filter or modify the paths of any lines of the backtrace, you can call BacktraceCleaner#remove_filters! These two methods
9
- # will give you a completely untouched backtrace.
6
+ # Filters are used to modify lines of data, while silencers are used to remove lines entirely. The typical filter use case
7
+ # is to remove lengthy path information from the start of each line, and view file paths relevant to the app directory
8
+ # instead of the file system root. The typical silencer use case is to exclude the output of a noisy library from the
9
+ # backtrace, so that you can focus on the rest.
10
10
  #
11
11
  # ==== Example:
12
12
  #
@@ -15,13 +15,18 @@ module ActiveSupport
15
15
  # bc.add_silencer { |line| line =~ /mongrel|rubygems/ }
16
16
  # bc.clean(exception.backtrace) # will strip the Rails.root prefix and skip any lines from mongrel or rubygems
17
17
  #
18
+ # To reconfigure an existing BacktraceCleaner (like the default one in Rails) and show as much data as possible, you can
19
+ # always call <tt>BacktraceCleaner#remove_silencers!</tt>, which will restore the backtrace to a pristine state. If you
20
+ # need to reconfigure an existing BacktraceCleaner so that it does not filter or modify the paths of any lines of the
21
+ # backtrace, you can call BacktraceCleaner#remove_filters! These two methods will give you a completely untouched backtrace.
22
+ #
18
23
  # Inspired by the Quiet Backtrace gem by Thoughtbot.
19
24
  class BacktraceCleaner
20
25
  def initialize
21
26
  @filters, @silencers = [], []
22
27
  end
23
28
 
24
- # Returns the backtrace after all filters and silencers has been run against it. Filters run first, then silencers.
29
+ # Returns the backtrace after all filters and silencers have been run against it. Filters run first, then silencers.
25
30
  def clean(backtrace, kind = :silent)
26
31
  filtered = filter(backtrace)
27
32
 
@@ -45,8 +50,8 @@ module ActiveSupport
45
50
  @filters << block
46
51
  end
47
52
 
48
- # Adds a silencer from the block provided. If the silencer returns true for a given line, it'll be excluded from the
49
- # clean backtrace.
53
+ # Adds a silencer from the block provided. If the silencer returns true for a given line, it will be excluded from
54
+ # the clean backtrace.
50
55
  #
51
56
  # Example:
52
57
  #
@@ -57,7 +62,7 @@ module ActiveSupport
57
62
  end
58
63
 
59
64
  # Will remove all silencers, but leave in the filters. This is useful if your context of debugging suddenly expands as
60
- # you suspect a bug in the libraries you use.
65
+ # you suspect a bug in one of the libraries you use.
61
66
  def remove_silencers!
62
67
  @silencers = []
63
68
  end
@@ -16,7 +16,7 @@ module ActiveSupport
16
16
 
17
17
  def initialize(cache_path, options = nil)
18
18
  super(options)
19
- @cache_path = cache_path
19
+ @cache_path = cache_path.to_s
20
20
  extend Strategy::LocalCache
21
21
  end
22
22
 
@@ -12,12 +12,12 @@ module ActiveSupport
12
12
 
13
13
  class Configuration < ActiveSupport::InheritableOptions
14
14
  def compile_methods!
15
- self.class.compile_methods!(keys.reject {|key| respond_to?(key)})
15
+ self.class.compile_methods!(keys)
16
16
  end
17
17
 
18
18
  # compiles reader methods so we don't have to go through method_missing
19
19
  def self.compile_methods!(keys)
20
- keys.each do |key|
20
+ keys.reject { |m| method_defined?(m) }.each do |key|
21
21
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
22
22
  def #{key}; _get(#{key.inspect}); end
23
23
  RUBY
@@ -14,7 +14,7 @@ class Array
14
14
  # This method is similar in purpose to <tt>Kernel#Array</tt>, but there are some differences:
15
15
  #
16
16
  # * If the argument responds to +to_ary+ the method is invoked. <tt>Kernel#Array</tt>
17
- # moves on to try +to_a+ if the returned value is +nil+, but <tt>Arraw.wrap</tt> returns
17
+ # moves on to try +to_a+ if the returned value is +nil+, but <tt>Array.wrap</tt> returns
18
18
  # such a +nil+ right away.
19
19
  # * If the returned value from +to_ary+ is neither +nil+ nor an +Array+ object, <tt>Kernel#Array</tt>
20
20
  # raises an exception, while <tt>Array.wrap</tt> does not, it just returns the value.
@@ -1,5 +1,6 @@
1
1
  require 'active_support/core_ext/kernel/singleton_class'
2
2
  require 'active_support/core_ext/module/remove_method'
3
+ require 'active_support/core_ext/array/extract_options'
3
4
 
4
5
  class Class
5
6
  # Declare a class-level attribute whose value is inheritable by subclasses.
@@ -56,11 +57,18 @@ class Class
56
57
  # object.setting # => false
57
58
  # Base.setting # => true
58
59
  #
60
+ # To opt out of the instance reader method, pass :instance_reader => false.
61
+ #
62
+ # object.setting # => NoMethodError
63
+ # object.setting? # => NoMethodError
64
+ #
59
65
  # To opt out of the instance writer method, pass :instance_writer => false.
60
66
  #
61
67
  # object.setting = false # => NoMethodError
62
68
  def class_attribute(*attrs)
63
- instance_writer = !attrs.last.is_a?(Hash) || attrs.pop[:instance_writer]
69
+ options = attrs.extract_options!
70
+ instance_reader = options.fetch(:instance_reader, true)
71
+ instance_writer = options.fetch(:instance_writer, true)
64
72
 
65
73
  attrs.each do |name|
66
74
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -84,13 +92,15 @@ class Class
84
92
  val
85
93
  end
86
94
 
87
- remove_possible_method :#{name}
88
- def #{name}
89
- defined?(@#{name}) ? @#{name} : self.class.#{name}
90
- end
95
+ if instance_reader
96
+ remove_possible_method :#{name}
97
+ def #{name}
98
+ defined?(@#{name}) ? @#{name} : self.class.#{name}
99
+ end
91
100
 
92
- def #{name}?
93
- !!#{name}
101
+ def #{name}?
102
+ !!#{name}
103
+ end
94
104
  end
95
105
  RUBY
96
106
 
@@ -100,12 +110,6 @@ class Class
100
110
 
101
111
  private
102
112
  def singleton_class?
103
- # in case somebody is crazy enough to overwrite allocate
104
- allocate = Class.instance_method(:allocate)
105
- # object.class always points to a real (non-singleton) class
106
- allocate.bind(self).call.class != self
107
- rescue TypeError
108
- # MRI/YARV/JRuby all disallow creating new instances of a singleton class
109
- true
113
+ !name || '' == name
110
114
  end
111
115
  end
@@ -96,7 +96,7 @@ module Enumerable
96
96
  # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1.
97
97
  # Can be called with a block too, much like any?, so people.many? { |p| p.age > 26 } returns true if more than 1 person is over 26.
98
98
  def many?(&block)
99
- size = block_given? ? select(&block).size : self.size
99
+ size = block_given? ? count(&block) : self.size
100
100
  size > 1
101
101
  end
102
102
 
@@ -11,7 +11,7 @@ class Hash
11
11
  end
12
12
 
13
13
  # Called when object is nested under an object that receives
14
- # #with_indifferent_access. This method with be called on the current object
14
+ # #with_indifferent_access. This method will be called on the current object
15
15
  # by the enclosing object and is aliased to #with_indifferent_access by
16
16
  # default. Subclasses of Hash may overwrite this method to return +self+ if
17
17
  # converting to an +ActiveSupport::HashWithIndifferentAccess+ would not be
@@ -127,10 +127,6 @@ class Module
127
127
  end
128
128
 
129
129
  module_eval(<<-EOS, file, line - 5)
130
- if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}")
131
- remove_possible_method("#{prefix}#{method}")
132
- end
133
-
134
130
  def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
135
131
  #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block)
136
132
  rescue NoMethodError # rescue NoMethodError
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'date'
2
3
  require 'active_support/core_ext/time/publicize_conversion_methods'
3
4
  require 'active_support/core_ext/time/calculations'
@@ -35,7 +35,7 @@ class String
35
35
  # object. Interoperability problems can be resolved easily with a +to_s+ call.
36
36
  #
37
37
  # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars. For
38
- # information about how to change the default Multibyte behaviour see ActiveSupport::Multibyte.
38
+ # information about how to change the default Multibyte behavior see ActiveSupport::Multibyte.
39
39
  def mb_chars
40
40
  if ActiveSupport::Multibyte.proxy_class.consumes?(self)
41
41
  ActiveSupport::Multibyte.proxy_class.new(self)
@@ -67,7 +67,7 @@ class Object
67
67
  end
68
68
  end
69
69
 
70
- class Fixnum
70
+ class Numeric
71
71
  def html_safe?
72
72
  true
73
73
  end
@@ -76,10 +76,33 @@ end
76
76
  module ActiveSupport #:nodoc:
77
77
  class SafeBuffer < String
78
78
  UNSAFE_STRING_METHODS = ["capitalize", "chomp", "chop", "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", "upcase"].freeze
79
- alias safe_concat concat
79
+
80
+ alias_method :original_concat, :concat
81
+ private :original_concat
82
+
83
+ class SafeConcatError < StandardError
84
+ def initialize
85
+ super "Could not concatenate to the buffer because it is not html safe."
86
+ end
87
+ end
88
+
89
+ def safe_concat(value)
90
+ raise SafeConcatError if dirty?
91
+ original_concat(value)
92
+ end
93
+
94
+ def initialize(*)
95
+ @dirty = false
96
+ super
97
+ end
98
+
99
+ def initialize_copy(other)
100
+ super
101
+ @dirty = other.dirty?
102
+ end
80
103
 
81
104
  def concat(value)
82
- if value.html_safe?
105
+ if dirty? || value.html_safe?
83
106
  super(value)
84
107
  else
85
108
  super(ERB::Util.h(value))
@@ -92,15 +115,15 @@ module ActiveSupport #:nodoc:
92
115
  end
93
116
 
94
117
  def html_safe?
95
- true
118
+ !dirty?
96
119
  end
97
120
 
98
- def html_safe
121
+ def to_s
99
122
  self
100
123
  end
101
124
 
102
- def to_s
103
- self
125
+ def to_param
126
+ to_str
104
127
  end
105
128
 
106
129
  def encode_with(coder)
@@ -109,7 +132,6 @@ module ActiveSupport #:nodoc:
109
132
 
110
133
  def to_yaml(*args)
111
134
  return super() if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
112
-
113
135
  to_str.to_yaml(*args)
114
136
  end
115
137
 
@@ -120,18 +142,21 @@ module ActiveSupport #:nodoc:
120
142
  end
121
143
 
122
144
  def #{unsafe_method}!(*args)
123
- raise TypeError, "Cannot modify SafeBuffer in place"
145
+ @dirty = true
146
+ super
124
147
  end
125
148
  EOT
126
149
  end
150
+
151
+ protected
152
+
153
+ def dirty?
154
+ @dirty
155
+ end
127
156
  end
128
157
  end
129
158
 
130
159
  class String
131
- def html_safe!
132
- raise "You can't call html_safe! on a String"
133
- end
134
-
135
160
  def html_safe
136
161
  ActiveSupport::SafeBuffer.new(self)
137
162
  end
@@ -651,17 +651,6 @@ module ActiveSupport #:nodoc:
651
651
  return []
652
652
  end
653
653
 
654
- class LoadingModule #:nodoc:
655
- # Old style environment.rb referenced this method directly. Please note, it doesn't
656
- # actually *do* anything any more.
657
- def self.root(*args)
658
- if defined?(Rails) && Rails.logger
659
- Rails.logger.warn "Your environment.rb uses the old syntax, it may not continue to work in future releases."
660
- Rails.logger.warn "For upgrade instructions please see: http://manuals.rubyonrails.com/read/book/19"
661
- end
662
- end
663
- end
664
-
665
654
  # Convert the provided const desc to a qualified constant name (as a string).
666
655
  # A module, class, symbol, or string may be provided.
667
656
  def to_constant_name(desc) #:nodoc:
@@ -7,12 +7,12 @@ module ActiveSupport
7
7
  # Whether to print a backtrace along with the warning.
8
8
  attr_accessor :debug
9
9
 
10
- # Returns the set behaviour or if one isn't set, defaults to +:stderr+
10
+ # Returns the set behavior or if one isn't set, defaults to +:stderr+
11
11
  def behavior
12
12
  @behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
13
13
  end
14
14
 
15
- # Sets the behaviour to the specified value. Can be a single value or an array.
15
+ # Sets the behavior to the specified value. Can be a single value or an array.
16
16
  #
17
17
  # Examples
18
18
  #
@@ -6,6 +6,8 @@ require 'active_support/core_ext/hash/keys'
6
6
 
7
7
  module ActiveSupport
8
8
  class HashWithIndifferentAccess < Hash
9
+
10
+ # Always returns true, so that <tt>Array#extract_options!</tt> finds members of this class.
9
11
  def extractable_options?
10
12
  true
11
13
  end
@@ -3,8 +3,8 @@ require 'active_support/core_ext/class/attribute'
3
3
 
4
4
  module ActiveSupport
5
5
  # ActiveSupport::LogSubscriber is an object set to consume ActiveSupport::Notifications
6
- # with solely purpose of logging. The log subscriber dispatches notifications to a
7
- # registered object based on its given namespace.
6
+ # with the sole purpose of logging them. The log subscriber dispatches notifications to
7
+ # a registered object based on its given namespace.
8
8
  #
9
9
  # An example would be Active Record log subscriber responsible for logging queries:
10
10
  #
@@ -109,8 +109,8 @@ module ActiveSupport
109
109
 
110
110
  # Set color by using a string or one of the defined constants. If a third
111
111
  # option is set to true, it also adds bold to the string. This is based
112
- # on Highline implementation and it automatically appends CLEAR to the end
113
- # of the returned String.
112
+ # on the Highline implementation and will automatically append CLEAR to the
113
+ # end of the returned String.
114
114
  #
115
115
  def color(text, color, bold=false)
116
116
  return text unless colorize_logging
@@ -331,8 +331,7 @@ module ActiveSupport #:nodoc:
331
331
  # when the storage for a string is limited for some reason.
332
332
  #
333
333
  # Example:
334
- # s = 'こんにちは'
335
- # s.mb_chars.limit(7) # => "こに"
334
+ # 'こんにちは'.mb_chars.limit(7).to_s # => "こん"
336
335
  def limit(limit)
337
336
  slice(0...translate_offset(limit))
338
337
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module ActiveSupport
2
3
  module Multibyte
3
4
  module Unicode
@@ -36,6 +36,10 @@ module ActiveSupport #:nodoc:
36
36
  self[name]
37
37
  end
38
38
  end
39
+
40
+ def respond_to?(name)
41
+ true
42
+ end
39
43
  end
40
44
 
41
45
  class InheritableOptions < OrderedOptions
@@ -3,7 +3,7 @@ module ActiveSupport
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
5
  TINY = 0
6
- PRE = "rc4"
6
+ PRE = "rc5"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424109
5
- prerelease: 6
4
+ prerelease: true
6
5
  segments:
7
6
  - 3
8
7
  - 1
9
8
  - 0
10
- - rc
11
- - 4
12
- version: 3.1.0.rc4
9
+ - rc5
10
+ version: 3.1.0.rc5
13
11
  platform: ruby
14
12
  authors:
15
13
  - David Heinemeier Hansson
@@ -17,17 +15,16 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2011-06-09 00:00:00 Z
18
+ date: 2011-07-25 00:00:00 -07:00
19
+ default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: multi_json
24
23
  prerelease: false
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
25
  requirements:
28
26
  - - ~>
29
27
  - !ruby/object:Gem::Version
30
- hash: 15
31
28
  segments:
32
29
  - 1
33
30
  - 0
@@ -256,6 +253,7 @@ files:
256
253
  - lib/active_support/xml_mini/rexml.rb
257
254
  - lib/active_support/xml_mini.rb
258
255
  - lib/active_support.rb
256
+ has_rdoc: true
259
257
  homepage: http://www.rubyonrails.org
260
258
  licenses: []
261
259
 
@@ -265,22 +263,18 @@ rdoc_options: []
265
263
  require_paths:
266
264
  - lib
267
265
  required_ruby_version: !ruby/object:Gem::Requirement
268
- none: false
269
266
  requirements:
270
267
  - - ">="
271
268
  - !ruby/object:Gem::Version
272
- hash: 57
273
269
  segments:
274
270
  - 1
275
271
  - 8
276
272
  - 7
277
273
  version: 1.8.7
278
274
  required_rubygems_version: !ruby/object:Gem::Requirement
279
- none: false
280
275
  requirements:
281
276
  - - ">"
282
277
  - !ruby/object:Gem::Version
283
- hash: 25
284
278
  segments:
285
279
  - 1
286
280
  - 3
@@ -289,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
283
  requirements: []
290
284
 
291
285
  rubyforge_project:
292
- rubygems_version: 1.8.2
286
+ rubygems_version: 1.3.6
293
287
  signing_key:
294
288
  specification_version: 3
295
289
  summary: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.