activesupport 2.0.1 → 2.0.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 +22 -11
- data/lib/active_support/core_ext/array/conversions.rb +12 -3
- data/lib/active_support/core_ext/date/conversions.rb +3 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +25 -5
- data/lib/active_support/core_ext/hash/conversions.rb +7 -17
- data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -0
- data/lib/active_support/core_ext/hash/keys.rb +1 -7
- data/lib/active_support/core_ext/integer/even_odd.rb +4 -4
- data/lib/active_support/core_ext/object.rb +1 -0
- data/lib/active_support/core_ext/object/conversions.rb +14 -0
- data/lib/active_support/core_ext/range/conversions.rb +3 -3
- data/lib/active_support/core_ext/string.rb +6 -1
- data/lib/active_support/core_ext/string/conversions.rb +7 -2
- data/lib/active_support/core_ext/string/starts_ends_with.rb +7 -0
- data/lib/active_support/dependencies.rb +7 -7
- data/lib/active_support/duration.rb +36 -26
- data/lib/active_support/multibyte/chars.rb +8 -2
- data/lib/active_support/values/time_zone.rb +5 -4
- data/lib/active_support/version.rb +1 -1
- metadata +41 -33
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
*SVN*
|
2
|
+
|
3
|
+
* Ruby 1.9 compatibility. #1689, #10466, #10468 [Cheah Chu Yeow, Pratik Naik, Jeremy Kemper]
|
4
|
+
|
5
|
+
* TimeZone#to_s uses UTC rather than GMT. #1689 [Cheah Chu Yeow]
|
6
|
+
|
7
|
+
* Refactor of Hash#symbolize_keys! to use Hash#replace. Closes #10420 [ReinH]
|
8
|
+
|
9
|
+
* Fix HashWithIndifferentAccess#to_options! so it doesn't clear the options hash. Closes #10419 [ReinH]
|
10
|
+
|
11
|
+
|
1
12
|
*2.0.1* (December 7th, 2007)
|
2
13
|
|
3
14
|
* Added Array#from and Array#to that behaves just from String#from and String#to [DHH]
|
@@ -10,11 +21,11 @@
|
|
10
21
|
|
11
22
|
* Speedup String#blank? [Jeremy Kemper, Koz]
|
12
23
|
|
13
|
-
* Add documentation for Hash#diff. Closes #9306 [
|
24
|
+
* Add documentation for Hash#diff. Closes #9306 [Tarmo Tänav]
|
14
25
|
|
15
|
-
* Add new superclass_delegating_accessors. Similar to class inheritable attributes but with subtly different semantics. [Koz,
|
26
|
+
* Add new superclass_delegating_accessors. Similar to class inheritable attributes but with subtly different semantics. [Koz, Tarmo Tänav]
|
16
27
|
|
17
|
-
* Change JSON to encode %w(< > &) as 4 digit hex codes to be in compliance with the JSON spec. Closes #9975 [
|
28
|
+
* Change JSON to encode %w(< > &) as 4 digit hex codes to be in compliance with the JSON spec. Closes #9975 [Josh Peek, Cheah Chu Yeow, Tim Pope]
|
18
29
|
|
19
30
|
* Fix JSON encoding/decoding bugs dealing with /'s. Closes #9990 [Rick, theamazingrando]
|
20
31
|
|
@@ -23,7 +34,7 @@
|
|
23
34
|
The intention is to use this to reduce the amount of monkeypatching / overriding that
|
24
35
|
is done to test/unit's classes.
|
25
36
|
|
26
|
-
* Document Enumerable and Hash #to_json. #9970 [Chu Yeow]
|
37
|
+
* Document Enumerable and Hash #to_json. #9970 [Cheah Chu Yeow]
|
27
38
|
|
28
39
|
* Hash#to_xml handles symbol values. #9954 [Assaf]
|
29
40
|
|
@@ -55,9 +66,9 @@
|
|
55
66
|
|
56
67
|
* Unbundle Builder in favor of a gem dependency. [Jeremy Kemper]
|
57
68
|
|
58
|
-
* Disambiguate Time, Date, and DateTime#to_json formatting. #9750 [Geoff Buesing, Chu Yeow]
|
69
|
+
* Disambiguate Time, Date, and DateTime#to_json formatting. #9750 [Geoff Buesing, Cheah Chu Yeow]
|
59
70
|
|
60
|
-
* Hash#to_json takes :only or :except options to specific or omit certain hash keys. Enumerable#to_json passes through its options to each element. #9751 [Chu Yeow]
|
71
|
+
* Hash#to_json takes :only or :except options to specific or omit certain hash keys. Enumerable#to_json passes through its options to each element. #9751 [Cheah Chu Yeow]
|
61
72
|
|
62
73
|
* BufferedLogger#auto_flushing = N flushes the log every N messages. Buffers with an array instead of string. Disabling auto_flushing still flushes when the buffer hits a maximum size, as a failsafe against memory-gobbling. [Jeremy Kemper]
|
63
74
|
|
@@ -65,7 +76,7 @@
|
|
65
76
|
|
66
77
|
* Fixed that La Paz was included in -25200 and -14400 offsets when it should only be in -14400 #9735 [bermi]
|
67
78
|
|
68
|
-
* Fixed JSON encoding to use quoted keys according to the JSON standard
|
79
|
+
* Fixed JSON encoding to use quoted keys according to the JSON standard. #8762 [choonkat, Cheah Chu Yeow]
|
69
80
|
|
70
81
|
* Alias Object#send to send! for Ruby 1.9 forward compatibility. [Jeremy Kemper]
|
71
82
|
|
@@ -79,11 +90,11 @@
|
|
79
90
|
|
80
91
|
* Decode json strings as Dates/Times if they're using a YAML-compatible format. Closes #9614 [Rick]
|
81
92
|
|
82
|
-
* Fixed cache_page to use the request url instead of the routing options when picking a save path
|
93
|
+
* Fixed cache_page to use the request url instead of the routing options when picking a save path. #8614 [Josh Peek]
|
83
94
|
|
84
95
|
* Object.subclasses_of includes anonymous subclasses. [Jeremy Kemper]
|
85
96
|
|
86
|
-
* Fixed that pluralizing an empty string should return the same empty string, not "s"
|
97
|
+
* Fixed that pluralizing an empty string should return the same empty string, not "s". #7720 [Josh Peek]
|
87
98
|
|
88
99
|
* Added call to inspect on non-string classes for the logger #8533 [codahale]
|
89
100
|
|
@@ -93,7 +104,7 @@
|
|
93
104
|
|
94
105
|
* Hash#to_xml doesn't double-unescape. #8806 [Ezran]
|
95
106
|
|
96
|
-
* Added Array#rand #9170 [
|
107
|
+
* Added Array#rand #9170 [Norbert Crombach]. Examples:
|
97
108
|
|
98
109
|
[].rand # => nil
|
99
110
|
['a'].rand # => 'a'
|
@@ -109,7 +120,7 @@
|
|
109
120
|
|
110
121
|
* Add support for []= on ActiveSupport::Multibyte::Chars. Closes #9142. [ewan, manfred]
|
111
122
|
|
112
|
-
* Added Array#extract_options! to encapsulate the pattern of getting an options hash out of a variable number of parameters
|
123
|
+
* Added Array#extract_options! to encapsulate the pattern of getting an options hash out of a variable number of parameters. #8759 [Norbert Crombach]
|
113
124
|
|
114
125
|
* Let alias_attribute work with attributes with initial capital letters (legacy columns etc). Closes #8596 [mpalmer]
|
115
126
|
|
@@ -16,7 +16,7 @@ module ActiveSupport #:nodoc:
|
|
16
16
|
when 0
|
17
17
|
""
|
18
18
|
when 1
|
19
|
-
self[0]
|
19
|
+
self[0].to_s
|
20
20
|
when 2
|
21
21
|
"#{self[0]} #{options[:connector]}#{self[1]}"
|
22
22
|
else
|
@@ -24,9 +24,18 @@ module ActiveSupport #:nodoc:
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
27
|
+
# Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.
|
28
28
|
def to_param
|
29
|
-
join '/'
|
29
|
+
map(&:to_param).join '/'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
|
33
|
+
# param name.
|
34
|
+
#
|
35
|
+
# ==== Example:
|
36
|
+
# ['Rails', 'coding'].to_query('hobbies') => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
|
37
|
+
def to_query(key)
|
38
|
+
collect { |value| value.to_query("#{key}[]") } * '&'
|
30
39
|
end
|
31
40
|
|
32
41
|
def self.included(base) #:nodoc:
|
@@ -20,6 +20,9 @@ module ActiveSupport #:nodoc:
|
|
20
20
|
|
21
21
|
# Ruby 1.9 has Date#to_time which converts to localtime only.
|
22
22
|
remove_method :to_time if base.instance_methods.include?(:to_time)
|
23
|
+
|
24
|
+
# Ruby 1.9 has Date#xmlschema which converts to a string without the time component.
|
25
|
+
remove_method :xmlschema if base.instance_methods.include?(:xmlschema)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -9,9 +9,28 @@ module ActiveSupport #:nodoc:
|
|
9
9
|
alias_method :to_s, :to_formatted_s
|
10
10
|
alias_method :default_inspect, :inspect
|
11
11
|
alias_method :inspect, :readable_inspect
|
12
|
+
|
13
|
+
# Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
|
14
|
+
# DateTimes outside the range of what can be created with Time.
|
15
|
+
remove_method :to_time if base.instance_methods.include?(:to_time)
|
12
16
|
end
|
13
17
|
end
|
14
|
-
|
18
|
+
|
19
|
+
# Convert to a formatted string - see DATE_FORMATS for predefined formats.
|
20
|
+
# You can also add your own formats to the DATE_FORMATS constant and use them with this method.
|
21
|
+
#
|
22
|
+
# This method is also aliased as <tt>to_s</tt>.
|
23
|
+
#
|
24
|
+
# === Examples:
|
25
|
+
# datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
|
26
|
+
#
|
27
|
+
# datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
|
28
|
+
# datetime.to_s(:db) # => "2007-12-04 00:00:00"
|
29
|
+
# datetime.to_s(:number) # => "20071204000000"
|
30
|
+
# datetime.to_formatted_s(:short) # => "04 Dec 00:00"
|
31
|
+
# datetime.to_formatted_s(:long) # => "December 04, 2007 00:00"
|
32
|
+
# datetime.to_formatted_s(:long_ordinal) # => "December 4th, 2007 00:00"
|
33
|
+
# datetime.to_formatted_s(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"
|
15
34
|
def to_formatted_s(format = :default)
|
16
35
|
if formatter = ::Time::DATE_FORMATS[format]
|
17
36
|
if formatter.respond_to?(:call)
|
@@ -38,16 +57,17 @@ module ActiveSupport #:nodoc:
|
|
38
57
|
# If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
|
39
58
|
def to_time
|
40
59
|
self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self
|
41
|
-
end
|
60
|
+
end
|
42
61
|
|
43
62
|
# To be able to keep Times, Dates and DateTimes interchangeable on conversions
|
44
63
|
def to_datetime
|
45
64
|
self
|
46
65
|
end
|
47
|
-
|
66
|
+
|
67
|
+
# Converts datetime to an appropriate format for use in XML
|
48
68
|
def xmlschema
|
49
|
-
strftime("%Y-%m-%dT%H:%M:%S
|
50
|
-
end
|
69
|
+
strftime("%Y-%m-%dT%H:%M:%S%Z")
|
70
|
+
end if RUBY_VERSION < '1.9'
|
51
71
|
end
|
52
72
|
end
|
53
73
|
end
|
@@ -4,23 +4,6 @@ require 'base64'
|
|
4
4
|
require 'builder'
|
5
5
|
require 'xmlsimple'
|
6
6
|
|
7
|
-
# Extensions needed for Hash#to_query
|
8
|
-
class Object
|
9
|
-
def to_param #:nodoc:
|
10
|
-
to_s
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_query(key) #:nodoc:
|
14
|
-
"#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Array
|
19
|
-
def to_query(key) #:nodoc:
|
20
|
-
collect { |value| value.to_query("#{key}[]") } * '&'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
7
|
# Locked down XmlSimple#xml_in_string
|
25
8
|
class XmlSimple
|
26
9
|
# Same as xml_in but doesn't try to smartly shoot itself in the foot.
|
@@ -100,6 +83,13 @@ module ActiveSupport #:nodoc:
|
|
100
83
|
klass.extend(ClassMethods)
|
101
84
|
end
|
102
85
|
|
86
|
+
# Converts a hash into a string suitable for use as a URL query string. An optional <tt>namespace</tt> can be
|
87
|
+
# passed to enclose the param names (see example below).
|
88
|
+
#
|
89
|
+
# ==== Example:
|
90
|
+
# { :name => 'David', :nationality => 'Danish' }.to_query # => "name=David&nationality=Danish"
|
91
|
+
#
|
92
|
+
# { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
|
103
93
|
def to_query(namespace = nil)
|
104
94
|
collect do |key, value|
|
105
95
|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
@@ -31,13 +31,7 @@ module ActiveSupport #:nodoc:
|
|
31
31
|
|
32
32
|
# Destructively convert all keys to symbols.
|
33
33
|
def symbolize_keys!
|
34
|
-
|
35
|
-
unless key.is_a?(Symbol) || (new_key = key.to_sym).nil?
|
36
|
-
self[new_key] = self[key]
|
37
|
-
delete(key)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
self
|
34
|
+
self.replace(self.symbolize_keys)
|
41
35
|
end
|
42
36
|
|
43
37
|
alias_method :to_options, :symbolize_keys
|
@@ -10,14 +10,14 @@ module ActiveSupport #:nodoc:
|
|
10
10
|
def multiple_of?(number)
|
11
11
|
self % number == 0
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def even?
|
15
15
|
multiple_of? 2
|
16
|
-
end
|
17
|
-
|
16
|
+
end if RUBY_VERSION < '1.9'
|
17
|
+
|
18
18
|
def odd?
|
19
19
|
!even?
|
20
|
-
end
|
20
|
+
end if RUBY_VERSION < '1.9'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Object
|
2
|
+
# Alias of <tt>to_s</tt>.
|
3
|
+
def to_param
|
4
|
+
to_s
|
5
|
+
end
|
6
|
+
|
7
|
+
# Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
|
8
|
+
# param name.
|
9
|
+
#
|
10
|
+
# Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
|
11
|
+
def to_query(key)
|
12
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
|
13
|
+
end
|
14
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ActiveSupport #:nodoc:
|
2
2
|
module CoreExtensions #:nodoc:
|
3
3
|
module Range #:nodoc:
|
4
|
-
# Getting
|
4
|
+
# Getting ranges in different convenient string representations and other objects
|
5
5
|
module Conversions
|
6
|
-
|
6
|
+
RANGE_FORMATS = {
|
7
7
|
:db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
|
8
8
|
}
|
9
9
|
|
@@ -15,7 +15,7 @@ module ActiveSupport #:nodoc:
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_formatted_s(format = :default)
|
18
|
-
|
18
|
+
RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -10,7 +10,12 @@ class String #:nodoc:
|
|
10
10
|
include ActiveSupport::CoreExtensions::String::Access
|
11
11
|
include ActiveSupport::CoreExtensions::String::Conversions
|
12
12
|
include ActiveSupport::CoreExtensions::String::Inflections
|
13
|
-
|
13
|
+
if RUBY_VERSION < '1.9'
|
14
|
+
include ActiveSupport::CoreExtensions::String::StartsEndsWith
|
15
|
+
else
|
16
|
+
alias starts_with? start_with?
|
17
|
+
alias ends_with? end_with?
|
18
|
+
end
|
14
19
|
if defined? ActiveSupport::CoreExtensions::String::Iterators
|
15
20
|
include ActiveSupport::CoreExtensions::String::Iterators
|
16
21
|
end
|
@@ -5,6 +5,11 @@ module ActiveSupport #:nodoc:
|
|
5
5
|
module String #:nodoc:
|
6
6
|
# Converting strings to other objects
|
7
7
|
module Conversions
|
8
|
+
# 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
|
9
|
+
def ord
|
10
|
+
self[0]
|
11
|
+
end if RUBY_VERSION < '1.9'
|
12
|
+
|
8
13
|
# Form can be either :utc (default) or :local.
|
9
14
|
def to_time(form = :utc)
|
10
15
|
::Time.send("#{form}_time", *ParseDate.parsedate(self)[0..5].map {|arg| arg || 0})
|
@@ -13,11 +18,11 @@ module ActiveSupport #:nodoc:
|
|
13
18
|
def to_date
|
14
19
|
::Date.new(*ParseDate.parsedate(self)[0..2])
|
15
20
|
end
|
16
|
-
|
21
|
+
|
17
22
|
def to_datetime
|
18
23
|
::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0)
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
23
|
-
end
|
28
|
+
end
|
@@ -3,6 +3,13 @@ module ActiveSupport #:nodoc:
|
|
3
3
|
module String #:nodoc:
|
4
4
|
# Additional string tests.
|
5
5
|
module StartsEndsWith
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
alias_method :start_with?, :starts_with?
|
9
|
+
alias_method :end_with?, :ends_with?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
# Does the string start with the specified +prefix+?
|
7
14
|
def starts_with?(prefix)
|
8
15
|
prefix = prefix.to_s
|
@@ -216,7 +216,7 @@ module Dependencies #:nodoc:
|
|
216
216
|
end
|
217
217
|
|
218
218
|
# Load the constant named +const_name+ which is missing from +from_mod+. If
|
219
|
-
# it is not possible to
|
219
|
+
# it is not possible to load the constant into from_mod, try its parent module
|
220
220
|
# using const_missing.
|
221
221
|
def load_missing_constant(from_mod, const_name)
|
222
222
|
log_call from_mod, const_name
|
@@ -236,7 +236,7 @@ module Dependencies #:nodoc:
|
|
236
236
|
unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id
|
237
237
|
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
|
238
238
|
end
|
239
|
-
|
239
|
+
|
240
240
|
raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name)
|
241
241
|
|
242
242
|
qualified_name = qualified_name_for from_mod, const_name
|
@@ -460,21 +460,21 @@ class Module #:nodoc:
|
|
460
460
|
end
|
461
461
|
|
462
462
|
class Class
|
463
|
-
def const_missing(
|
463
|
+
def const_missing(const_name)
|
464
464
|
if [Object, Kernel].include?(self) || parent == self
|
465
465
|
super
|
466
466
|
else
|
467
467
|
begin
|
468
468
|
begin
|
469
|
-
Dependencies.load_missing_constant self,
|
469
|
+
Dependencies.load_missing_constant self, const_name
|
470
470
|
rescue NameError
|
471
|
-
parent.send :const_missing,
|
471
|
+
parent.send :const_missing, const_name
|
472
472
|
end
|
473
473
|
rescue NameError => e
|
474
474
|
# Make sure that the name we are missing is the one that caused the error
|
475
|
-
parent_qualified_name = Dependencies.qualified_name_for parent,
|
475
|
+
parent_qualified_name = Dependencies.qualified_name_for parent, const_name
|
476
476
|
raise unless e.missing_name? parent_qualified_name
|
477
|
-
qualified_name = Dependencies.qualified_name_for self,
|
477
|
+
qualified_name = Dependencies.qualified_name_for self, const_name
|
478
478
|
raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e)
|
479
479
|
end
|
480
480
|
end
|
@@ -6,11 +6,11 @@ module ActiveSupport
|
|
6
6
|
# 1.month.ago # equivalent to Time.now.advance(:months => -1)
|
7
7
|
class Duration < BasicObject
|
8
8
|
attr_accessor :value, :parts
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(value, parts) #:nodoc:
|
11
11
|
@value, @parts = value, parts
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# Adds another Duration or a Numeric to this Duration. Numeric values
|
15
15
|
# are treated as seconds.
|
16
16
|
def +(other)
|
@@ -20,67 +20,77 @@ module ActiveSupport
|
|
20
20
|
Duration.new(value + other, @parts + [[:seconds, other]])
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Subtracts another Duration or a Numeric from this Duration. Numeric
|
25
25
|
# values are treated as seconds.
|
26
26
|
def -(other)
|
27
27
|
self + (-other)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def -@ #:nodoc:
|
31
31
|
Duration.new(-value, parts.map { |type,number| [type, -number] })
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def is_a?(klass) #:nodoc:
|
35
35
|
klass == Duration || super
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
|
+
# Returns true if <tt>other</tt> is also a Duration instance with the
|
39
|
+
# same <tt>value</tt>, or if <tt>other == value</tt>.
|
40
|
+
def ==(other)
|
41
|
+
if Duration === other
|
42
|
+
other.value == value
|
43
|
+
else
|
44
|
+
other == value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
38
48
|
def self.===(other) #:nodoc:
|
39
49
|
other.is_a?(Duration) rescue super
|
40
50
|
end
|
41
|
-
|
51
|
+
|
42
52
|
# Calculates a new Time or Date that is as far in the future
|
43
53
|
# as this Duration represents.
|
44
54
|
def since(time = ::Time.now)
|
45
55
|
sum(1, time)
|
46
56
|
end
|
47
57
|
alias :from_now :since
|
48
|
-
|
58
|
+
|
49
59
|
# Calculates a new Time or Date that is as far in the past
|
50
60
|
# as this Duration represents.
|
51
61
|
def ago(time = ::Time.now)
|
52
62
|
sum(-1, time)
|
53
63
|
end
|
54
64
|
alias :until :ago
|
55
|
-
|
65
|
+
|
56
66
|
def inspect #:nodoc:
|
57
|
-
consolidated = parts.inject(Hash.new(0)) { |h,part| h[part.first] += part.last; h }
|
67
|
+
consolidated = parts.inject(::Hash.new(0)) { |h,part| h[part.first] += part.last; h }
|
58
68
|
[:years, :months, :days, :minutes, :seconds].map do |length|
|
59
69
|
n = consolidated[length]
|
60
70
|
"#{n} #{n == 1 ? length.to_s.singularize : length.to_s}" if n.nonzero?
|
61
71
|
end.compact.to_sentence
|
62
72
|
end
|
63
|
-
|
73
|
+
|
64
74
|
protected
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
75
|
+
|
76
|
+
def sum(sign, time = ::Time.now) #:nodoc:
|
77
|
+
parts.inject(time) do |t,(type,number)|
|
78
|
+
if t.acts_like?(:time) || t.acts_like?(:date)
|
79
|
+
if type == :seconds
|
80
|
+
t.since(sign * number)
|
81
|
+
else
|
82
|
+
t.advance(type => sign * number)
|
83
|
+
end
|
71
84
|
else
|
72
|
-
|
85
|
+
raise ArgumentError, "expected a time or date, got #{time.inspect}"
|
73
86
|
end
|
74
|
-
else
|
75
|
-
raise ArgumentError, "expected a time or date, got #{time.inspect}"
|
76
87
|
end
|
77
88
|
end
|
78
|
-
|
79
|
-
|
89
|
+
|
80
90
|
private
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
91
|
+
|
92
|
+
def method_missing(method, *args, &block) #:nodoc:
|
93
|
+
value.send(method, *args)
|
94
|
+
end
|
85
95
|
end
|
86
96
|
end
|
@@ -119,8 +119,14 @@ module ActiveSupport::Multibyte #:nodoc:
|
|
119
119
|
|
120
120
|
# +utf8_pragma+ checks if it can send this string to the handlers. It makes sure @string isn't nil and $KCODE is
|
121
121
|
# set to 'UTF8'.
|
122
|
-
|
123
|
-
|
122
|
+
if RUBY_VERSION < '1.9'
|
123
|
+
def utf8_pragma?
|
124
|
+
!@string.nil? && ($KCODE == 'UTF8')
|
125
|
+
end
|
126
|
+
else
|
127
|
+
def utf8_pragma?
|
128
|
+
!@string.nil? && (Encoding.default_external == Encoding::UTF_8)
|
129
|
+
end
|
124
130
|
end
|
125
131
|
end
|
126
132
|
end
|
@@ -45,7 +45,7 @@ class TimeZone
|
|
45
45
|
|
46
46
|
# Adjust the given time to the time zone represented by +self+.
|
47
47
|
def adjust(time)
|
48
|
-
time = time.to_time
|
48
|
+
time = time.to_time unless time.is_a?(::Time)
|
49
49
|
time + utc_offset - time.utc_offset
|
50
50
|
end
|
51
51
|
|
@@ -53,8 +53,9 @@ class TimeZone
|
|
53
53
|
# zone, and then adjusts it to return the corresponding time in the
|
54
54
|
# local time zone.
|
55
55
|
def unadjust(time)
|
56
|
-
time =
|
57
|
-
time
|
56
|
+
time = time.to_time unless time.is_a?(::Time)
|
57
|
+
time = time.localtime
|
58
|
+
time - utc_offset - time.utc_offset
|
58
59
|
end
|
59
60
|
|
60
61
|
# Compare this time zone to the parameter. The two are comapred first on
|
@@ -67,7 +68,7 @@ class TimeZone
|
|
67
68
|
|
68
69
|
# Returns a textual representation of this time zone.
|
69
70
|
def to_s
|
70
|
-
"(
|
71
|
+
"(UTC#{formatted_offset}) #{name}"
|
71
72
|
end
|
72
73
|
|
73
74
|
@@zones = nil
|
metadata
CHANGED
@@ -1,33 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: activesupport
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.0.
|
7
|
-
date: 2007-12-07 00:00:00 -06:00
|
8
|
-
summary: Support and utility classes used by the Rails framework.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: david@loudthinking.com
|
12
|
-
homepage: http://www.rubyonrails.org
|
13
|
-
rubyforge_project: activesupport
|
14
|
-
description: Utility library which carries commonly used classes and goodies from the Rails framework
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 2.0.2
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- David Heinemeier Hansson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2007-12-20 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Utility library which carries commonly used classes and goodies from the Rails framework
|
17
|
+
email: david@loudthinking.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
31
24
|
files:
|
32
25
|
- CHANGELOG
|
33
26
|
- README
|
@@ -110,6 +103,7 @@ files:
|
|
110
103
|
- lib/active_support/core_ext/numeric/time.rb
|
111
104
|
- lib/active_support/core_ext/numeric.rb
|
112
105
|
- lib/active_support/core_ext/object
|
106
|
+
- lib/active_support/core_ext/object/conversions.rb
|
113
107
|
- lib/active_support/core_ext/object/extending.rb
|
114
108
|
- lib/active_support/core_ext/object/instance_variables.rb
|
115
109
|
- lib/active_support/core_ext/object/misc.rb
|
@@ -204,17 +198,31 @@ files:
|
|
204
198
|
- lib/active_support/whiny_nil.rb
|
205
199
|
- lib/active_support.rb
|
206
200
|
- lib/activesupport.rb
|
207
|
-
|
208
|
-
|
201
|
+
has_rdoc: true
|
202
|
+
homepage: http://www.rubyonrails.org
|
203
|
+
post_install_message:
|
209
204
|
rdoc_options: []
|
210
205
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
206
|
+
require_paths:
|
207
|
+
- lib
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: "0"
|
213
|
+
version:
|
214
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
|
+
requirements:
|
216
|
+
- - ">="
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: "0"
|
219
|
+
version:
|
217
220
|
requirements: []
|
218
221
|
|
219
|
-
|
222
|
+
rubyforge_project: activesupport
|
223
|
+
rubygems_version: 1.0.0
|
224
|
+
signing_key:
|
225
|
+
specification_version: 2
|
226
|
+
summary: Support and utility classes used by the Rails framework.
|
227
|
+
test_files: []
|
220
228
|
|