activesupport 3.0.0.beta → 3.0.0.beta2

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.

Files changed (73) hide show
  1. data/CHANGELOG +15 -1
  2. data/lib/active_support.rb +3 -0
  3. data/lib/active_support/all.rb +0 -1
  4. data/lib/active_support/cache/mem_cache_store.rb +1 -1
  5. data/lib/active_support/callbacks.rb +2 -2
  6. data/lib/active_support/core_ext/array/conversions.rb +0 -1
  7. data/lib/active_support/core_ext/array/extract_options.rb +16 -1
  8. data/lib/active_support/core_ext/class.rb +1 -0
  9. data/lib/active_support/core_ext/class/attribute.rb +30 -5
  10. data/lib/active_support/core_ext/class/attribute_accessors.rb +33 -27
  11. data/lib/active_support/core_ext/class/delegating_attributes.rb +10 -7
  12. data/lib/active_support/core_ext/class/subclasses.rb +55 -0
  13. data/lib/active_support/core_ext/date_time/conversions.rb +1 -0
  14. data/lib/active_support/core_ext/file/atomic.rb +3 -2
  15. data/lib/active_support/core_ext/file/path.rb +5 -0
  16. data/lib/active_support/core_ext/hash/conversions.rb +9 -0
  17. data/lib/active_support/core_ext/kernel.rb +0 -1
  18. data/lib/active_support/core_ext/kernel/debugger.rb +1 -1
  19. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  20. data/lib/active_support/core_ext/module.rb +5 -3
  21. data/lib/active_support/core_ext/module/anonymous.rb +24 -0
  22. data/lib/active_support/core_ext/module/attribute_accessors.rb +25 -21
  23. data/lib/active_support/core_ext/module/delegation.rb +20 -9
  24. data/lib/active_support/core_ext/module/introspection.rb +8 -8
  25. data/lib/active_support/core_ext/module/method_names.rb +14 -0
  26. data/lib/active_support/core_ext/module/reachable.rb +10 -0
  27. data/lib/active_support/core_ext/module/remove_method.rb +6 -0
  28. data/lib/active_support/core_ext/object.rb +7 -1
  29. data/lib/active_support/core_ext/object/extending.rb +11 -0
  30. data/lib/active_support/core_ext/object/singleton_class.rb +13 -0
  31. data/lib/active_support/core_ext/proc.rb +3 -3
  32. data/lib/active_support/core_ext/string/conversions.rb +1 -0
  33. data/lib/active_support/core_ext/string/inflections.rb +1 -1
  34. data/lib/active_support/core_ext/string/interpolation.rb +1 -91
  35. data/lib/active_support/core_ext/string/output_safety.rb +12 -8
  36. data/lib/active_support/core_ext/string/xchar.rb +1 -1
  37. data/lib/active_support/core_ext/time/conversions.rb +1 -0
  38. data/lib/active_support/core_ext/time/marshal.rb +56 -0
  39. data/lib/active_support/dependencies.rb +146 -191
  40. data/lib/active_support/dependencies/autoload.rb +1 -0
  41. data/lib/active_support/deprecation/method_wrappers.rb +9 -9
  42. data/lib/active_support/deprecation/reporting.rb +2 -1
  43. data/lib/active_support/hash_with_indifferent_access.rb +4 -0
  44. data/lib/active_support/i18n.rb +2 -1
  45. data/lib/active_support/inflector/methods.rb +1 -1
  46. data/lib/active_support/inflector/transliterate.rb +3 -3
  47. data/lib/active_support/json/backends/yajl.rb +40 -0
  48. data/lib/active_support/json/decoding.rb +16 -1
  49. data/lib/active_support/lazy_load_hooks.rb +17 -0
  50. data/lib/active_support/memoizable.rb +1 -1
  51. data/lib/active_support/multibyte.rb +2 -2
  52. data/lib/active_support/multibyte/utils.rb +1 -1
  53. data/lib/active_support/notifications.rb +7 -3
  54. data/lib/active_support/notifications/fanout.rb +19 -5
  55. data/lib/active_support/ordered_options.rb +6 -0
  56. data/lib/active_support/railtie.rb +9 -9
  57. data/lib/active_support/ruby/shim.rb +2 -0
  58. data/lib/active_support/test_case.rb +2 -7
  59. data/lib/active_support/testing/assertions.rb +15 -0
  60. data/lib/active_support/testing/isolation.rb +2 -2
  61. data/lib/active_support/time.rb +1 -1
  62. data/lib/active_support/values/time_zone.rb +7 -4
  63. data/lib/active_support/version.rb +3 -2
  64. data/lib/active_support/whiny_nil.rb +4 -5
  65. data/lib/active_support/xml_mini/libxmlsax.rb +1 -0
  66. data/lib/active_support/xml_mini/nokogirisax.rb +1 -0
  67. data/lib/active_support/xml_mini/rexml.rb +7 -1
  68. metadata +65 -31
  69. data/lib/active_support/core_ext/kernel/daemonizing.rb +0 -7
  70. data/lib/active_support/core_ext/module/inclusion.rb +0 -30
  71. data/lib/active_support/core_ext/module/loading.rb +0 -25
  72. data/lib/active_support/core_ext/object/metaclass.rb +0 -13
  73. data/lib/active_support/core_ext/time/marshal_with_utc_flag.rb +0 -22
