activesupport 3.0.20 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. data/CHANGELOG +24 -28
  2. data/README.rdoc +2 -2
  3. data/lib/active_support/backtrace_cleaner.rb +17 -12
  4. data/lib/active_support/buffered_logger.rb +7 -9
  5. data/lib/active_support/cache/file_store.rb +4 -3
  6. data/lib/active_support/cache/mem_cache_store.rb +10 -2
  7. data/lib/active_support/cache/strategy/local_cache.rb +28 -23
  8. data/lib/active_support/cache.rb +11 -14
  9. data/lib/active_support/callbacks.rb +195 -175
  10. data/lib/active_support/concern.rb +105 -35
  11. data/lib/active_support/configurable.rb +50 -8
  12. data/lib/active_support/core_ext/array/access.rb +2 -2
  13. data/lib/active_support/core_ext/array/conversions.rb +2 -2
  14. data/lib/active_support/core_ext/array/random_access.rb +10 -7
  15. data/lib/active_support/core_ext/array/uniq_by.rb +2 -3
  16. data/lib/active_support/core_ext/array/wrap.rb +1 -1
  17. data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -2
  18. data/lib/active_support/core_ext/class/attribute.rb +15 -1
  19. data/lib/active_support/core_ext/class/inheritable_attributes.rb +10 -86
  20. data/lib/active_support/core_ext/class/subclasses.rb +20 -34
  21. data/lib/active_support/core_ext/date/calculations.rb +17 -5
  22. data/lib/active_support/core_ext/date/conversions.rb +9 -2
  23. data/lib/active_support/core_ext/date_time/calculations.rb +26 -9
  24. data/lib/active_support/core_ext/date_time/conversions.rb +9 -9
  25. data/lib/active_support/core_ext/date_time/zones.rb +1 -1
  26. data/lib/active_support/core_ext/enumerable.rb +3 -6
  27. data/lib/active_support/core_ext/float/rounding.rb +1 -1
  28. data/lib/active_support/core_ext/hash/conversions.rb +22 -34
  29. data/lib/active_support/core_ext/hash/deep_dup.rb +11 -0
  30. data/lib/active_support/core_ext/hash/indifferent_access.rb +12 -0
  31. data/lib/active_support/core_ext/hash/keys.rb +6 -4
  32. data/lib/active_support/core_ext/hash/reverse_merge.rb +9 -14
  33. data/lib/active_support/core_ext/hash/slice.rb +3 -1
  34. data/lib/active_support/core_ext/hash.rb +1 -0
  35. data/lib/active_support/core_ext/integer/inflections.rb +7 -4
  36. data/lib/active_support/core_ext/kernel/reporting.rb +31 -0
  37. data/lib/active_support/core_ext/kernel/requires.rb +2 -0
  38. data/lib/active_support/core_ext/logger.rb +11 -38
  39. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +12 -12
  40. data/lib/active_support/core_ext/module/attr_internal.rb +13 -6
  41. data/lib/active_support/core_ext/module/delegation.rb +1 -5
  42. data/lib/active_support/core_ext/module/remove_method.rb +7 -2
  43. data/lib/active_support/core_ext/numeric/time.rb +2 -0
  44. data/lib/active_support/core_ext/object/blank.rb +45 -12
  45. data/lib/active_support/core_ext/object/duplicable.rb +50 -9
  46. data/lib/active_support/core_ext/object/inclusion.rb +15 -0
  47. data/lib/active_support/core_ext/object/instance_variables.rb +1 -35
  48. data/lib/active_support/core_ext/object/to_param.rb +13 -8
  49. data/lib/active_support/core_ext/object/to_query.rb +2 -2
  50. data/lib/active_support/core_ext/object/try.rb +29 -10
  51. data/lib/active_support/core_ext/object/with_options.rb +25 -8
  52. data/lib/active_support/core_ext/object.rb +1 -1
  53. data/lib/active_support/core_ext/range/cover.rb +3 -0
  54. data/lib/active_support/core_ext/range.rb +1 -0
  55. data/lib/active_support/core_ext/string/behavior.rb +1 -2
  56. data/lib/active_support/core_ext/string/conversions.rb +1 -0
  57. data/lib/active_support/core_ext/string/exclude.rb +1 -1
  58. data/lib/active_support/core_ext/string/filters.rb +3 -3
  59. data/lib/active_support/core_ext/string/inflections.rb +1 -1
  60. data/lib/active_support/core_ext/string/inquiry.rb +13 -0
  61. data/lib/active_support/core_ext/string/multibyte.rb +2 -2
  62. data/lib/active_support/core_ext/string/output_safety.rb +45 -62
  63. data/lib/active_support/core_ext/string.rb +1 -0
  64. data/lib/active_support/core_ext/time/calculations.rb +19 -16
  65. data/lib/active_support/core_ext/time/conversions.rb +2 -24
  66. data/lib/active_support/core_ext/time/zones.rb +32 -21
  67. data/lib/active_support/core_ext/uri.rb +8 -0
  68. data/lib/active_support/dependencies.rb +74 -28
  69. data/lib/active_support/deprecation/behaviors.rb +7 -0
  70. data/lib/active_support/deprecation/proxy_wrappers.rb +1 -1
  71. data/lib/active_support/deprecation/reporting.rb +4 -0
  72. data/lib/active_support/deprecation.rb +2 -2
  73. data/lib/active_support/descendants_tracker.rb +9 -7
  74. data/lib/active_support/duration.rb +5 -0
  75. data/lib/active_support/file_update_checker.rb +1 -1
  76. data/lib/active_support/file_watcher.rb +36 -0
  77. data/lib/active_support/hash_with_indifferent_access.rb +20 -8
  78. data/lib/active_support/i18n.rb +0 -1
  79. data/lib/active_support/i18n_railtie.rb +2 -2
  80. data/lib/active_support/inflections.rb +1 -0
  81. data/lib/active_support/inflector/inflections.rb +1 -1
  82. data/lib/active_support/inflector/methods.rb +5 -3
  83. data/lib/active_support/json/decoding.rb +37 -23
  84. data/lib/active_support/json/encoding.rb +12 -4
  85. data/lib/active_support/lazy_load_hooks.rb +7 -7
  86. data/lib/active_support/log_subscriber/test_helper.rb +5 -3
  87. data/lib/active_support/log_subscriber.rb +6 -6
  88. data/lib/active_support/message_encryptor.rb +1 -1
  89. data/lib/active_support/message_verifier.rb +1 -1
  90. data/lib/active_support/multibyte/chars.rb +5 -5
  91. data/lib/active_support/multibyte/unicode.rb +2 -1
  92. data/lib/active_support/notifications/fanout.rb +3 -3
  93. data/lib/active_support/notifications/instrumenter.rb +1 -1
  94. data/lib/active_support/notifications.rb +9 -10
  95. data/lib/active_support/ordered_hash.rb +23 -2
  96. data/lib/active_support/ordered_options.rb +37 -3
  97. data/lib/active_support/railtie.rb +1 -1
  98. data/lib/active_support/rescuable.rb +1 -0
  99. data/lib/active_support/secure_random.rb +3 -196
  100. data/lib/active_support/test_case.rb +2 -10
  101. data/lib/active_support/testing/assertions.rb +20 -7
  102. data/lib/active_support/testing/mochaing.rb +7 -0
  103. data/lib/active_support/testing/pending.rb +27 -23
  104. data/lib/active_support/testing/performance/jruby.rb +115 -0
  105. data/lib/active_support/testing/performance/rubinius.rb +113 -0
  106. data/lib/active_support/testing/performance/ruby/mri.rb +57 -0
  107. data/lib/active_support/testing/performance/ruby/yarv.rb +57 -0
  108. data/lib/active_support/testing/performance/ruby.rb +152 -0
  109. data/lib/active_support/testing/performance.rb +214 -322
  110. data/lib/active_support/testing/setup_and_teardown.rb +8 -11
  111. data/lib/active_support/time_with_zone.rb +6 -3
  112. data/lib/active_support/values/time_zone.rb +26 -8
  113. data/lib/active_support/version.rb +2 -2
  114. data/lib/active_support/whiny_nil.rb +1 -1
  115. data/lib/active_support/xml_mini/jdom.rb +1 -1
  116. data/lib/active_support/xml_mini/libxml.rb +1 -0
  117. data/lib/active_support/xml_mini/libxmlsax.rb +2 -1
  118. data/lib/active_support/xml_mini/nokogiri.rb +1 -0
  119. data/lib/active_support/xml_mini/nokogirisax.rb +1 -0
  120. data/lib/active_support/xml_mini/rexml.rb +1 -0
  121. data/lib/active_support/xml_mini.rb +8 -3
  122. data/lib/active_support.rb +4 -2
  123. metadata +70 -32
  124. checksums.yaml +0 -7
  125. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
  126. data/lib/active_support/core_ext/cgi.rb +0 -1
  127. data/lib/active_support/core_ext/object/returning.rb +0 -43
  128. data/lib/active_support/json/backends/jsongem.rb +0 -47
  129. data/lib/active_support/json/backends/okjson.rb +0 -644
  130. data/lib/active_support/json/backends/yajl.rb +0 -44
  131. data/lib/active_support/json/backends/yaml.rb +0 -19
  132. data/lib/active_support/testing/default.rb +0 -9
