activesupport 3.1.0.rc1 → 3.1.0.rc2

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.

data/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
1
  *Rails 3.1.0 (unreleased)*
2
2
 
3
+ * ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. [Andrew White]
4
+
5
+ * Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton]
6
+
3
7
  * New reporting method Kernel#quietly. [fxn]
4
8
 
5
9
  * Add String#inquiry as a convenience method for turning a string into a StringInquirer object [DHH]
@@ -21,6 +21,8 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
+ require 'securerandom'
25
+
24
26
  module ActiveSupport
25
27
  class << self
26
28
  attr_accessor :load_all_hooks
@@ -30,7 +32,7 @@ module ActiveSupport
30
32
  self.load_all_hooks = []
31
33
 
32
34
  on_load_all do
33
- [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom]
35
+ [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte]
34
36
  end
35
37
  end
36
38
 
@@ -31,7 +31,7 @@ module ActiveSupport
31
31
  DELETED = "DELETED\r\n"
32
32
  end
33
33
 
34
- ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/
34
+ ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/n
35
35
 
36
36
  def self.build_mem_cache(*addresses)
37
37
  addresses = addresses.flatten
@@ -59,7 +59,7 @@ module Kernel
59
59
  raise unless exception_classes.any? { |cls| e.kind_of?(cls) }
60
60
  end
61
61
  end
62
-
62
+
63
63
  # Captures the given stream and returns it:
64
64
  #
65
65
  # stream = capture(:stdout) { puts "Cool" }
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/kernel/reporting'
2
+ require 'active_support/core_ext/module/deprecation'
2
3
 
3
4
  module Kernel
4
5
  # Require a library with fallback to RubyGems. Warnings during library
@@ -23,4 +24,5 @@ module Kernel
23
24
  end
24
25
  end
25
26
  end
27
+ deprecate :require_library_or_gem
26
28
  end
@@ -74,6 +74,7 @@ end
74
74
 
75
75
  module ActiveSupport #:nodoc:
76
76
  class SafeBuffer < String
77
+ UNSAFE_STRING_METHODS = ["capitalize", "chomp", "chop", "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", "upcase"].freeze
77
78
  alias safe_concat concat
78
79
 
79
80
  def concat(value)
@@ -110,6 +111,18 @@ module ActiveSupport #:nodoc:
110
111
 
111
112
  to_str.to_yaml(*args)
112
113
  end
114
+
115
+ for unsafe_method in UNSAFE_STRING_METHODS
116
+ class_eval <<-EOT, __FILE__, __LINE__
117
+ def #{unsafe_method}(*args)
118
+ super.to_str
119
+ end
120
+
121
+ def #{unsafe_method}!(*args)
122
+ raise TypeError, "Cannot modify SafeBuffer in place"
123
+ end
124
+ EOT
125
+ end
113
126
  end
114
127
  end
115
128
 
@@ -474,7 +474,7 @@ module ActiveSupport #:nodoc:
474
474
  raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
475
475
  end
476
476
 
477
- raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if local_const_defined?(from_mod, const_name)
477
+ raise NameError, "#{from_mod} is not missing constant #{const_name}!" if local_const_defined?(from_mod, const_name)
478
478
 
479
479
  qualified_name = qualified_name_for from_mod, const_name
480
480
  path_suffix = qualified_name.underscore
@@ -29,7 +29,7 @@ module ActiveSupport
29
29
 
30
30
  private
31
31
  def unique_id
32
- SecureRandom.hex(10)
32
+ ::SecureRandom.hex(10)
33
33
  end
34
34
  end
35
35
 
@@ -1,6 +1,6 @@
1
- require 'securerandom'
1
+ require 'active_support/deprecation'
2
2
 
3
3
  module ActiveSupport
4
4
  # Use Ruby's SecureRandom library.
5
- SecureRandom = ::SecureRandom # :nodoc:
5
+ SecureRandom = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('ActiveSupport::SecureRandom', ::SecureRandom) # :nodoc:
6
6
  end
@@ -9,7 +9,7 @@ module ActiveSupport
9
9
  module Testing
10
10
  module Performance
11
11
  extend ActiveSupport::Concern
12
-
12
+
13
13
  included do
14
14
  superclass_delegating_accessor :profile_options
15
15
  self.profile_options = {}
