activesupport 1.4.4 → 2.0.0
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 +263 -7
- data/lib/active_support.rb +9 -4
- data/lib/active_support/basic_object.rb +5 -0
- data/lib/active_support/buffered_logger.rb +107 -0
- data/lib/active_support/clean_logger.rb +94 -5
- data/lib/active_support/core_ext.rb +4 -1
- data/lib/active_support/core_ext/array.rb +8 -2
- data/lib/active_support/core_ext/array/access.rb +28 -0
- data/lib/active_support/core_ext/array/conversions.rb +28 -15
- data/lib/active_support/core_ext/array/extract_options.rb +19 -0
- data/lib/active_support/core_ext/array/grouping.rb +20 -7
- data/lib/active_support/core_ext/array/random_access.rb +12 -0
- data/lib/active_support/core_ext/bigdecimal.rb +1 -2
- data/lib/active_support/core_ext/bigdecimal/{formatting.rb → conversions.rb} +1 -2
- data/lib/active_support/core_ext/blank.rb +2 -8
- data/lib/active_support/core_ext/cgi.rb +2 -2
- data/lib/active_support/core_ext/class.rb +4 -3
- data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
- data/lib/active_support/core_ext/class/delegating_attributes.rb +40 -0
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +3 -3
- data/lib/active_support/core_ext/class/removal.rb +2 -2
- data/lib/active_support/core_ext/date.rb +5 -1
- data/lib/active_support/core_ext/date/behavior.rb +13 -0
- data/lib/active_support/core_ext/date/calculations.rb +188 -0
- data/lib/active_support/core_ext/date/conversions.rb +69 -13
- data/lib/active_support/core_ext/date_time.rb +10 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +77 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +54 -0
- data/lib/active_support/core_ext/duplicable.rb +37 -0
- data/lib/active_support/core_ext/enumerable.rb +1 -0
- data/lib/active_support/core_ext/exception.rb +2 -2
- data/lib/active_support/core_ext/file.rb +21 -0
- data/lib/active_support/core_ext/float.rb +5 -0
- data/lib/active_support/core_ext/float/rounding.rb +24 -0
- data/lib/active_support/core_ext/hash.rb +5 -5
- data/lib/active_support/core_ext/hash/conversions.rb +86 -34
- data/lib/active_support/core_ext/hash/diff.rb +8 -0
- data/lib/active_support/core_ext/hash/except.rb +24 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +15 -2
- data/lib/active_support/core_ext/hash/keys.rb +10 -3
- data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -2
- data/lib/active_support/core_ext/hash/slice.rb +28 -0
- data/lib/active_support/core_ext/integer.rb +2 -2
- data/lib/active_support/core_ext/kernel.rb +5 -4
- data/lib/active_support/core_ext/kernel/debugger.rb +13 -0
- data/lib/active_support/core_ext/module.rb +8 -7
- data/lib/active_support/core_ext/module/aliasing.rb +17 -5
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +1 -1
- data/lib/active_support/core_ext/module/delegation.rb +21 -0
- data/lib/active_support/core_ext/name_error.rb +2 -2
- data/lib/active_support/core_ext/numeric.rb +2 -2
- data/lib/active_support/core_ext/numeric/time.rb +30 -11
- data/lib/active_support/core_ext/object.rb +3 -2
- data/lib/active_support/core_ext/object/extending.rb +40 -29
- data/lib/active_support/core_ext/object/instance_variables.rb +22 -0
- data/lib/active_support/core_ext/object/misc.rb +29 -4
- data/lib/active_support/core_ext/pathname.rb +1 -1
- data/lib/active_support/core_ext/range.rb +7 -1
- data/lib/active_support/core_ext/range/blockless_step.rb +22 -0
- data/lib/active_support/core_ext/range/conversions.rb +8 -6
- data/lib/active_support/core_ext/range/include_range.rb +22 -0
- data/lib/active_support/core_ext/range/overlaps.rb +12 -0
- data/lib/active_support/core_ext/string.rb +10 -7
- data/lib/active_support/core_ext/string/conversions.rb +5 -1
- data/lib/active_support/core_ext/string/unicode.rb +2 -2
- data/lib/active_support/core_ext/string/xchar.rb +11 -0
- data/lib/active_support/core_ext/symbol.rb +12 -10
- data/lib/active_support/core_ext/test.rb +1 -0
- data/lib/active_support/core_ext/test/unit/assertions.rb +62 -0
- data/lib/active_support/core_ext/time.rb +4 -2
- data/lib/active_support/core_ext/time/behavior.rb +13 -0
- data/lib/active_support/core_ext/time/calculations.rb +87 -54
- data/lib/active_support/core_ext/time/conversions.rb +71 -10
- data/lib/active_support/dependencies.rb +25 -24
- data/lib/active_support/deprecation.rb +4 -2
- data/lib/active_support/duration.rb +86 -0
- data/lib/active_support/inflections.rb +2 -1
- data/lib/active_support/inflector.rb +13 -6
- data/lib/active_support/json.rb +22 -39
- data/lib/active_support/json/decoding.rb +60 -0
- data/lib/active_support/json/encoders/date.rb +5 -0
- data/lib/active_support/json/encoders/date_time.rb +5 -0
- data/lib/active_support/json/encoders/enumerable.rb +12 -0
- data/lib/active_support/json/encoders/false_class.rb +5 -0
- data/lib/active_support/json/encoders/hash.rb +50 -0
- data/lib/active_support/json/encoders/nil_class.rb +5 -0
- data/lib/active_support/json/encoders/numeric.rb +5 -0
- data/lib/active_support/json/encoders/object.rb +6 -0
- data/lib/active_support/json/encoders/regexp.rb +5 -0
- data/lib/active_support/json/encoders/string.rb +30 -0
- data/lib/active_support/json/encoders/symbol.rb +5 -0
- data/lib/active_support/json/encoders/time.rb +5 -0
- data/lib/active_support/json/encoders/true_class.rb +5 -0
- data/lib/active_support/json/encoding.rb +38 -0
- data/lib/active_support/json/variable.rb +10 -0
- data/lib/active_support/multibyte.rb +7 -5
- data/lib/active_support/multibyte/chars.rb +6 -0
- data/lib/active_support/multibyte/handlers/utf8_handler.rb +115 -5
- data/lib/active_support/option_merger.rb +7 -7
- data/lib/active_support/ordered_options.rb +22 -17
- data/lib/active_support/test_case.rb +5 -0
- data/lib/active_support/testing.rb +1 -0
- data/lib/active_support/testing/default.rb +12 -0
- data/lib/active_support/values/time_zone.rb +3 -3
- data/lib/active_support/vendor.rb +14 -0
- data/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/lib/active_support/vendor/{builder.rb → builder-2.1.2/builder.rb} +0 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/lib/active_support/vendor/{builder → builder-2.1.2/builder}/xchar.rb +11 -8
- data/lib/active_support/vendor/{builder → builder-2.1.2/builder}/xmlbase.rb +38 -44
- data/lib/active_support/vendor/{builder → builder-2.1.2/builder}/xmlevents.rb +1 -1
- data/lib/active_support/vendor/{builder → builder-2.1.2/builder}/xmlmarkup.rb +40 -39
- data/lib/active_support/vendor/{xml_simple.rb → xml-simple-1.0.11/xmlsimple.rb} +3 -3
- data/lib/active_support/version.rb +3 -3
- data/lib/active_support/whiny_nil.rb +12 -12
- data/lib/activesupport.rb +1 -0
- metadata +69 -17
- data/lib/active_support/binding_of_caller.rb +0 -84
- data/lib/active_support/breakpoint.rb +0 -528
- data/lib/active_support/caching_tools.rb +0 -62
- data/lib/active_support/json/encoders.rb +0 -25
- data/lib/active_support/json/encoders/core.rb +0 -70
- data/lib/active_support/reloadable.rb +0 -60
- data/lib/active_support/vendor/builder/blankslate.rb +0 -63
@@ -1,62 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
module CachingTools #:nodoc:
|
3
|
-
|
4
|
-
# Provide shortcuts to simply the creation of nested default hashes. This
|
5
|
-
# pattern is useful, common practice, and unsightly when done manually.
|
6
|
-
module HashCaching
|
7
|
-
# Dynamically create a nested hash structure used to cache calls to +method_name+
|
8
|
-
# The cache method is named +#{method_name}_cache+ unless :as => :alternate_name
|
9
|
-
# is given.
|
10
|
-
#
|
11
|
-
# The hash structure is created using nested Hash.new. For example:
|
12
|
-
#
|
13
|
-
# def slow_method(a, b) a ** b end
|
14
|
-
#
|
15
|
-
# can be cached using hash_cache :slow_method, which will define the method
|
16
|
-
# slow_method_cache. We can then find the result of a ** b using:
|
17
|
-
#
|
18
|
-
# slow_method_cache[a][b]
|
19
|
-
#
|
20
|
-
# The hash structure returned by slow_method_cache would look like this:
|
21
|
-
#
|
22
|
-
# Hash.new do |as, a|
|
23
|
-
# as[a] = Hash.new do |bs, b|
|
24
|
-
# bs[b] = slow_method(a, b)
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# The generated code is actually compressed onto a single line to maintain
|
29
|
-
# sensible backtrace signatures.
|
30
|
-
#
|
31
|
-
def hash_cache(method_name, options = {})
|
32
|
-
selector = options[:as] || "#{method_name}_cache"
|
33
|
-
method = self.instance_method(method_name)
|
34
|
-
|
35
|
-
args = []
|
36
|
-
code = "def #{selector}(); @#{selector} ||= "
|
37
|
-
|
38
|
-
(1..method.arity).each do |n|
|
39
|
-
args << "v#{n}"
|
40
|
-
code << "Hash.new {|h#{n}, v#{n}| h#{n}[v#{n}] = "
|
41
|
-
end
|
42
|
-
|
43
|
-
# Add the method call with arguments, followed by closing braces and end.
|
44
|
-
code << "#{method_name}(#{args * ', '}) #{'}' * method.arity} end"
|
45
|
-
|
46
|
-
# Extract the line number information from the caller. Exceptions arising
|
47
|
-
# in the generated code should point to the +hash_cache :...+ line.
|
48
|
-
if caller[0] && /^(.*):(\d+)$/ =~ caller[0]
|
49
|
-
file, line_number = $1, $2.to_i
|
50
|
-
else # We can't give good trackback info; fallback to this line:
|
51
|
-
file, line_number = __FILE__, __LINE__
|
52
|
-
end
|
53
|
-
|
54
|
-
# We use eval rather than building proc's because it allows us to avoid
|
55
|
-
# linking the Hash's to this method's binding. Experience has shown that
|
56
|
-
# doing so can cause obtuse memory leaks.
|
57
|
-
class_eval code, file, line_number
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
module JSON #:nodoc:
|
3
|
-
module Encoders
|
4
|
-
mattr_accessor :encoders
|
5
|
-
@@encoders = {}
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def define_encoder(klass, &block)
|
9
|
-
encoders[klass] = block
|
10
|
-
end
|
11
|
-
|
12
|
-
def [](klass)
|
13
|
-
klass.ancestors.each do |k|
|
14
|
-
encoder = encoders[k]
|
15
|
-
return encoder if encoder
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
Dir[File.dirname(__FILE__) + '/encoders/*.rb'].each do |file|
|
24
|
-
require file[0..-4]
|
25
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
module JSON #:nodoc:
|
3
|
-
module Encoders #:nodoc:
|
4
|
-
define_encoder Object do |object|
|
5
|
-
object.instance_values.to_json
|
6
|
-
end
|
7
|
-
|
8
|
-
define_encoder TrueClass do
|
9
|
-
'true'
|
10
|
-
end
|
11
|
-
|
12
|
-
define_encoder FalseClass do
|
13
|
-
'false'
|
14
|
-
end
|
15
|
-
|
16
|
-
define_encoder NilClass do
|
17
|
-
'null'
|
18
|
-
end
|
19
|
-
|
20
|
-
ESCAPED_CHARS = {
|
21
|
-
"\010" => '\b',
|
22
|
-
"\f" => '\f',
|
23
|
-
"\n" => '\n',
|
24
|
-
"\r" => '\r',
|
25
|
-
"\t" => '\t',
|
26
|
-
'"' => '\"',
|
27
|
-
'\\' => '\\\\',
|
28
|
-
'<' => '\\074',
|
29
|
-
'>' => '\\076'
|
30
|
-
}
|
31
|
-
|
32
|
-
define_encoder String do |string|
|
33
|
-
'"' + string.gsub(/[\010\f\n\r\t"\\<>]/) { |s|
|
34
|
-
ESCAPED_CHARS[s]
|
35
|
-
}.gsub(/([\xC0-\xDF][\x80-\xBF]|
|
36
|
-
[\xE0-\xEF][\x80-\xBF]{2}|
|
37
|
-
[\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s|
|
38
|
-
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
|
39
|
-
} + '"'
|
40
|
-
end
|
41
|
-
|
42
|
-
define_encoder Numeric do |numeric|
|
43
|
-
numeric.to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
define_encoder Symbol do |symbol|
|
47
|
-
symbol.to_s.to_json
|
48
|
-
end
|
49
|
-
|
50
|
-
define_encoder Enumerable do |enumerable|
|
51
|
-
"[#{enumerable.map { |value| value.to_json } * ', '}]"
|
52
|
-
end
|
53
|
-
|
54
|
-
define_encoder Hash do |hash|
|
55
|
-
returning result = '{' do
|
56
|
-
result << hash.map do |key, value|
|
57
|
-
key = ActiveSupport::JSON::Variable.new(key.to_s) if
|
58
|
-
ActiveSupport::JSON.can_unquote_identifier?(key)
|
59
|
-
"#{key.to_json}: #{value.to_json}"
|
60
|
-
end * ', '
|
61
|
-
result << '}'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
define_encoder Regexp do |regexp|
|
66
|
-
regexp.inspect
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'active_support/deprecation'
|
2
|
-
|
3
|
-
# A deprecated mechanism to mark a class reloadable.
|
4
|
-
#
|
5
|
-
# Deprecated as of Rails 1.2.
|
6
|
-
# All autoloaded objects are now unloaded.
|
7
|
-
module Reloadable #:nodoc:
|
8
|
-
class << self
|
9
|
-
def included(base) #nodoc:
|
10
|
-
unless base.ancestors.include?(Reloadable::Subclasses) # Avoid double warning
|
11
|
-
ActiveSupport::Deprecation.warn "Reloadable has been deprecated and has no effect.", caller
|
12
|
-
end
|
13
|
-
|
14
|
-
raise TypeError, "Only Classes can be Reloadable!" unless base.is_a? Class
|
15
|
-
|
16
|
-
unless base.respond_to?(:reloadable?)
|
17
|
-
class << base
|
18
|
-
define_method(:reloadable?) do
|
19
|
-
ActiveSupport::Deprecation.warn "Reloadable has been deprecated and reloadable? has no effect", caller
|
20
|
-
true
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def reloadable_classes
|
27
|
-
ActiveSupport::Deprecation.silence do
|
28
|
-
included_in_classes.select { |klass| klass.reloadable? }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
deprecate :reloadable_classes
|
32
|
-
end
|
33
|
-
|
34
|
-
# Captures the common pattern where a base class should not be reloaded,
|
35
|
-
# but its subclasses should be.
|
36
|
-
#
|
37
|
-
# Deprecated as of Rails 1.2.
|
38
|
-
# All autoloaded objects are now unloaded.
|
39
|
-
module Subclasses #:nodoc:
|
40
|
-
def self.included(base) #nodoc:
|
41
|
-
base.send :include, Reloadable
|
42
|
-
ActiveSupport::Deprecation.warn "Reloadable::Subclasses has been deprecated and has no effect.", caller
|
43
|
-
(class << base; self; end).send(:define_method, :reloadable?) do
|
44
|
-
ActiveSupport::Deprecation.warn "Reloadable has been deprecated and reloadable? has no effect", caller
|
45
|
-
base != self
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
module Deprecated #:nodoc:
|
51
|
-
def self.included(base)
|
52
|
-
class << base
|
53
|
-
define_method(:reloadable?) do
|
54
|
-
ActiveSupport::Deprecation.warn "Reloadable has been deprecated and reloadable? has no effect", caller
|
55
|
-
true # This might not have the desired effect, as AR::B.reloadable? => true.
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#--
|
3
|
-
# Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
4
|
-
# All rights reserved.
|
5
|
-
|
6
|
-
# Permission is granted for use, copying, modification, distribution,
|
7
|
-
# and distribution of modified versions of this work as long as the
|
8
|
-
# above copyright notice is included.
|
9
|
-
#++
|
10
|
-
|
11
|
-
module Builder #:nodoc:
|
12
|
-
|
13
|
-
# BlankSlate provides an abstract base class with no predefined
|
14
|
-
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
15
|
-
# BlankSlate is useful as a base class when writing classes that
|
16
|
-
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
17
|
-
class BlankSlate
|
18
|
-
class << self
|
19
|
-
|
20
|
-
# Hide the method named +name+ in the BlankSlate class. Don't
|
21
|
-
# hide +instance_eval+ or any method beginning with "__".
|
22
|
-
def hide(name)
|
23
|
-
undef_method name if
|
24
|
-
instance_methods.include?(name.to_s) and
|
25
|
-
name !~ /^(__|instance_eval)/
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
instance_methods.each { |m| hide(m) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Since Ruby is very dynamic, methods added to the ancestors of
|
34
|
-
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
|
35
|
-
# list of available BlankSlate methods. We handle this by defining a
|
36
|
-
# hook in the Object and Kernel classes that will hide any defined
|
37
|
-
module Kernel #:nodoc:
|
38
|
-
class << self
|
39
|
-
alias_method :blank_slate_method_added, :method_added
|
40
|
-
|
41
|
-
# Detect method additions to Kernel and remove them in the
|
42
|
-
# BlankSlate class.
|
43
|
-
def method_added(name)
|
44
|
-
blank_slate_method_added(name)
|
45
|
-
return if self != Kernel
|
46
|
-
Builder::BlankSlate.hide(name)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Object #:nodoc:
|
52
|
-
class << self
|
53
|
-
alias_method :blank_slate_method_added, :method_added
|
54
|
-
|
55
|
-
# Detect method additions to Object and remove them in the
|
56
|
-
# BlankSlate class.
|
57
|
-
def method_added(name)
|
58
|
-
blank_slate_method_added(name)
|
59
|
-
return if self != Object
|
60
|
-
Builder::BlankSlate.hide(name)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|