@@ -0,0 +1,57 @@
1
+ module ActiveSupport
2
+ module Testing
3
+ module Performance
4
+ module Metrics
5
+ class Base
6
+ protected
7
+ # Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker)
8
+ if GC.respond_to?(:enable_stats)
9
+ def with_gc_stats
10
+ GC.enable_stats
11
+ GC.start
12
+ yield
13
+ ensure
14
+ GC.disable_stats
15
+ end
16
+ end
17
+ end
18
+
19
+ class Memory < DigitalInformationUnit
20
+ # Ruby 1.8 + ruby-prof wrapper
21
+ if RubyProf.respond_to?(:measure_memory)
22
+ def measure
23
+ RubyProf.measure_memory
24
+ end
25
+ end
26
+ end
27
+
28
+ class Objects < Amount
29
+ # Ruby 1.8 + ruby-prof wrapper
30
+ if RubyProf.respond_to?(:measure_allocations)
31
+ def measure
32
+ RubyProf.measure_allocations
33
+ end
34
+ end
35
+ end
36
+
37
+ class GcRuns < Amount
38
+ # Ruby 1.8 + ruby-prof wrapper
39
+ if RubyProf.respond_to?(:measure_gc_runs)
40
+ def measure
41
+ RubyProf.measure_gc_runs
42
+ end
43
+ end
44
+ end
45
+
46
+ class GcTime < Time
47
+ # Ruby 1.8 + ruby-prof wrapper
48
+ if RubyProf.respond_to?(:measure_gc_time)
49
+ def measure
50
+ RubyProf.measure_gc_time / 1000.0 / 1000.0
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ module ActiveSupport
2
+ module Testing
3
+ module Performance
4
+ module Metrics
5
+ class Base
6
+ protected
7
+ # Ruby 1.9 with GC::Profiler
8
+ if defined?(GC::Profiler)
9
+ def with_gc_stats
10
+ GC::Profiler.enable
11
+ GC.start
12
+ yield
13
+ ensure
14
+ GC::Profiler.disable
15
+ end
16
+ end
17
+ end
18
+
19
+ class Memory < DigitalInformationUnit
20
+ # Ruby 1.9 + GCdata patch
21
+ if GC.respond_to?(:malloc_allocated_size)
22
+ def measure
23
+ GC.malloc_allocated_size
24
+ end
25
+ end
26
+ end
27
+
28
+ class Objects < Amount
29
+ # Ruby 1.9 + GCdata patch
30
+ if GC.respond_to?(:malloc_allocations)
31
+ def measure
32
+ GC.malloc_allocations
33
+ end
34
+ end
35
+ end
36
+
37
+ class GcRuns < Amount
38
+ # Ruby 1.9
39
+ if GC.respond_to?(:count)
40
+ def measure
41
+ GC.count
42
+ end
43
+ end
44
+ end
45
+
46
+ class GcTime < Time
47
+ # Ruby 1.9 with GC::Profiler
48
+ if defined?(GC::Profiler) && GC::Profiler.respond_to?(:total_time)
49
+ def measure
50
+ GC::Profiler.total_time
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,152 @@
1
+ begin
2
+ require 'ruby-prof'
3
+ rescue LoadError
4
+ $stderr.puts 'Specify ruby-prof as application\'s dependency in Gemfile to run benchmarks.'
5
+ exit
6
+ end
7
+
8
+ module ActiveSupport
9
+ module Testing
10
+ module Performance
11
+ DEFAULTS.merge!(
12
+ if ARGV.include?('--benchmark')
13
+ { :metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time] }
14
+ else
15
+ { :min_percent => 0.01,
16
+ :metrics => [:process_time, :memory, :objects],
17
+ :formats => [:flat, :graph_html, :call_tree, :call_stack] }
18
+ end).freeze
19
+
20
+ protected
21
+ def run_gc
22
+ GC.start
23
+ end
24
+
25
+ class Profiler < Performer
26
+ def initialize(*args)
27
+ super
28
+ @supported = @metric.measure_mode rescue false
29
+ end
30
+
31
+ def run
32
+ return unless @supported
33
+
34
+ RubyProf.measure_mode = @metric.measure_mode
35
+ RubyProf.start
36
+ RubyProf.pause
37
+ full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
38
+ @data = RubyProf.stop
39
+ @total = @data.threads.values.sum(0) { |method_infos| method_infos.max.total_time }
40
+ end
41
+
42
+ def record
43
+ return unless @supported
44
+
45
+ klasses = full_profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact
46
+
47
+ klasses.each do |klass|
48
+ fname = output_filename(klass)
49
+ FileUtils.mkdir_p(File.dirname(fname))
50
+ File.open(fname, 'wb') do |file|
51
+ klass.new(@data).print(file, full_profile_options.slice(:min_percent))
52
+ end
53
+ end
54
+ end
55
+
56
+ protected
57
+ def output_filename(printer_class)
58
+ suffix =
59
+ case printer_class.name.demodulize
60
+ when 'FlatPrinter'; 'flat.txt'
61
+ when 'FlatPrinterWithLineNumbers'; 'flat_line_numbers.txt'
62
+ when 'GraphPrinter'; 'graph.txt'
63
+ when 'GraphHtmlPrinter'; 'graph.html'
64
+ when 'GraphYamlPrinter'; 'graph.yml'
65
+ when 'CallTreePrinter'; 'tree.txt'
66
+ when 'CallStackPrinter'; 'stack.html'
67
+ when 'DotPrinter'; 'graph.dot'
68
+ else printer_class.name.sub(/Printer$/, '').underscore
69
+ end
70
+
71
+ "#{super()}_#{suffix}"
72
+ end
73
+ end
74
+
75
+ module Metrics
76
+ class Base
77
+ def measure_mode
78
+ self.class::Mode
79
+ end
80
+
81
+ def profile
82
+ RubyProf.resume
83
+ yield
84
+ ensure
85
+ RubyProf.pause
86
+ end
87
+
88
+ protected
89
+ # overridden by each implementation
90
+ def with_gc_stats
91
+ yield
92
+ end
93
+ end
94
+
95
+ class ProcessTime < Time
96
+ Mode = RubyProf::PROCESS_TIME if RubyProf.const_defined?(:PROCESS_TIME)
97
+
98
+ def measure
99
+ RubyProf.measure_process_time
100
+ end
101
+ end
102
+
103
+ class WallTime < Time
104
+ Mode = RubyProf::WALL_TIME if RubyProf.const_defined?(:WALL_TIME)
105
+
106
+ def measure
107
+ RubyProf.measure_wall_time
108
+ end
109
+ end
110
+
111
+ class CpuTime < Time
112
+ Mode = RubyProf::CPU_TIME if RubyProf.const_defined?(:CPU_TIME)
113
+
114
+ def initialize(*args)
115
+ # FIXME: yeah my CPU is 2.33 GHz
116
+ RubyProf.cpu_frequency = 2.33e9 unless RubyProf.cpu_frequency > 0
117
+ super
118
+ end
119
+
120
+ def measure
121
+ RubyProf.measure_cpu_time
122
+ end
123
+ end
124
+
125
+ class Memory < DigitalInformationUnit
126
+ Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
127
+ end
128
+
129
+ class Objects < Amount
130
+ Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
131
+ end
132
+
133
+ class GcRuns < Amount
134
+ Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS)
135
+ end
136
+
137
+ class GcTime < Time
138
+ Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME)
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ if RUBY_VERSION.between?('1.9.2', '2.0')
146
+ require 'active_support/testing/performance/ruby/yarv'
147
+ elsif RUBY_VERSION.between?('1.8.6', '1.9')
148
+ require 'active_support/testing/performance/ruby/mri'
149
+ else
150
+ $stderr.puts 'Update your ruby interpreter to be able to run benchmarks.'
151
+ exit
152
+ end