@@ -2,21 +2,25 @@ require 'active_support/core_ext/array/extract_options'
2
2
 
3
3
  class Module
4
4
  def mattr_reader(*syms)
5
- syms.extract_options!
5
+ options = syms.extract_options!
6
6
  syms.each do |sym|
7
7
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
8
- unless defined? @@#{sym} # unless defined? @@pagination_options
9
- @@#{sym} = nil # @@pagination_options = nil
10
- end # end
11
-
12
- def self.#{sym} # def self.pagination_options
13
- @@#{sym} # @@pagination_options
14
- end # end
8
+ unless defined? @@#{sym}
9
+ @@#{sym} = nil
10
+ end
15
11
 
16
- def #{sym} # def pagination_options
17
- @@#{sym} # @@pagination_options
18
- end # end
12
+ def self.#{sym}
13
+ @@#{sym}
14
+ end
19
15
  EOS
16
+
17
+ unless options[:instance_reader] == false
18
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
19
+ def #{sym}
20
+ @@#{sym}
21
+ end
22
+ EOS
23
+ end
20
24
  end
21
25
  end
22
26
 
@@ -24,20 +28,20 @@ class Module
24
28
  options = syms.extract_options!
25
29
  syms.each do |sym|
26
30
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
27
- unless defined? @@#{sym} # unless defined? @@pagination_options
28
- @@#{sym} = nil # @@pagination_options = nil
29
- end # end
31
+ unless defined? @@#{sym}
32
+ @@#{sym} = nil
33
+ end
30
34
 
31
- def self.#{sym}=(obj) # def self.pagination_options=(obj)
32
- @@#{sym} = obj # @@pagination_options = obj
33
- end # end
35
+ def self.#{sym}=(obj)
36
+ @@#{sym} = obj
37
+ end
34
38
  EOS
35
39
 
36
40
  unless options[:instance_writer] == false
37
- class_eval(<<-EOS, __FILE__, __LINE__)
38
- def #{sym}=(obj) # def pagination_options=(obj)
39
- @@#{sym} = obj # @@pagination_options = obj
40
- end # end
41
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
42
+ def #{sym}=(obj)
43
+ @@#{sym} = obj
44
+ end
41
45
  EOS
42
46
  end
43
47
  end
@@ -1,14 +1,21 @@
1
+ require "active_support/core_ext/module/remove_method"
2
+
1
3
  class Module
2
4
  # Provides a delegate class method to easily expose contained objects' methods
3
5
  # as your own. Pass one or more methods (specified as symbols or strings)
4
- # and the name of the target object as the final <tt>:to</tt> option (also a symbol
5
- # or string). At least one method and the <tt>:to</tt> option are required.
6
+ # and the name of the target object via the <tt>:to</tt> option (also a symbol
7
+ # or string). At least one method and the <tt>:to</tt> option are required.
6
8
  #
7
9
  # Delegation is particularly useful with Active Record associations:
8
10
  #
9
11
  # class Greeter < ActiveRecord::Base
10
- # def hello() "hello" end
11
- # def goodbye() "goodbye" end
12
+ # def hello
13
+ # "hello"
14
+ # end
15
+ #
16
+ # def goodbye
17
+ # "goodbye"
18
+ # end
12
19
  # end