@@ -20,7 +20,7 @@ module ActiveSupport
20
20
  include ForClassicTestUnit
21
21
  end
22
22
  end
23
-
23
+
24
24
  # each implementation should define metrics and freeze the defaults
25
25
  DEFAULTS =
26
26
  if ARGV.include?('--benchmark') # HAX for rake test
@@ -32,7 +32,7 @@ module ActiveSupport
32
32
  :output => 'tmp/performance',
33
33
  :benchmark => false }
34
34
  end
35
-
35
+
36
36
  def full_profile_options
37
37
  DEFAULTS.merge(profile_options)
38
38
  end
@@ -40,7 +40,7 @@ module ActiveSupport
40
40
  def full_test_name
41
41
  "#{self.class.name}##{method_name}"
42
42
  end
43
-
43
+
44
44
  module ForMiniTest
45
45
  def run(runner)
46
46
  @runner = runner
@@ -53,7 +53,7 @@ module ActiveSupport
53
53
  end
54
54
  end
55
55
  end
56
-
56
+
57
57
  return
58
58
  end
59
59
 
@@ -122,7 +122,7 @@ module ActiveSupport
122
122
  protected
123
123
  # overridden by each implementation
124
124
  def run_gc; end
125
-
125
+
126
126
  def run_warmup
127
127
  run_gc
128
128
 
@@ -132,7 +132,7 @@ module ActiveSupport
132
132
 
133
133
  run_gc
134
134
  end
135
-
135
+
136
136
  def run_profile(metric)
137
137
  klass = full_profile_options[:benchmark] ? Benchmarker : Profiler
138
138
  performer = klass.new(self, metric)
@@ -163,7 +163,7 @@ module ActiveSupport
163
163
  "#{full_profile_options[:output]}/#{full_test_name}_#{@metric.name}"
164
164
  end
165
165
  end
166
-
166
+
167
167
  # overridden by each implementation
168
168
  class Profiler < Performer
169
169
  def time_with_block
@@ -171,7 +171,7 @@ module ActiveSupport
171
171
  yield
172
172
  Time.now - before
173
173
  end
174
-
174
+
175
175
  def run; end
176
176
  def record; end
177
177
  end
@@ -181,10 +181,10 @@ module ActiveSupport
181
181
  super
182
182
  @supported = @metric.respond_to?('measure')
183
183
  end
184
-
184
+
185
185
  def run
186
186
  return unless @supported
187
-
187
+
188
188
  full_profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
189
189
  @total = @metric.total
190
190
  end
@@ -237,7 +237,7 @@ module ActiveSupport
237
237
  "#{super}.csv"
238
238
  end
239
239
  end
240
-
240
+
241
241
  module Metrics
242
242
  def self.[](name)
243
243
  const_get(name.to_s.camelize)
@@ -247,7 +247,7 @@ module ActiveSupport
247
247
 
248
248
  class Base
249
249
  include ActionView::Helpers::NumberHelper
250
-
250
+
251
251
  attr_reader :total
252
252
 
253
253
  def initialize
@@ -265,15 +265,15 @@ module ActiveSupport
265
265
  @total += (measure - before)
266
266
  end
267
267
  end
268
-
268
+
269
269
  # overridden by each implementation
270
270
  def profile; end
271
-
271
+
272
272
  protected
273
273
  # overridden by each implementation
274
274
  def with_gc_stats; end
275
275
  end
276
-
276
+
277
277
  class Time < Base
278
278
  def measure
279
279
  ::Time.now.to_f
@@ -287,19 +287,19 @@ module ActiveSupport
287
287
  end
288
288
  end
289
289
  end
290
-
290
+
291
291
  class Amount < Base
292
292
  def format(measurement)
293
293
  number_with_delimiter(measurement.floor)
294
294
  end
295
295
  end
296
-
296
+
297
297
  class DigitalInformationUnit < Base
298
298
  def format(measurement)
299
299
  number_to_human_size(measurement, :precision => 2)
300
300
  end
301
301
  end
302
-
302
+
303
303
  # each implementation provides its own metrics like ProcessTime, Memory or GcRuns
304
304
  end
305
305
  end
@@ -1,6 +1,6 @@
1
1
  require 'jruby/profiler'
