activesupport 2.3.6.pre → 2.3.6

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 (123) hide show
  1. data/CHANGELOG +9 -5
  2. data/lib/active_support/buffered_logger.rb +1 -1
  3. data/lib/active_support/cache/memory_store.rb +7 -1
  4. data/lib/active_support/cache/strategy/local_cache.rb +1 -1
  5. data/lib/active_support/core_ext/array/conversions.rb +1 -1
  6. data/lib/active_support/core_ext/array/random_access.rb +11 -1
  7. data/lib/active_support/core_ext/class/attribute_accessors.rb +35 -28
  8. data/lib/active_support/core_ext/date/calculations.rb +14 -4
  9. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  10. data/lib/active_support/core_ext/module/aliasing.rb +1 -1
  11. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  12. data/lib/active_support/core_ext/module/attribute_accessors.rb +33 -26
  13. data/lib/active_support/core_ext/module/synchronization.rb +1 -1
  14. data/lib/active_support/core_ext/object/blank.rb +20 -2
  15. data/lib/active_support/core_ext/string/output_safety.rb +10 -2
  16. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -4
  17. data/lib/active_support/core_ext/time.rb +8 -4
  18. data/lib/active_support/core_ext/time/calculations.rb +11 -2
  19. data/lib/active_support/deprecation.rb +3 -2
  20. data/lib/active_support/inflections.rb +1 -1
  21. data/lib/active_support/inflector.rb +4 -1
  22. data/lib/active_support/json/backends/yaml.rb +10 -7
  23. data/lib/active_support/json/decoding.rb +1 -1
  24. data/lib/active_support/memoizable.rb +1 -1
  25. data/lib/active_support/multibyte/unicode_database.rb +2 -2
  26. data/lib/active_support/multibyte/utils.rb +6 -7
  27. data/lib/active_support/ordered_hash.rb +24 -30
  28. data/lib/active_support/testing/assertions.rb +14 -0
  29. data/lib/active_support/values/time_zone.rb +84 -76
  30. data/lib/active_support/vendor.rb +1 -1
  31. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n.rb +92 -34
  32. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend.rb +2 -0
  33. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record.rb +9 -13
  34. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/missing.rb +1 -1
  35. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/store_procs.rb +6 -6
  36. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/translation.rb +14 -9
  37. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/base.rb +23 -16
  38. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cache.rb +1 -0
  39. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cascade.rb +22 -8
  40. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/chain.rb +2 -1
  41. data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/cldr.rb +100 -0
  42. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fallbacks.rb +20 -3
  43. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fast.rb +14 -13
  44. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/gettext.rb +1 -1
  45. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/helpers.rb +4 -16
  46. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/interpolation_compiler.rb +2 -2
  47. data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/links.rb +34 -0
  48. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/metadata.rb +0 -0
  49. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/pluralization.rb +1 -1
  50. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/simple.rb +0 -0
  51. data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/except.rb +8 -0
  52. data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/slice.rb +8 -0
  53. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/object/meta_class.rb +0 -0
  54. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/string/interpolate.rb +1 -1
  55. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/exceptions.rb +1 -1
  56. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/gettext.rb +0 -0
  57. data/lib/active_support/vendor/{i18n-0.3.3/vendor → i18n-0.3.7/i18n/gettext}/po_parser.rb +0 -0
  58. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers.rb +0 -0
  59. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers/gettext.rb +3 -2
  60. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale.rb +0 -0
  61. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/fallbacks.rb +0 -0
  62. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag.rb +0 -0
  63. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/parents.rb +0 -0
  64. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/rfc4646.rb +0 -0
  65. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/simple.rb +0 -0
  66. data/lib/active_support/vendor/i18n-0.3.7/i18n/version.rb +3 -0
  67. metadata +42 -96
  68. data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +0 -76
  69. data/lib/active_support/vendor/i18n-0.3.3/MIT-LICENSE +0 -20
  70. data/lib/active_support/vendor/i18n-0.3.3/README.textile +0 -81
  71. data/lib/active_support/vendor/i18n-0.3.3/Rakefile +0 -24
  72. data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +0 -144
  73. data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +0 -71
  74. data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +0 -17
  75. data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +0 -165
  76. data/lib/active_support/vendor/i18n-0.3.3/init.rb +0 -1
  77. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +0 -3
  78. data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +0 -8
  79. data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +0 -15
  80. data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +0 -40
  81. data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +0 -92
  82. data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +0 -55
  83. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +0 -91
  84. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +0 -90
  85. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +0 -54
  86. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +0 -84
  87. data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +0 -45
  88. data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +0 -35
  89. data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +0 -40
  90. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +0 -29
  91. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +0 -40
  92. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +0 -31
  93. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +0 -26
  94. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +0 -33
  95. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +0 -31
  96. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +0 -33
  97. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +0 -21
  98. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +0 -60
  99. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +0 -52
  100. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +0 -72
  101. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +0 -66
  102. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +0 -64
  103. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +0 -57
  104. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +0 -50
  105. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +0 -26
  106. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +0 -107
  107. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +0 -67
  108. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +0 -43
  109. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +0 -77
  110. data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +0 -94
  111. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +0 -201
  112. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +0 -91
  113. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_exceptions_test.rb +0 -97
  114. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +0 -23
  115. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +0 -172
  116. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +0 -126
  117. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +0 -143
  118. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +0 -33
  119. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +0 -72
  120. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +0 -3
  121. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +0 -3
  122. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +0 -113
  123. data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +0 -100