13
20
  #
14
21
  # class Foo < ActiveRecord::Base
@@ -34,7 +41,7 @@ class Module
34
41
  # class Foo
35
42
  # CONSTANT_ARRAY = [0,1,2,3]
36
43
  # @@class_array = [4,5,6,7]
37
- #
44
+ #
38
45
  # def initialize
39
46
  # @instance_array = [8,9,10,11]
40
47
  # end
@@ -72,9 +79,9 @@ class Module
72
79
  # invoice.customer_name # => "John Doe"
73
80
  # invoice.customer_address # => "Vimmersvej 13"
74
81
  #
75
- # If the object to which you delegate can be nil, you may want to use the
76
- # :allow_nil option. In that case, it returns nil instead of raising a
77
- # NoMethodError exception:
82
+ # If the delegate object is +nil+ an exception is raised, and that happens
83
+ # no matter whether +nil+ responds to the delegated method. You can get a
84
+ # +nil+ instead with the +:allow_nil+ option.
78
85
  #
79
86
  # class Foo
80
87
  # attr_accessor :bar
@@ -120,11 +127,15 @@ class Module
120
127
  end
121
128
 
122
129
  module_eval(<<-EOS, file, line)
130
+ if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}")
131
+ remove_possible_method("#{prefix}#{method}")
132
+ end
133
+
123
134
  def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
124
135
  #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block)
125
136
  rescue NoMethodError # rescue NoMethodError
126
137
  if #{to}.nil? # if client.nil?
127
- #{on_nil}
138
+ #{on_nil} # return # depends on :allow_nil
128
139
  else # else
129
140
  raise # raise
130
141
  end # end
@@ -3,7 +3,7 @@ require 'active_support/inflector'
3
3
  class Module
4
4
  # Returns the name of the module containing this one.
5
5
  #
6
- # p M::N.parent_name # => "M"
6
+ # M::N.parent_name # => "M"
7
7
  def parent_name
8
8
  unless defined? @parent_name
9
9
  @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
@@ -19,13 +19,13 @@ class Module
19
19
  # end
20
20
  # X = M::N
21
21
  #
22
- # p M::N.parent # => M
23
- # p X.parent # => M
22
+ # M::N.parent # => M
23
+ # X.parent # => M
24
24
  #
25
25
  # The parent of top-level and anonymous modules is Object.
26
26
  #
27
- # p M.parent # => Object
28
- # p Module.new.parent # => Object
27
+ # M.parent # => Object
28
+ # Module.new.parent # => Object
29
29
  #
30
30
  def parent
31
31
  parent_name ? ActiveSupport::Inflector.constantize(parent_name) : Object
@@ -40,9 +40,9 @@ class Module
40
40
  # end
41
41
  # X = M::N
42
42
  #
43
- # p M.parents # => [Object]
44
- # p M::N.parents # => [M, Object]
45
- # p X.parents # => [M, Object]
43
+ # M.parents # => [Object]
44
+ # M::N.parents # => [M, Object]
45
+ # X.parents # => [M, Object]
46
46
  #
47
47
  def parents
48
48
  parents = []
@@ -0,0 +1,14 @@
1
+ class Module
2
+ if instance_methods[0].is_a?(Symbol)
3
+ def instance_method_names(*args)
4
+ instance_methods(*args).map(&:to_s)
5
+ end
6
+
7
+ def method_names(*args)
8
+ methods(*args).map(&:to_s)
9
+ end
10
+ else
11
+ alias_method :instance_method_names, :instance_methods
12
+ alias_method :method_names, :methods
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ require 'active_support/core_ext/module/anonymous'
2
+ require 'active_support/core_ext/string/inflections'
3
+
4
+ class Module
5
+ def reachable? #:nodoc:
6
+ !anonymous? && name.constantize.equal?(self)
7
+ rescue NameError
8
+ false
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class Module
2
+ def remove_possible_method(method)
3
+ remove_method(method)
4
+ rescue NameError
5
+ end
6
+ end
@@ -5,5 +5,11 @@ require 'active_support/core_ext/object/try'
5
5
 
6
6
  require 'active_support/core_ext/object/conversions'
