activesupport 2.2.3 → 2.3.2
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 +128 -89
- data/lib/active_support.rb +31 -33
- data/lib/active_support/backtrace_cleaner.rb +72 -0
- data/lib/active_support/buffered_logger.rb +9 -7
- data/lib/active_support/cache.rb +13 -8
- data/lib/active_support/cache/drb_store.rb +2 -3
- data/lib/active_support/cache/mem_cache_store.rb +6 -1
- data/lib/active_support/cache/strategy/local_cache.rb +104 -0
- data/lib/active_support/callbacks.rb +20 -21
- data/lib/active_support/core_ext.rb +1 -1
- data/lib/active_support/core_ext/array.rb +2 -0
- data/lib/active_support/core_ext/array/conversions.rb +26 -13
- data/lib/active_support/core_ext/array/wrapper.rb +24 -0
- data/lib/active_support/core_ext/benchmark.rb +13 -6
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -5
- data/lib/active_support/core_ext/class/attribute_accessors.rb +24 -24
- data/lib/active_support/core_ext/class/delegating_attributes.rb +20 -19
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +34 -34
- data/lib/active_support/core_ext/date/conversions.rb +3 -3
- data/lib/active_support/core_ext/date_time/conversions.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +9 -0
- data/lib/active_support/core_ext/exception.rb +12 -8
- data/lib/active_support/core_ext/file/atomic.rb +2 -2
- data/lib/active_support/core_ext/hash/conversions.rb +32 -54
- data/lib/active_support/core_ext/hash/indifferent_access.rb +6 -0
- data/lib/active_support/core_ext/hash/keys.rb +1 -1
- data/lib/active_support/core_ext/hash/slice.rb +8 -1
- data/lib/active_support/core_ext/logger.rb +8 -6
- data/lib/active_support/core_ext/module/aliasing.rb +3 -3
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +4 -4
- data/lib/active_support/core_ext/module/attribute_accessors.rb +24 -24
- data/lib/active_support/core_ext/module/delegation.rb +29 -3
- data/lib/active_support/core_ext/module/synchronization.rb +5 -5
- data/lib/active_support/core_ext/object/conversions.rb +2 -1
- data/lib/active_support/core_ext/object/misc.rb +16 -0
- data/lib/active_support/core_ext/range/conversions.rb +1 -1
- data/lib/active_support/core_ext/rexml.rb +29 -24
- data/lib/active_support/core_ext/string/inflections.rb +3 -3
- data/lib/active_support/core_ext/time/calculations.rb +1 -2
- data/lib/active_support/core_ext/time/conversions.rb +1 -1
- data/lib/active_support/core_ext/try.rb +36 -0
- data/lib/active_support/dependencies.rb +18 -14
- data/lib/active_support/deprecation.rb +10 -57
- data/lib/active_support/duration.rb +3 -1
- data/lib/active_support/inflections.rb +1 -0
- data/lib/active_support/inflector.rb +16 -7
- data/lib/active_support/json/decoding.rb +21 -3
- data/lib/active_support/json/encoders/date.rb +1 -1
- data/lib/active_support/json/encoders/date_time.rb +1 -1
- data/lib/active_support/json/encoders/hash.rb +10 -11
- data/lib/active_support/json/encoders/time.rb +1 -1
- data/lib/active_support/json/encoding.rb +23 -29
- data/lib/active_support/locale/en.yml +3 -2
- data/lib/active_support/memoizable.rb +61 -43
- data/lib/active_support/message_encryptor.rb +70 -0
- data/lib/active_support/message_verifier.rb +46 -0
- data/lib/active_support/multibyte.rb +6 -30
- data/lib/active_support/multibyte/chars.rb +30 -9
- data/lib/active_support/multibyte/unicode_database.rb +4 -4
- data/lib/active_support/option_merger.rb +7 -1
- data/lib/active_support/ordered_hash.rb +75 -27
- data/lib/active_support/secure_random.rb +8 -6
- data/lib/active_support/test_case.rb +32 -17
- data/lib/active_support/testing/{core_ext/test/unit/assertions.rb → assertions.rb} +13 -20
- data/lib/active_support/testing/declarative.rb +21 -0
- data/lib/active_support/testing/deprecation.rb +55 -0
- data/lib/active_support/testing/performance.rb +1 -1
- data/lib/active_support/testing/setup_and_teardown.rb +57 -86
- data/lib/active_support/time_with_zone.rb +8 -6
- data/lib/active_support/values/time_zone.rb +1 -0
- data/lib/active_support/vendor.rb +6 -11
- data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +20 -0
- data/lib/active_support/vendor/i18n-0.1.3/README.textile +20 -0
- data/lib/active_support/vendor/i18n-0.1.3/Rakefile +5 -0
- data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +27 -0
- data/lib/active_support/vendor/{i18n-0.0.1 → i18n-0.1.3/lib}/i18n.rb +42 -37
- data/lib/active_support/vendor/{i18n-0.0.1 → i18n-0.1.3/lib}/i18n/backend/simple.rb +37 -39
- data/lib/active_support/vendor/{i18n-0.0.1 → i18n-0.1.3/lib}/i18n/exceptions.rb +3 -3
- data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +5 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +100 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +125 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +1 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +3 -0
- data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +568 -0
- data/lib/active_support/vendor/{memcache-client-1.5.1 → memcache-client-1.6.5}/memcache.rb +381 -295
- data/lib/active_support/version.rb +2 -2
- data/lib/active_support/xml_mini.rb +31 -0
- data/lib/active_support/xml_mini/libxml.rb +133 -0
- data/lib/active_support/xml_mini/nokogiri.rb +77 -0
- data/lib/active_support/xml_mini/rexml.rb +108 -0
- metadata +85 -14
- data/lib/active_support/multibyte/utils.rb +0 -61
- data/lib/active_support/testing/core_ext/test.rb +0 -6
- data/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +0 -1021
@@ -3,6 +3,7 @@ require 'active_support/core_ext/array/conversions'
|
|
3
3
|
require 'active_support/core_ext/array/extract_options'
|
4
4
|
require 'active_support/core_ext/array/grouping'
|
5
5
|
require 'active_support/core_ext/array/random_access'
|
6
|
+
require 'active_support/core_ext/array/wrapper'
|
6
7
|
|
7
8
|
class Array #:nodoc:
|
8
9
|
include ActiveSupport::CoreExtensions::Array::Access
|
@@ -10,4 +11,5 @@ class Array #:nodoc:
|
|
10
11
|
include ActiveSupport::CoreExtensions::Array::ExtractOptions
|
11
12
|
include ActiveSupport::CoreExtensions::Array::Grouping
|
12
13
|
include ActiveSupport::CoreExtensions::Array::RandomAccess
|
14
|
+
extend ActiveSupport::CoreExtensions::Array::Wrapper
|
13
15
|
end
|
@@ -1,29 +1,41 @@
|
|
1
|
-
require 'builder'
|
2
|
-
|
3
1
|
module ActiveSupport #:nodoc:
|
4
2
|
module CoreExtensions #:nodoc:
|
5
3
|
module Array #:nodoc:
|
6
4
|
module Conversions
|
7
5
|
# Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
|
8
|
-
# * <tt>:
|
9
|
-
# * <tt>:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
options.reverse_merge! :connector => default, :skip_last_comma => default_skip_last_comma
|
16
|
-
options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
|
6
|
+
# * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", ")
|
7
|
+
# * <tt>:two_words_connector</tt> - The sign or word used to join the elements in arrays with two elements (default: " and ")
|
8
|
+
# * <tt>:last_word_connector</tt> - The sign or word used to join the last element in arrays with three or more elements (default: ", and ")
|
9
|
+
def to_sentence(options = {})
|
10
|
+
default_words_connector = I18n.translate(:'support.array.words_connector', :locale => options[:locale])
|
11
|
+
default_two_words_connector = I18n.translate(:'support.array.two_words_connector', :locale => options[:locale])
|
12
|
+
default_last_word_connector = I18n.translate(:'support.array.last_word_connector', :locale => options[:locale])
|
17
13
|
|
14
|
+
# Try to emulate to_senteces previous to 2.3
|
15
|
+
if options.has_key?(:connector) || options.has_key?(:skip_last_comma)
|
16
|
+
::ActiveSupport::Deprecation.warn(":connector has been deprecated. Use :words_connector instead", caller) if options.has_key? :connector
|
17
|
+
::ActiveSupport::Deprecation.warn(":skip_last_comma has been deprecated. Use :last_word_connector instead", caller) if options.has_key? :skip_last_comma
|
18
|
+
|
19
|
+
skip_last_comma = options.delete :skip_last_comma
|
20
|
+
if connector = options.delete(:connector)
|
21
|
+
options[:last_word_connector] ||= skip_last_comma ? connector : ", #{connector}"
|
22
|
+
else
|
23
|
+
options[:last_word_connector] ||= skip_last_comma ? default_two_words_connector : default_last_word_connector
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
|
28
|
+
options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector
|
29
|
+
|
18
30
|
case length
|
19
31
|
when 0
|
20
32
|
""
|
21
33
|
when 1
|
22
34
|
self[0].to_s
|
23
35
|
when 2
|
24
|
-
"#{self[0]}
|
36
|
+
"#{self[0]}#{options[:two_words_connector]}#{self[1]}"
|
25
37
|
else
|
26
|
-
"#{self[0...-1].join(
|
38
|
+
"#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
@@ -149,6 +161,7 @@ module ActiveSupport #:nodoc:
|
|
149
161
|
#
|
150
162
|
def to_xml(options = {})
|
151
163
|
raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }
|
164
|
+
require 'builder' unless defined?(Builder)
|
152
165
|
|
153
166
|
options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
|
154
167
|
options[:children] ||= options[:root].singularize
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
module CoreExtensions #:nodoc:
|
3
|
+
module Array #:nodoc:
|
4
|
+
module Wrapper
|
5
|
+
# Wraps the object in an Array unless it's an Array. Converts the
|
6
|
+
# object to an Array using #to_ary if it implements that.
|
7
|
+
def wrap(object)
|
8
|
+
case object
|
9
|
+
when nil
|
10
|
+
[]
|
11
|
+
when self
|
12
|
+
object
|
13
|
+
else
|
14
|
+
if object.respond_to?(:to_ary)
|
15
|
+
object.to_ary
|
16
|
+
else
|
17
|
+
[object]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,12 +1,19 @@
|
|
1
1
|
require 'benchmark'
|
2
2
|
|
3
3
|
class << Benchmark
|
4
|
-
|
4
|
+
# Earlier Ruby had a slower implementation.
|
5
|
+
if RUBY_VERSION < '1.8.7'
|
6
|
+
remove_method :realtime
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def realtime
|
9
|
+
r0 = Time.now
|
10
|
+
yield
|
11
|
+
r1 = Time.now
|
12
|
+
r1.to_f - r0.to_f
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def ms
|
17
|
+
1000 * realtime { yield }
|
11
18
|
end
|
12
19
|
end
|
@@ -2,11 +2,20 @@ module ActiveSupport #:nodoc:
|
|
2
2
|
module CoreExtensions #:nodoc:
|
3
3
|
module CGI #:nodoc:
|
4
4
|
module EscapeSkippingSlashes #:nodoc:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
if RUBY_VERSION >= '1.9'
|
6
|
+
def escape_skipping_slashes(str)
|
7
|
+
str = str.join('/') if str.respond_to? :join
|
8
|
+
str.gsub(/([^ \/a-zA-Z0-9_.-])/n) do
|
9
|
+
"%#{$1.unpack('H2' * $1.bytesize).join('%').upcase}"
|
10
|
+
end.tr(' ', '+')
|
11
|
+
end
|
12
|
+
else
|
13
|
+
def escape_skipping_slashes(str)
|
14
|
+
str = str.join('/') if str.respond_to? :join
|
15
|
+
str.gsub(/([^ \/a-zA-Z0-9_.-])/n) do
|
16
|
+
"%#{$1.unpack('H2').first.upcase}"
|
17
|
+
end.tr(' ', '+')
|
18
|
+
end
|
10
19
|
end
|
11
20
|
end
|
12
21
|
end
|
@@ -11,17 +11,17 @@ class Class
|
|
11
11
|
syms.flatten.each do |sym|
|
12
12
|
next if sym.is_a?(Hash)
|
13
13
|
class_eval(<<-EOS, __FILE__, __LINE__)
|
14
|
-
unless defined? @@#{sym}
|
15
|
-
@@#{sym} = nil
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.#{sym}
|
19
|
-
@@#{sym}
|
20
|
-
end
|
21
|
-
|
22
|
-
def #{sym}
|
23
|
-
@@#{sym}
|
24
|
-
end
|
14
|
+
unless defined? @@#{sym} # unless defined? @@hair_colors
|
15
|
+
@@#{sym} = nil # @@hair_colors = nil
|
16
|
+
end # end
|
17
|
+
#
|
18
|
+
def self.#{sym} # def self.hair_colors
|
19
|
+
@@#{sym} # @@hair_colors
|
20
|
+
end # end
|
21
|
+
#
|
22
|
+
def #{sym} # def hair_colors
|
23
|
+
@@#{sym} # @@hair_colors
|
24
|
+
end # end
|
25
25
|
EOS
|
26
26
|
end
|
27
27
|
end
|
@@ -30,19 +30,19 @@ class Class
|
|
30
30
|
options = syms.extract_options!
|
31
31
|
syms.flatten.each do |sym|
|
32
32
|
class_eval(<<-EOS, __FILE__, __LINE__)
|
33
|
-
unless defined? @@#{sym}
|
34
|
-
@@#{sym} = nil
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.#{sym}=(obj)
|
38
|
-
@@#{sym} = obj
|
39
|
-
end
|
40
|
-
|
41
|
-
#{"
|
42
|
-
def #{sym}=(obj)
|
43
|
-
@@#{sym} = obj
|
44
|
-
end
|
45
|
-
" unless options[:instance_writer] == false }
|
33
|
+
unless defined? @@#{sym} # unless defined? @@hair_colors
|
34
|
+
@@#{sym} = nil # @@hair_colors = nil
|
35
|
+
end # end
|
36
|
+
#
|
37
|
+
def self.#{sym}=(obj) # def self.hair_colors=(obj)
|
38
|
+
@@#{sym} = obj # @@hair_colors = obj
|
39
|
+
end # end
|
40
|
+
#
|
41
|
+
#{" #
|
42
|
+
def #{sym}=(obj) # def hair_colors=(obj)
|
43
|
+
@@#{sym} = obj # @@hair_colors = obj
|
44
|
+
end # end
|
45
|
+
" unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false
|
46
46
|
EOS
|
47
47
|
end
|
48
48
|
end
|
@@ -9,22 +9,23 @@ class Class
|
|
9
9
|
class_name_to_stop_searching_on = self.superclass.name.blank? ? "Object" : self.superclass.name
|
10
10
|
names.each do |name|
|
11
11
|
class_eval <<-EOS
|
12
|
-
def self.#{name}
|
13
|
-
if defined?(@#{name})
|
14
|
-
@#{name}
|
15
|
-
elsif superclass < #{class_name_to_stop_searching_on} && superclass
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
12
|
+
def self.#{name} # def self.only_reader
|
13
|
+
if defined?(@#{name}) # if defined?(@only_reader)
|
14
|
+
@#{name} # @only_reader
|
15
|
+
elsif superclass < #{class_name_to_stop_searching_on} && # elsif superclass < Object &&
|
16
|
+
superclass.respond_to?(:#{name}) # superclass.respond_to?(:only_reader)
|
17
|
+
superclass.#{name} # superclass.only_reader
|
18
|
+
end # end
|
19
|
+
end # end
|
20
|
+
def #{name} # def only_reader
|
21
|
+
self.class.#{name} # self.class.only_reader
|
22
|
+
end # end
|
23
|
+
def self.#{name}? # def self.only_reader?
|
24
|
+
!!#{name} # !!only_reader
|
25
|
+
end # end
|
26
|
+
def #{name}? # def only_reader?
|
27
|
+
!!#{name} # !!only_reader
|
28
|
+
end # end
|
28
29
|
EOS
|
29
30
|
end
|
30
31
|
end
|
@@ -32,9 +33,9 @@ class Class
|
|
32
33
|
def superclass_delegating_writer(*names)
|
33
34
|
names.each do |name|
|
34
35
|
class_eval <<-EOS
|
35
|
-
def self.#{name}=(value)
|
36
|
-
@#{name} = value
|
37
|
-
end
|
36
|
+
def self.#{name}=(value) # def self.only_writer=(value)
|
37
|
+
@#{name} = value # @only_writer = value
|
38
|
+
end # end
|
38
39
|
EOS
|
39
40
|
end
|
40
41
|
end
|
@@ -11,13 +11,13 @@ class Class # :nodoc:
|
|
11
11
|
syms.each do |sym|
|
12
12
|
next if sym.is_a?(Hash)
|
13
13
|
class_eval <<-EOS
|
14
|
-
def self.#{sym}
|
15
|
-
read_inheritable_attribute(:#{sym})
|
16
|
-
end
|
17
|
-
|
18
|
-
def #{sym}
|
19
|
-
self.class.#{sym}
|
20
|
-
end
|
14
|
+
def self.#{sym} # def self.before_add_for_comments
|
15
|
+
read_inheritable_attribute(:#{sym}) # read_inheritable_attribute(:before_add_for_comments)
|
16
|
+
end # end
|
17
|
+
#
|
18
|
+
def #{sym} # def before_add_for_comments
|
19
|
+
self.class.#{sym} # self.class.before_add_for_comments
|
20
|
+
end # end
|
21
21
|
EOS
|
22
22
|
end
|
23
23
|
end
|
@@ -26,15 +26,15 @@ class Class # :nodoc:
|
|
26
26
|
options = syms.extract_options!
|
27
27
|
syms.each do |sym|
|
28
28
|
class_eval <<-EOS
|
29
|
-
def self.#{sym}=(obj)
|
30
|
-
write_inheritable_attribute(:#{sym}, obj)
|
31
|
-
end
|
32
|
-
|
33
|
-
#{"
|
34
|
-
def #{sym}=(obj)
|
35
|
-
self.class.#{sym} = obj
|
36
|
-
end
|
37
|
-
" unless options[:instance_writer] == false }
|
29
|
+
def self.#{sym}=(obj) # def self.color=(obj)
|
30
|
+
write_inheritable_attribute(:#{sym}, obj) # write_inheritable_attribute(:color, obj)
|
31
|
+
end # end
|
32
|
+
#
|
33
|
+
#{" #
|
34
|
+
def #{sym}=(obj) # def color=(obj)
|
35
|
+
self.class.#{sym} = obj # self.class.color = obj
|
36
|
+
end # end
|
37
|
+
" unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false
|
38
38
|
EOS
|
39
39
|
end
|
40
40
|
end
|
@@ -43,15 +43,15 @@ class Class # :nodoc:
|
|
43
43
|
options = syms.extract_options!
|
44
44
|
syms.each do |sym|
|
45
45
|
class_eval <<-EOS
|
46
|
-
def self.#{sym}=(obj)
|
47
|
-
write_inheritable_array(:#{sym}, obj)
|
48
|
-
end
|
49
|
-
|
50
|
-
#{"
|
51
|
-
def #{sym}=(obj)
|
52
|
-
self.class.#{sym} = obj
|
53
|
-
end
|
54
|
-
" unless options[:instance_writer] == false }
|
46
|
+
def self.#{sym}=(obj) # def self.levels=(obj)
|
47
|
+
write_inheritable_array(:#{sym}, obj) # write_inheritable_array(:levels, obj)
|
48
|
+
end # end
|
49
|
+
#
|
50
|
+
#{" #
|
51
|
+
def #{sym}=(obj) # def levels=(obj)
|
52
|
+
self.class.#{sym} = obj # self.class.levels = obj
|
53
|
+
end # end
|
54
|
+
" unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false
|
55
55
|
EOS
|
56
56
|
end
|
57
57
|
end
|
@@ -60,15 +60,15 @@ class Class # :nodoc:
|
|
60
60
|
options = syms.extract_options!
|
61
61
|
syms.each do |sym|
|
62
62
|
class_eval <<-EOS
|
63
|
-
def self.#{sym}=(obj)
|
64
|
-
write_inheritable_hash(:#{sym}, obj)
|
65
|
-
end
|
66
|
-
|
67
|
-
#{"
|
68
|
-
def #{sym}=(obj)
|
69
|
-
self.class.#{sym} = obj
|
70
|
-
end
|
71
|
-
" unless options[:instance_writer] == false }
|
63
|
+
def self.#{sym}=(obj) # def self.nicknames=(obj)
|
64
|
+
write_inheritable_hash(:#{sym}, obj) # write_inheritable_hash(:nicknames, obj)
|
65
|
+
end # end
|
66
|
+
#
|
67
|
+
#{" #
|
68
|
+
def #{sym}=(obj) # def nicknames=(obj)
|
69
|
+
self.class.#{sym} = obj # self.class.nicknames = obj
|
70
|
+
end # end
|
71
|
+
" unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false
|
72
72
|
EOS
|
73
73
|
end
|
74
74
|
end
|
@@ -31,7 +31,7 @@ module ActiveSupport #:nodoc:
|
|
31
31
|
#
|
32
32
|
# This method is aliased to <tt>to_s</tt>.
|
33
33
|
#
|
34
|
-
# ==== Examples
|
34
|
+
# ==== Examples
|
35
35
|
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
|
36
36
|
#
|
37
37
|
# date.to_formatted_s(:db) # => "2007-11-10"
|
@@ -76,7 +76,7 @@ module ActiveSupport #:nodoc:
|
|
76
76
|
# Converts a Date instance to a Time, where the time is set to the beginning of the day.
|
77
77
|
# The timezone can be either :local or :utc (default :local).
|
78
78
|
#
|
79
|
-
# ==== Examples
|
79
|
+
# ==== Examples
|
80
80
|
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
|
81
81
|
#
|
82
82
|
# date.to_time # => Sat Nov 10 00:00:00 0800 2007
|
@@ -90,7 +90,7 @@ module ActiveSupport #:nodoc:
|
|
90
90
|
# Converts a Date instance to a DateTime, where the time is set to the beginning of the day
|
91
91
|
# and UTC offset is set to 0.
|
92
92
|
#
|
93
|
-
# ====
|
93
|
+
# ==== Examples
|
94
94
|
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
|
95
95
|
#
|
96
96
|
# date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000
|
@@ -25,7 +25,7 @@ module ActiveSupport #:nodoc:
|
|
25
25
|
#
|
26
26
|
# This method is aliased to <tt>to_s</tt>.
|
27
27
|
#
|
28
|
-
# === Examples
|
28
|
+
# === Examples
|
29
29
|
# datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
|
30
30
|
#
|
31
31
|
# datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
|
@@ -104,4 +104,13 @@ module Enumerable
|
|
104
104
|
size = block_given? ? select(&block).size : self.size
|
105
105
|
size > 1
|
106
106
|
end
|
107
|
+
|
108
|
+
# Returns true if none of the elements match the given block.
|
109
|
+
#
|
110
|
+
# success = responses.none? {|r| r.status / 100 == 5 }
|
111
|
+
#
|
112
|
+
# This is a builtin method in Ruby 1.8.7 and later.
|
113
|
+
def none?(&block)
|
114
|
+
!any?(&block)
|
115
|
+
end unless [].respond_to?(:none?)
|
107
116
|
end
|
@@ -6,14 +6,16 @@ module ActiveSupport
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
# TODO: Turn all this into using the BacktraceCleaner.
|
9
10
|
class Exception # :nodoc:
|
10
11
|
def clean_message
|
11
12
|
Pathname.clean_within message
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
TraceSubstitutions = []
|
15
|
-
|
16
|
-
|
16
|
+
FrameworkStart = /action_controller\/dispatcher\.rb/.freeze
|
17
|
+
FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/.freeze
|
18
|
+
|
17
19
|
def clean_backtrace
|
18
20
|
backtrace.collect do |line|
|
19
21
|
Pathname.clean_within(TraceSubstitutions.inject(line) do |result, (regexp, sub)|
|
@@ -21,20 +23,22 @@ class Exception # :nodoc:
|
|
21
23
|
end)
|
22
24
|
end
|
23
25
|
end
|
24
|
-
|
26
|
+
|
25
27
|
def application_backtrace
|
28
|
+
before_framework_frame = nil
|
26
29
|
before_application_frame = true
|
27
|
-
|
30
|
+
|
28
31
|
trace = clean_backtrace.reject do |line|
|
32
|
+
before_framework_frame ||= (line =~ FrameworkStart)
|
29
33
|
non_app_frame = (line =~ FrameworkRegexp)
|
30
34
|
before_application_frame = false unless non_app_frame
|
31
|
-
non_app_frame && !
|
35
|
+
before_framework_frame || (non_app_frame && !before_application_frame)
|
32
36
|
end
|
33
|
-
|
37
|
+
|
34
38
|
# If we didn't find any application frames, return an empty app trace.
|
35
39
|
before_application_frame ? [] : trace
|
36
40
|
end
|
37
|
-
|
41
|
+
|
38
42
|
def framework_backtrace
|
39
43
|
clean_backtrace.grep FrameworkRegexp
|
40
44
|
end
|