data/CHANGELOG CHANGED
@@ -1,4 +1,12 @@
1
- *2.3.6 (pending)*
1
+ *2.3.6 (May 23, 2010)*
2
+
3
+ * 1.9 compat: deprecated last_(month|year) in favor of prev_(month|year). [fxn]
4
+
5
+ * Deprecated Array#rand in favor of Array#random_element. [Santiago Pastorino, Rizwan Reza]
6
+
7
+ * Added Object#presence that returns the object if it's #present? otherwise returns nil [DHH/Colin Kelley]
8
+
9
+ * New assertions assert_blank and assert_present. #4299 [Juanjo Bazan]
2
10
 
3
11
  * Use Object#singleton_class instead of #metaclass. Prefer Ruby's choice. [Jeremy Kemper]
4
12
 
@@ -10,10 +18,6 @@
10
18
 
11
19
  * YAML serialization for OrderedHash. #3608 [Gregor Schmidt]
12
20
 
13
- * Update bundled TZInfo to v0.3.16 [Geoff Buesing]
14
-
15
- * Georgetown TimeZone is now mapped to "America/Guyana" instead of "America/Argentina/San_Juan" #1821 [Geoff Buesing, Reuben Sivan]
16
-
17
21
  * Add Enumerable#exclude? to bring parity to Enumerable#include? and avoid if !x.include?/else calls [DHH]
18
22
 
19
23
 
@@ -67,7 +67,7 @@ module ActiveSupport
67
67
  end
68
68
 
69
69
  for severity in Severity.constants
70
- class_eval <<-EOT, __FILE__, __LINE__
70
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
71
71
  def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block)