7
7
  require 'active_support/core_ext/object/instance_variables'
8
- require 'active_support/core_ext/object/metaclass'
8
+ require 'active_support/core_ext/object/singleton_class'
9
9
  require 'active_support/core_ext/object/misc'
10
+ require 'active_support/core_ext/object/extending'
11
+
12
+ require 'active_support/core_ext/object/returning'
13
+ require 'active_support/core_ext/object/to_param'
14
+ require 'active_support/core_ext/object/to_query'
15
+ require 'active_support/core_ext/object/with_options'
@@ -0,0 +1,11 @@
1
+ require 'active_support/core_ext/class/subclasses'
2
+
3
+ class Object
4
+ # Exclude this class unless it's a subclass of our supers and is defined.
5
+ # We check defined? in case we find a removed class that has yet to be
6
+ # garbage collected. This also fails for anonymous classes -- please
7
+ # submit a patch if you have a workaround.
8
+ def subclasses_of(*superclasses) #:nodoc:
9
+ Class.subclasses_of(*superclasses)
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class Object
2
+ # Returns the object's singleton class.
3
+ def singleton_class
4
+ class << self
5
+ self
6
+ end
7
+ end unless respond_to?(:singleton_class)
8
+
9
+ # class_eval on an object acts like singleton_class_eval.
10
+ def class_eval(*args, &block)
11
+ singleton_class.class_eval(*args, &block)
12
+ end
13
+ end
@@ -5,9 +5,9 @@ class Proc #:nodoc:
5
5
  block, time = self, Time.now
6
6
  object.class_eval do
7
7
  method_name = "__bind_#{time.to_i}_#{time.usec}"
8
- define_method(method_name, &block) # define_method("__bind_1230458026_720454", &block)
9
- method = instance_method(method_name) # method = instance_method("__bind_1230458026_720454")
10
- remove_method(method_name) # remove_method("__bind_1230458026_720454")
8
+ define_method(method_name, &block)
9
+ method = instance_method(method_name)
10
+ remove_method(method_name)
11
11
  method
12
12
  end.bind(object)
13
13
  end
@@ -1,4 +1,5 @@
1
1
  require 'date'
2
+ require 'active_support/core_ext/time/publicize_conversion_methods'
2
3
  require 'active_support/core_ext/time/calculations'
3
4
 
4
5
  class String
@@ -2,7 +2,7 @@
2
2
  # For instance, you can figure out the name of a database from the name of a class.
3
3
  #
4
4
  # "ScaleScore".tableize # => "scale_scores"
5
-
5
+ #
6
6
  class String
7
7
  # Returns the plural form of the word in the string.
8
8
  #