2
- require 'java'
3
- import java.lang.management.ManagementFactory
2
+ require 'java'
3
+ java_import java.lang.management.ManagementFactory
4
4
 
5
5
  module ActiveSupport
6
6
  module Testing
@@ -12,21 +12,21 @@ module ActiveSupport
12
12
  { :metrics => [:wall_time],
13
13
  :formats => [:flat, :graph] }
14
14
  end).freeze
15
-
15
+
16
16
  protected
17
17
  def run_gc
18
18
  ManagementFactory.memory_mx_bean.gc
19
- end
19
+ end
20
20
 
21
21
  class Profiler < Performer
22
22
  def initialize(*args)
23
23
  super
24
24
  @supported = @metric.is_a?(Metrics::WallTime)
25
25
  end
26
-
26
+
27
27
  def run
28
28
  return unless @supported
29
-
29
+
30
30
  @total = time_with_block do
31
31
  @data = JRuby::Profiler.profile do
32
32
  full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
@@ -36,7 +36,7 @@ module ActiveSupport
36
36
 
37
37
  def record
38
38
  return unless @supported
39
-
39
+
40
40
  klasses = full_profile_options[:formats].map { |f| JRuby::Profiler.const_get("#{f.to_s.camelize}ProfilePrinter") }.compact
41
41
 
42
42
  klasses.each do |klass|
@@ -61,7 +61,7 @@ module ActiveSupport
61
61
  end
62
62
  end
63
63
 
64
- module Metrics
64
+ module Metrics
65
65
  class Base
66
66
  def profile
67
67
  yield
@@ -85,7 +85,7 @@ module ActiveSupport
85
85
  ManagementFactory.thread_mx_bean.get_current_thread_cpu_time / 1000 / 1000 / 1000.0 # seconds
86
86
  end
87
87
  end
88
-
88
+
89
89
  class UserTime < Time
90
90
  def measure
91
91
  ManagementFactory.thread_mx_bean.get_current_thread_user_time / 1000 / 1000 / 1000.0 # seconds
@@ -97,7 +97,7 @@ module ActiveSupport
97
97
  ManagementFactory.memory_mx_bean.non_heap_memory_usage.used + ManagementFactory.memory_mx_bean.heap_memory_usage.used
98
98
  end
99
99
  end
100
-
100
+
101
101
  class GcRuns < Amount
102
102
  def measure
103
103
  ManagementFactory.garbage_collector_mx_beans.inject(0) { |total_runs, current_gc| total_runs += current_gc.collection_count }
@@ -10,12 +10,12 @@ module ActiveSupport
10
10
  { :metrics => [:wall_time],
11
11
  :formats => [:flat, :graph] }
12
12
  end).freeze
13
-
13
+
14
14
  protected
15
15
  def run_gc
16
16
  GC.run(true)
17
17
  end
18
-
18
+
19
19
  class Performer; end
20
20
 
21
21
  class Profiler < Performer
@@ -23,35 +23,35 @@ module ActiveSupport
23
23
  super
24
24
  @supported = @metric.is_a?(Metrics::WallTime)
25
25
  end
26
-
26
+
27
27
  def run
28
28
  return unless @supported
29
-
29
+
30
30
  @profiler = Rubinius::Profiler::Instrumenter.new
31
-
31
+
32
32
  @total = time_with_block do
33
33
  @profiler.profile(false) do
34
34
  full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
35
35
  end
36
36
  end
37
37
  end
38
-
38
+
39
39
  def record
40
40
  return unless @supported
41
-
41
+
42
42
  if(full_profile_options[:formats].include?(:flat))
43
43
  create_path_and_open_file(:flat) do |file|
44
44
  @profiler.show(file)
45
45
  end
46
46
  end
47
-
47
+
48
48
  if(full_profile_options[:formats].include?(:graph))
49
49
  create_path_and_open_file(:graph) do |file|
50
50
  @profiler.show(file)
51
51
  end
52
52
  end
53
53
  end
54
-
54
+
55
55
  protected
56
56
  def create_path_and_open_file(printer_name)
57
57
  fname = "#{output_filename}_#{printer_name}.txt"
@@ -62,10 +62,10 @@ module ActiveSupport
62
62
  end
63
63
  end
64
64
 
65
- module Metrics
65
+ module Metrics
66
66
  class Base
67
67
  attr_reader :loopback