72
72
  add(#{severity}, message, progname, &block) # add(DEBUG, message, progname, &block)
73
73
  end # end
@@ -19,6 +19,12 @@ module ActiveSupport
19
19
  @data = {}
20
20
  end
21
21
 
22
+ def read_multi(*names)
23
+ results = {}
24
+ names.each { |n| results[n] = read(n) }
25
+ results
26
+ end
27
+
22
28
  def read(name, options = nil)
23
29
  super
24
30
  @data[name]
@@ -39,7 +45,7 @@ module ActiveSupport
39
45
  @data.delete_if { |k,v| k =~ matcher }
40
46
  end
41
47
 
42
- def exist?(name,options = nil)
48
+ def exist?(name, options = nil)
43
49
  super
44
50
  @data.has_key?(name)
45
51
  end
@@ -15,7 +15,7 @@ module ActiveSupport
15
15
  def middleware
16
16
  @middleware ||= begin
17
17
  klass = Class.new
18
- klass.class_eval(<<-EOS, __FILE__, __LINE__)
18
+ klass.class_eval(<<-EOS, __FILE__, __LINE__ + 1)
19
19
  def initialize(app)
20
20
  @app = app
21
21
  end
@@ -164,7 +164,7 @@ module ActiveSupport #:nodoc:
164
164
  require 'builder' unless defined?(Builder)
165
165
 
166
166
  options = options.dup
167
- options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
167
+ options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize.tr('/', '-') : "records"
168
168
  options[:children] ||= options[:root].singularize
169
169
  options[:indent] ||= 2
170
170
  options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
@@ -2,8 +2,18 @@ module ActiveSupport #:nodoc:
2
2
  module CoreExtensions #:nodoc:
3
3
  module Array #:nodoc:
4
4
  module RandomAccess
5
+ # This method is deprecated because it masks Kernel#rand within the Array class itself,
6
+ # which may be used by a 3rd party library extending Array in turn. See
7
+ #
8
+ # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4555
9
+ #
10
+ def rand # :nodoc:
11
+ ActiveSupport::Deprecation.warn 'Array#rand is deprecated and will be removed in Rails 3. Use "random_element" instead', caller
12
+ random_element
13
+ end
14
+
5
15
  # Returns a random element from the array.
6
- def rand
16
+ def random_element
7
17
  self[Kernel.rand(length)]
8
18
  end
9
19
  end
@@ -8,42 +8,49 @@
8
8
  # Person.hair_colors = [:brown, :black, :blonde, :red]
9
9
  class Class
10
10
  def cattr_reader(*syms)
11
- syms.flatten.each do |sym|
11
+ options = syms.extract_options!
12
+ syms.each do |sym|
12
13
  next if sym.is_a?(Hash)
13
- class_eval(<<-EOS, __FILE__, __LINE__)
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
14
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
15
+ unless defined? @@#{sym}
16
+ @@#{sym} = nil
17
+ end
18
+
19
+ def self.#{sym}
20
+ @@#{sym}
21
+ end
25
22
  EOS
23
+
24
+ unless options[:instance_reader] == false
25
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
26
+ def #{sym}
27
+ @@#{sym}
28
+ end
29
+ EOS
30
+ end
26
31
  end
27
32
  end
28
33
 
29
34
  def cattr_writer(*syms)
30
35
  options = syms.extract_options!
31
- syms.flatten.each do |sym|
32
- class_eval(<<-EOS, __FILE__, __LINE__)
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
36
+ syms.each do |sym|
37
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
38
+ unless defined? @@#{sym}
39
+ @@#{sym} = nil
40
+ end
41
+
42
+ def self.#{sym}=(obj)
43
+ @@#{sym} = obj
44
+ end
46
45
  EOS
46
+
47
+ unless options[:instance_writer] == false
48
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
49
+ def #{sym}=(obj)
50
+ @@#{sym} = obj
51
+ end
52
+ EOS
53
+ end
47
54
  end
48
55
  end
49
56
 
@@ -135,20 +135,30 @@ module ActiveSupport #:nodoc:
135
135
  advance(:years => years)
136
136
  end
137
137
 
138
+ def last_year # :nodoc:
139
+ ActiveSupport::Deprecation.warn("Date#last_year is deprecated and has been removed in Rails 3, please use Date#prev_year instead", caller)
140
+ prev_year
141
+ end
142
+
138
143
  # Short-hand for years_ago(1)
139
- def last_year
144
+ def prev_year
140
145
  years_ago(1)
141
- end
146
+ end unless method_defined?(:prev_year)
142
147
 
143
148
  # Short-hand for years_since(1)
144
149
  def next_year
145
150
  years_since(1)
146
151
  end
147
152
 
153
+ def last_month # :nodoc:
154
+ ActiveSupport::Deprecation.warn("Date#last_month is deprecated and has been removed in Rails 3, please use Date#prev_month instead", caller)
155
+ prev_month
156
+ end
157
+
148
158
  # Short-hand for months_ago(1)
149
- def last_month
159
+ def prev_month
150
160
  months_ago(1)
151
- end
161
+ end unless method_defined?(:prev_month)
152
162
 
153
163
  # Short-hand for months_since(1)
154
164
  def next_month
@@ -35,7 +35,7 @@ module Kernel
35
35
  # puts 'But this will'
36
36
  def silence_stream(stream)
37
37
  old_stream = stream.dup
38
- stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
38
+ stream.reopen(RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'NUL:' : '/dev/null')
39
39
  stream.sync = true
40
40
  yield
41
41
  ensure
@@ -63,7 +63,7 @@ module ActiveSupport
63
63
  # e.subject = "Megastars"
64
64
  # e.title # => "Megastars"
65
65
  def alias_attribute(new_name, old_name)
66
- module_eval <<-STR, __FILE__, __LINE__+1
66
+ module_eval <<-STR, __FILE__, __LINE__ + 1
67
67
  def #{new_name}; self.#{old_name}; end # def subject; self.title; end
68
68
  def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end
69
69
  def #{new_name}=(v); self.#{old_name} = v; end # def subject=(v); self.title = v; end
@@ -21,7 +21,7 @@ class Module
21
21
  def attr_accessor_with_default(sym, default = nil, &block)
22
22
  raise 'Default value or block required' unless !default.nil? || block
23
23
  define_method(sym, block_given? ? block : Proc.new { default })
24
- module_eval(<<-EVAL, __FILE__, __LINE__)
24
+ module_eval(<<-EVAL, __FILE__, __LINE__ + 1)
25
25
  def #{sym}=(value) # def age=(value)
26
26
  class << self; attr_reader :#{sym} end # class << self; attr_reader :age end
27
27
  @#{sym} = value # @age = value
@@ -14,42 +14,49 @@ require "active_support/core_ext/array"
14
14
  # AppConfiguration.google_api_key = "overriding the api key!"
15
15
  class Module
16
16
  def mattr_reader(*syms)
17
+ options = syms.extract_options!
17
18
  syms.each do |sym|
18
19
  next if sym.is_a?(Hash)
19
- class_eval(<<-EOS, __FILE__, __LINE__)
20
- unless defined? @@#{sym} # unless defined? @@pagination_options
21
- @@#{sym} = nil # @@pagination_options = nil
22
- end # end
23
- #
24
- def self.#{sym} # def self.pagination_options
25
- @@#{sym} # @@pagination_options
26
- end # end
27
- #
28
- def #{sym} # def pagination_options
29
- @@#{sym} # @@pagination_options
30
- end # end
20
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
21
+ unless defined? @@#{sym}
22
+ @@#{sym} = nil
23
+ end
24
+
25
+ def self.#{sym}
26
+ @@#{sym}
27
+ end
31
28
  EOS
29
+
30
+ unless options[:instance_reader] == false
31
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
32
+ def #{sym}
33
+ @@#{sym}
34
+ end
35
+ EOS
36
+ end
32
37
  end
33
38
  end
34
39
 
35
40
  def mattr_writer(*syms)
36
41
  options = syms.extract_options!
37
42
  syms.each do |sym|
38
- class_eval(<<-EOS, __FILE__, __LINE__)
39
- unless defined? @@#{sym} # unless defined? @@pagination_options
40
- @@#{sym} = nil # @@pagination_options = nil
41
- end # end
42
- #
43
- def self.#{sym}=(obj) # def self.pagination_options=(obj)
44
- @@#{sym} = obj # @@pagination_options = obj
45
- end # end
46
- #
47
- #{" #
48
- def #{sym}=(obj) # def pagination_options=(obj)
49
- @@#{sym} = obj # @@pagination_options = obj
50
- end # end
51
- " unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false
43
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
44
+ unless defined? @@#{sym}
45
+ @@#{sym} = nil
46
+ end
47
+
48
+ def self.#{sym}=(obj)
49
+ @@#{sym} = obj
50
+ end
52
51
  EOS
52
+
53
+ unless options[:instance_writer] == false
54
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
55
+ def #{sym}=(obj)
56
+ @@#{sym} = obj
57
+ end
58
+ EOS
59
+ end
53
60
  end
54
61
  end
55
62
 
@@ -25,7 +25,7 @@ class Module
25
25
  raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
26
26
  end
27
27
 
28
- module_eval(<<-EOS, __FILE__, __LINE__)
28
+ module_eval(<<-EOS, __FILE__, __LINE__ + 1)
29
29
  def #{aliased_method}_with_synchronization#{punctuation}(*args, &block) # def expire_with_synchronization(*args, &block)
30
30
  #{with}.synchronize do # @@lock.synchronize do
31
31
  #{aliased_method}_without_synchronization#{punctuation}(*args, &block) # expire_without_synchronization(*args, &block)
@@ -2,11 +2,11 @@ class Object
2
2
  # An object is blank if it's false, empty, or a whitespace string.
3
3
  # For example, "", " ", +nil+, [], and {} are blank.
4
4
  #
5
- # This simplifies
5
+ # This simplifies:
6
6
  #
7
7
  # if !address.nil? && !address.empty?
8
8
  #
9
- # to
9
+ # ...to:
10
10
  #
11
11
  # if !address.blank?
12
12
  def blank?
@@ -17,6 +17,24 @@ class Object
17
17
  def present?
18
18
  !blank?
19
19
  end
20
+
21
+ # Returns object if it's #present? otherwise returns nil.
22
+ # object.presence is equivalent to object.present? ? object : nil.
23
+ #
24
+ # This is handy for any representation of objects where blank is the same
25
+ # as not present at all. For example, this simplifies a common check for
26
+ # HTTP POST/query parameters:
27
+ #
28
+ # state = params[:state] if params[:state].present?
29
+ # country = params[:country] if params[:country].present?
30
+ # region = state || country || 'US'
31
+ #
32
+ # ...becomes:
33
+ #
34
+ # region = params[:state].presence || params[:country].presence || 'US'
35
+ def presence
36
+ self if present?
37
+ end
20
38
  end
21
39
 
22
40
  class NilClass #:nodoc:
@@ -104,18 +104,26 @@ module ActiveSupport #:nodoc:
104
104
  def to_s
105
105
  self
106
106
  end
107
+
108
+ def to_yaml(*args)
109
+ to_str.to_yaml(*args)
110
+ end
107
111
  end
108
112
  end
109
113
 
110
114
  class String
111
115
  alias_method :add_without_safety, :+
112
116
 
117
+ def as_str
118
+ self
119
+ end
120
+
113
121
  def html_safe
114
122
  ActiveSupport::SafeBuffer.new(self)
115
123
  end
116
124
 
117
125
  def html_safe?
118
- defined?(@_rails_html_safe) && @_rails_html_safe
126
+ defined?(@_rails_html_safe)
119
127
  end
120
128
 
121
129
  def html_safe!
@@ -137,7 +145,7 @@ class String
137
145
  def concat_with_safety(other_or_fixnum)
138
146
  result = concat_without_safety(other_or_fixnum)
139
147
  unless html_safe? && also_html_safe?(other_or_fixnum)
140
- @_rails_html_safe = false
148
+ remove_instance_variable(:@_rails_html_safe) if defined?(@_rails_html_safe)
141
149
  end
142
150
  result
143
151
  end
@@ -20,14 +20,12 @@ module ActiveSupport #:nodoc:
20
20
 
21
21
  # Does the string start with the specified +prefix+?
22
22
  def starts_with?(prefix)
23
- prefix = prefix.to_s
24
- self[0, prefix.length] == prefix
23
+ prefix.respond_to?(:to_str) && self[0, prefix.length] == prefix
25
24
  end
26
25
 
27
26
  # Does the string end with the specified +suffix+?
28
27
  def ends_with?(suffix)
29
- suffix = suffix.to_s
30
- self[-suffix.length, suffix.length] == suffix
28
+ suffix.respond_to?(:to_str) && self[-suffix.length, suffix.length] == suffix
31
29
  end
32
30
  end
33
31
  end
@@ -15,14 +15,18 @@ class Time
15
15
  alias_method :_original_load, :_load
16
16
  def _load(marshaled_time)
17
17
  time = _original_load(marshaled_time)
18
- utc = time.instance_variable_get('@marshal_with_utc_coercion')
19
- utc ? time.utc : time
18
+ time.instance_eval do
19
+ if defined?(@marshal_with_utc_coercion)
20
+ val = remove_instance_variable("@marshal_with_utc_coercion")
21
+ end
22
+ val ? utc : self
23
+ end
20
24
  end
21
25
  end
22
-
26
+
23
27
  alias_method :_original_dump, :_dump
24
28
  def _dump(*args)
25
- obj = self.frozen? ? self.dup : self
29
+ obj = dup
26
30
  obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
27
31
  obj._original_dump(*args)
28
32
  end