@@ -1,91 +1 @@
1
- =begin
2
- heavily based on Masao Mutoh's gettext String interpolation extension
3
- http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
4
- Copyright (C) 2005-2010 Masao Mutoh
5
- You may redistribute it and/or modify it under the same license terms as Ruby.
6
- =end
7
-
8
- if RUBY_VERSION < '1.9' && !"".respond_to?(:interpolate_without_ruby_19_syntax)
9
-
10
- # KeyError is raised by String#% when the string contains a named placeholder
11
- # that is not contained in the given arguments hash. Ruby 1.9 includes and
12
- # raises this exception natively. We define it to mimic Ruby 1.9's behaviour
13
- # in Ruby 1.8.x
14
-
15
- class KeyError < IndexError
16
- def initialize(message = nil)
17
- super(message || "key not found")
18
- end
19
- end unless defined?(KeyError)
20
-
21
- # Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError.
22
- #
23
- # String#% method which accept "named argument". The translator can know
24
- # the meaning of the msgids using "named argument" instead of %s/%d style.
25
-
26
- class String
27
- alias :interpolate_without_ruby_19_syntax :% # :nodoc:
28
-
29
- INTERPOLATION_PATTERN = Regexp.union(
30
- /%%/,
31
- /%\{(\w+)\}/, # matches placeholders like "%{foo}"
32
- /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
33
- )
34
-
35
- # % uses self (i.e. the String) as a format specification and returns the
36
- # result of applying it to the given arguments. In other words it interpolates
37
- # the given arguments to the string according to the formats the string
38
- # defines.
39
- #
40
- # There are three ways to use it:
41
- #
42
- # * Using a single argument or Array of arguments.
43
- #
44
- # This is the default behaviour of the String class. See Kernel#sprintf for
45
- # more details about the format string.
46
- #
47
- # Example:
48
- #
49
- # "%d %s" % [1, "message"]
50
- # # => "1 message"
51
- #
52
- # * Using a Hash as an argument and unformatted, named placeholders.
53
- #
54
- # When you pass a Hash as an argument and specify placeholders with %{foo}
55
- # it will interpret the hash values as named arguments.
56
- #
57
- # Example:
58
- #
59
- # "%{firstname}, %{lastname}" % {:firstname => "Masao", :lastname => "Mutoh"}
60
- # # => "Masao Mutoh"
61
- #
62
- # * Using a Hash as an argument and formatted, named placeholders.
63
- #
64
- # When you pass a Hash as an argument and specify placeholders with %<foo>d
65
- # it will interpret the hash values as named arguments and format the value
66
- # according to the formatting instruction appended to the closing >.
67
- #
68
- # Example:
69
- #
70
- # "%<integer>d, %<float>.1f" % { :integer => 10, :float => 43.4 }
71
- # # => "10, 43.3"
72
- def %(args)
73
- if args.kind_of?(Hash)
74
- dup.gsub(INTERPOLATION_PATTERN) do |match|
75
- if match == '%%'
76
- '%'
77
- else
78
- key = ($1 || $2).to_sym
79
- raise KeyError unless args.has_key?(key)
80
- $3 ? sprintf("%#{$3}", args[key]) : args[key]
81
- end
82
- end
83
- elsif self =~ INTERPOLATION_PATTERN
84
- raise ArgumentError.new('one hash required')
85
- else
86
- result = gsub(/%([{<])/, '%%\1')
87
- result.send :'interpolate_without_ruby_19_syntax', args
88
- end
89
- end
90
- end
91
- end
1
+ require 'i18n/core_ext/string/interpolate'
@@ -1,4 +1,5 @@
1
- require "erb"
1
+ require 'erb'
2
+ require 'active_support/core_ext/object/singleton_class'
2
3
 
3
4
  class ERB
4
5
  module Util
@@ -23,12 +24,14 @@ class ERB
23
24
  end
24
25
  end
25
26
 
26
- undef :h
27
+ remove_method(:h)
27
28
  alias h html_escape
28
29
 
29
- module_function :html_escape
30
30
  module_function :h
31
31
 
32
+ singleton_class.send(:remove_method, :html_escape)
33
+ module_function :html_escape
34
+
32
35
  # A utility method for escaping HTML entities in JSON strings.
33
36
  # This method is also aliased as <tt>j</tt>.
34
37
  #
@@ -71,15 +74,12 @@ module ActiveSupport #:nodoc:
71
74
  super(ERB::Util.h(value))
72
75
  end
73
76
  end
77
+ alias << concat
74
78
 
75
79
  def +(other)
76
80
  dup.concat(other)
77
81
  end
78
82
 
79
- def <<(value)
80
- self.concat(value)
81
- end
82
-
83
83
  def html_safe?
84
84
  true
85
85
  end
@@ -91,6 +91,10 @@ module ActiveSupport #:nodoc:
91
91
  def to_s
92
92
  self
93
93
  end
94
+
95
+ def to_yaml(*args)
96
+ to_str.to_yaml(*args)
97
+ end
94
98
  end
95
99
  end
96
100
 
@@ -102,4 +106,4 @@ class String
102
106
  def html_safe
103
107
  ActiveSupport::SafeBuffer.new(self)
104
108
  end
105
- end
109
+ end
@@ -1,5 +1,5 @@
1
1
  begin
2
- # See http://bogomips.org/fast_xs/ by Eric Wong.
2
+ # See http://fast-xs.rubyforge.org/ by Eric Wong.
3
3
  # Also included with hpricot.
4
4
  require 'fast_xs'
5
5
  rescue LoadError
@@ -1,4 +1,5 @@
1
1
  require 'active_support/inflector'
2
+ require 'active_support/core_ext/time/publicize_conversion_methods'
2
3
  require 'active_support/values/time_zone'
3
4
 
4
5
  class Time