68
-
68
+
69
69
  def profile
70
70
  yield
71
71
  end
@@ -16,7 +16,7 @@ module ActiveSupport
16
16
  :metrics => [:process_time, :memory, :objects],
17
17
  :formats => [:flat, :graph_html, :call_tree, :call_stack] }
18
18
  end).freeze
19
-
19
+
20
20
  protected
21
21
  def run_gc
22
22
  GC.start
@@ -77,7 +77,7 @@ module ActiveSupport
77
77
  def measure_mode
78
78
  self.class::Mode
79
79
  end
80
-
80
+
81
81
  def profile
82
82
  RubyProf.resume
83
83
  yield
@@ -91,7 +91,7 @@ module ActiveSupport
91
91
  yield
92
92
  end
93
93
  end
94
-
94
+
95
95
  class ProcessTime < Time
96
96
  Mode = RubyProf::PROCESS_TIME if RubyProf.const_defined?(:PROCESS_TIME)
97
97
 
@@ -15,7 +15,7 @@ module ActiveSupport
15
15
  end
16
16
  end
17
17
  end
18
-
18
+
19
19
  class Memory < DigitalInformationUnit
20
20
  # Ruby 1.8 + ruby-prof wrapper
21
21
  if RubyProf.respond_to?(:measure_memory)
@@ -24,7 +24,7 @@ module ActiveSupport
24
24
  end
25
25
  end
26
26
  end
27
-
27
+
28
28
  class Objects < Amount
29
29
  # Ruby 1.8 + ruby-prof wrapper
30
30
  if RubyProf.respond_to?(:measure_allocations)
@@ -33,7 +33,7 @@ module ActiveSupport
33
33
  end
34
34
  end
35
35
  end
36
-
36
+
37
37
  class GcRuns < Amount
38
38
  # Ruby 1.8 + ruby-prof wrapper
39
39
  if RubyProf.respond_to?(:measure_gc_runs)
@@ -42,7 +42,7 @@ module ActiveSupport
42
42
  end
43
43
  end
44
44
  end
45
-
45
+
46
46
  class GcTime < Time
47
47
  # Ruby 1.8 + ruby-prof wrapper
48
48
  if RubyProf.respond_to?(:measure_gc_time)
@@ -55,5 +55,3 @@ module ActiveSupport
55
55
  end
56
56
  end
57
57
  end
58
-
59
-
@@ -15,7 +15,7 @@ module ActiveSupport
15
15
  end
16
16
  end
17
17
  end
18
-
18
+
19
19
  class Memory < DigitalInformationUnit
20
20
  # Ruby 1.9 + GCdata patch
21
21
  if GC.respond_to?(:malloc_allocated_size)
@@ -24,7 +24,7 @@ module ActiveSupport
24
24
  end
25
25
  end
26
26
  end
27
-
27
+
28
28
  class Objects < Amount
29
29
  # Ruby 1.9 + GCdata patch
30
30
  if GC.respond_to?(:malloc_allocations)
@@ -33,7 +33,7 @@ module ActiveSupport
33
33
  end
34
34
  end
35
35
  end
36
-
36
+
37
37
  class GcRuns < Amount
38
38
  # Ruby 1.9
39
39
  if GC.respond_to?(:count)
@@ -42,7 +42,7 @@ module ActiveSupport
42
42
  end
43
43
  end
44
44
  end
45
-
45
+
46
46
  class GcTime < Time
47
47
  # Ruby 1.9 with GC::Profiler
48
48
  if defined?(GC::Profiler) && GC::Profiler.respond_to?(:total_time)
@@ -3,7 +3,7 @@ module ActiveSupport
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
5
  TINY = 0
6
- PRE = "rc1"
6
+ PRE = "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
@@ -5,12 +5,12 @@ include Java
5
5
 
6
6
  require 'active_support/core_ext/object/blank'
7
7
 
8
- import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder
9
- import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory
10
- import java.io.StringReader unless defined? StringReader
11
- import org.xml.sax.InputSource unless defined? InputSource
12
- import org.xml.sax.Attributes unless defined? Attributes
13
- import org.w3c.dom.Node unless defined? Node
8
+ java_import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder
9
+ java_import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory
10
+ java_import java.io.StringReader unless defined? StringReader
11
+ java_import org.xml.sax.InputSource unless defined? InputSource
12
+ java_import org.xml.sax.Attributes unless defined? Attributes
13
+ java_import org.w3c.dom.Node unless defined? Node
14
14
 
15
15
  # = XmlMini JRuby JDOM implementation
16
16
  module ActiveSupport
@@ -41,7 +41,7 @@ module ActiveSupport
41
41
  xml_string_reader = StringReader.new(data)
42
42
  xml_input_source = InputSource.new(xml_string_reader)
43
43
  doc = @dbf.new_document_builder.parse(xml_input_source)
44
- merge_element!({}, doc.document_element)
44
+ merge_element!({CONTENT_KEY => ''}, doc.document_element)
45
45
  end
46
46
  end
47
47
 
@@ -54,9 +54,14 @@ module ActiveSupport
54
54
  # element::
55
55
  # XML element to merge into hash
56
56
  def merge_element!(hash, element)
57
+ delete_empty(hash)
57
58
  merge!(hash, element.tag_name, collapse(element))
58
59
  end
59
60
 
61
+ def delete_empty(hash)
62
+ hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ''
63
+ end
64
+
60
65
  # Actually converts an XML document element into a data structure.
61
66
  #
62
67
  # element::
@@ -84,6 +89,7 @@ module ActiveSupport
84
89
  # element::
85
90
  # XML element whose texts are to me merged into the hash
86
91
  def merge_texts!(hash, element)
92
+ delete_empty(hash)
87
93
  text_children = texts(element)
88
94
  if text_children.join.empty?
89
95
  hash
@@ -128,8 +134,9 @@ module ActiveSupport
128
134
  attribute_hash = {}
129
135
  attributes = element.attributes
130
136
  for i in 0...attributes.length
131
- attribute_hash[attributes.item(i).name] = attributes.item(i).value
132
- end
137
+ attribute_hash[CONTENT_KEY] ||= ''
138
+ attribute_hash[attributes.item(i).name] = attributes.item(i).value
139
+ end
133
140
  attribute_hash
134
141
  end
135
142
 
metadata CHANGED
@@ -1,8 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 15424097
4
5
  prerelease: 6
5
- version: 3.1.0.rc1
6
+ segments:
7
+ - 3
8
+ - 1
9
+ - 0
10
+ - rc
11
+ - 2
12
+ version: 3.1.0.rc2
6
13
  platform: ruby
7
14
  authors:
8
15
  - David Heinemeier Hansson
@@ -10,8 +17,7 @@ autorequire:
10
17
  bindir: bin
11
18
  cert_chain: []
12
19
 
13
- date: 2011-05-21 00:00:00 -05:00
14
- default_executable:
20
+ date: 2011-06-07 00:00:00 Z
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: multi_json
@@ -21,6 +27,10 @@ dependencies:
21
27
  requirements:
22
28
  - - ~>
23
29
  - !ruby/object:Gem::Version
30
+ hash: 15
31
+ segments:
32
+ - 1
33
+ - 0
24
34
  version: "1.0"
25
35
  type: :runtime
26
36
  version_requirements: *id001
@@ -246,7 +256,6 @@ files:
246
256
  - lib/active_support/xml_mini/rexml.rb
247
257
  - lib/active_support/xml_mini.rb
248
258
  - lib/active_support.rb
249
- has_rdoc: true
250
259
  homepage: http://www.rubyonrails.org
251
260
  licenses: []
252
261
 
@@ -260,17 +269,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
260
269
  requirements:
261
270
  - - ">="
262
271
  - !ruby/object:Gem::Version
272
+ hash: 57
273
+ segments:
274
+ - 1
275
+ - 8
276
+ - 7
263
277
  version: 1.8.7
264
278
  required_rubygems_version: !ruby/object:Gem::Requirement
265
279
  none: false
266
280
  requirements:
267
281
  - - ">"
268
282
  - !ruby/object:Gem::Version
283
+ hash: 25
284
+ segments:
285
+ - 1
286
+ - 3
287
+ - 1
269
288
  version: 1.3.1
270
289
  requirements: []
271
290
 
272
291
  rubyforge_project:
273
- rubygems_version: 1.6.2
292
+ rubygems_version: 1.8.2
274
293
  signing_key:
275
294
  specification_version: 3
276
295
  summary: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.