activesupport 2.1.0 → 2.1.1
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 +13 -1
- data/lib/active_support.rb +6 -0
- data/lib/active_support/cache.rb +3 -1
- data/lib/active_support/cache/compressed_mem_cache_store.rb +4 -4
- data/lib/active_support/core_ext/date/behavior.rb +26 -0
- data/lib/active_support/core_ext/date/calculations.rb +1 -1
- data/lib/active_support/core_ext/hash/except.rb +4 -3
- data/lib/active_support/core_ext/hash/slice.rb +3 -1
- data/lib/active_support/core_ext/module.rb +5 -0
- data/lib/active_support/core_ext/module/model_naming.rb +22 -0
- data/lib/active_support/core_ext/object/extending.rb +9 -8
- data/lib/active_support/core_ext/range/blockless_step.rb +2 -2
- data/lib/active_support/core_ext/rexml.rb +35 -0
- data/lib/active_support/core_ext/string/unicode.rb +11 -13
- data/lib/active_support/core_ext/time.rb +22 -1
- data/lib/active_support/dependencies.rb +393 -392
- data/lib/active_support/deprecation.rb +27 -9
- data/lib/active_support/inflections.rb +51 -49
- data/lib/active_support/inflector.rb +267 -262
- data/lib/active_support/json/encoders/date_time.rb +1 -1
- data/lib/active_support/ordered_options.rb +14 -12
- data/lib/active_support/string_inquirer.rb +11 -0
- data/lib/active_support/time_with_zone.rb +34 -13
- data/lib/active_support/values/time_zone.rb +348 -346
- data/lib/active_support/vendor.rb +2 -2
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/data_timezone.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/data_timezone_info.rb +2 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Algiers.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Cairo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Casablanca.rb +2 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Harare.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Johannesburg.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Monrovia.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Nairobi.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Bogota.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Caracas.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Chicago.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Chihuahua.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Denver.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Godthab.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Guatemala.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Halifax.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Juneau.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/La_Paz.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Lima.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Los_Angeles.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Mazatlan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Mexico_City.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Monterrey.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/New_York.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Phoenix.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Regina.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Santiago.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/St_Johns.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Tijuana.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Almaty.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Baghdad.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Baku.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Bangkok.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Chongqing.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Dhaka.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Hong_Kong.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Irkutsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Jakarta.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Jerusalem.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kabul.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kamchatka.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Karachi.rb +2 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Katmandu.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kolkata.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kuwait.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Magadan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Muscat.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Novosibirsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Rangoon.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Riyadh.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Seoul.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Shanghai.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Singapore.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Taipei.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tashkent.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tbilisi.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tehran.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tokyo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Urumqi.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Vladivostok.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Yakutsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Yerevan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Atlantic/Azores.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Adelaide.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Brisbane.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Darwin.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Hobart.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Melbourne.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Perth.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Sydney.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Etc/UTC.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Amsterdam.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Athens.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Belgrade.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Berlin.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Bratislava.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Brussels.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Bucharest.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Budapest.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Copenhagen.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Dublin.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Helsinki.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Istanbul.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Kiev.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Lisbon.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Ljubljana.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/London.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Madrid.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Minsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Moscow.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Paris.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Prague.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Riga.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Rome.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Sarajevo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Skopje.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Sofia.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Stockholm.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Tallinn.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Vienna.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Vilnius.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Warsaw.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Zagreb.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Auckland.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Fiji.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Guam.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Honolulu.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Majuro.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Midway.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Noumea.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Tongatapu.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/info_timezone.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/linked_timezone.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/linked_timezone_info.rb +0 -0
- data/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/offset_rationals.rb +95 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/time_or_datetime.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone.rb +6 -6
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_definition.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_info.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_offset_info.rb +4 -4
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_period.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_transition_info.rb +2 -2
- data/lib/active_support/version.rb +1 -1
- metadata +154 -151
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/offset_rationals.rb +0 -95
@@ -92,7 +92,7 @@ module ActiveSupport
|
|
92
92
|
class_eval(<<-EOS, __FILE__, __LINE__)
|
93
93
|
def #{target}_with_deprecation#{punctuation}(*args, &block)
|
94
94
|
::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), caller)
|
95
|
-
|
95
|
+
send(:#{target}_without_deprecation#{punctuation}, *args, &block)
|
96
96
|
end
|
97
97
|
EOS
|
98
98
|
end
|
@@ -109,7 +109,7 @@ module ActiveSupport
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def deprecation_horizon
|
112
|
-
'2.
|
112
|
+
'2.2'
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -144,17 +144,11 @@ module ActiveSupport
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
|
148
|
-
# which emits deprecation warnings on any method call (except +inspect+).
|
149
|
-
class DeprecatedInstanceVariableProxy #:nodoc:
|
147
|
+
class DeprecationProxy #:nodoc:
|
150
148
|
silence_warnings do
|
151
149
|
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
|
152
150
|
end
|
153
151
|
|
154
|
-
def initialize(instance, method, var = "@#{method}")
|
155
|
-
@instance, @method, @var = instance, method, var
|
156
|
-
end
|
157
|
-
|
158
152
|
# Don't give a deprecation warning on inspect since test/unit and error
|
159
153
|
# logs rely on it for diagnostics.
|
160
154
|
def inspect
|
@@ -166,7 +160,16 @@ module ActiveSupport
|
|
166
160
|
warn caller, called, args
|
167
161
|
target.__send__(called, *args, &block)
|
168
162
|
end
|
163
|
+
end
|
169
164
|
|
165
|
+
# Stand-in for <tt>@request</tt>, <tt>@attributes</tt>, <tt>@params</tt>, etc.
|
166
|
+
# which emits deprecation warnings on any method call (except +inspect+).
|
167
|
+
class DeprecatedInstanceVariableProxy < DeprecationProxy #:nodoc:
|
168
|
+
def initialize(instance, method, var = "@#{method}")
|
169
|
+
@instance, @method, @var = instance, method, var
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
170
173
|
def target
|
171
174
|
@instance.__send__(@method)
|
172
175
|
end
|
@@ -176,6 +179,21 @@ module ActiveSupport
|
|
176
179
|
end
|
177
180
|
end
|
178
181
|
|
182
|
+
class DeprecatedConstantProxy < DeprecationProxy #:nodoc:
|
183
|
+
def initialize(old_const, new_const)
|
184
|
+
@old_const = old_const
|
185
|
+
@new_const = new_const
|
186
|
+
end
|
187
|
+
|
188
|
+
private
|
189
|
+
def target
|
190
|
+
@new_const.to_s.constantize
|
191
|
+
end
|
192
|
+
|
193
|
+
def warn(callstack, called, args)
|
194
|
+
ActiveSupport::Deprecation.warn("#{@old_const} is deprecated! Use #{@new_const} instead.", callstack)
|
195
|
+
end
|
196
|
+
end
|
179
197
|
end
|
180
198
|
end
|
181
199
|
|
@@ -1,53 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
module ActiveSupport
|
2
|
+
Inflector.inflections do |inflect|
|
3
|
+
inflect.plural(/$/, 's')
|
4
|
+
inflect.plural(/s$/i, 's')
|
5
|
+
inflect.plural(/(ax|test)is$/i, '\1es')
|
6
|
+
inflect.plural(/(octop|vir)us$/i, '\1i')
|
7
|
+
inflect.plural(/(alias|status)$/i, '\1es')
|
8
|
+
inflect.plural(/(bu)s$/i, '\1ses')
|
9
|
+
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
|
10
|
+
inflect.plural(/([ti])um$/i, '\1a')
|
11
|
+
inflect.plural(/sis$/i, 'ses')
|
12
|
+
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
|
13
|
+
inflect.plural(/(hive)$/i, '\1s')
|
14
|
+
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
|
15
|
+
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
|
16
|
+
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
|
17
|
+
inflect.plural(/([m|l])ouse$/i, '\1ice')
|
18
|
+
inflect.plural(/^(ox)$/i, '\1en')
|
19
|
+
inflect.plural(/(quiz)$/i, '\1zes')
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
21
|
+
inflect.singular(/s$/i, '')
|
22
|
+
inflect.singular(/(n)ews$/i, '\1ews')
|
23
|
+
inflect.singular(/([ti])a$/i, '\1um')
|
24
|
+
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
|
25
|
+
inflect.singular(/(^analy)ses$/i, '\1sis')
|
26
|
+
inflect.singular(/([^f])ves$/i, '\1fe')
|
27
|
+
inflect.singular(/(hive)s$/i, '\1')
|
28
|
+
inflect.singular(/(tive)s$/i, '\1')
|
29
|
+
inflect.singular(/([lr])ves$/i, '\1f')
|
30
|
+
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
|
31
|
+
inflect.singular(/(s)eries$/i, '\1eries')
|
32
|
+
inflect.singular(/(m)ovies$/i, '\1ovie')
|
33
|
+
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
|
34
|
+
inflect.singular(/([m|l])ice$/i, '\1ouse')
|
35
|
+
inflect.singular(/(bus)es$/i, '\1')
|
36
|
+
inflect.singular(/(o)es$/i, '\1')
|
37
|
+
inflect.singular(/(shoe)s$/i, '\1')
|
38
|
+
inflect.singular(/(cris|ax|test)es$/i, '\1is')
|
39
|
+
inflect.singular(/(octop|vir)i$/i, '\1us')
|
40
|
+
inflect.singular(/(alias|status)es$/i, '\1')
|
41
|
+
inflect.singular(/^(ox)en/i, '\1')
|
42
|
+
inflect.singular(/(vert|ind)ices$/i, '\1ex')
|
43
|
+
inflect.singular(/(matr)ices$/i, '\1ix')
|
44
|
+
inflect.singular(/(quiz)zes$/i, '\1')
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
inflect.irregular('person', 'people')
|
47
|
+
inflect.irregular('man', 'men')
|
48
|
+
inflect.irregular('child', 'children')
|
49
|
+
inflect.irregular('sex', 'sexes')
|
50
|
+
inflect.irregular('move', 'moves')
|
51
|
+
inflect.irregular('cow', 'kine')
|
51
52
|
|
52
|
-
|
53
|
+
inflect.uncountable(%w(equipment information rice money species series fish sheep))
|
54
|
+
end
|
53
55
|
end
|
@@ -1,305 +1,310 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# The Rails core team has stated patches for the inflections library will not be accepted
|
8
|
-
# in order to avoid breaking legacy applications which may be relying on errant inflections.
|
9
|
-
# If you discover an incorrect inflection and require it for your application, you'll need
|
10
|
-
# to correct it yourself (explained below).
|
11
|
-
module Inflector
|
12
|
-
# A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
|
13
|
-
# inflection rules. Examples:
|
3
|
+
module ActiveSupport
|
4
|
+
# The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
|
5
|
+
# and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
|
6
|
+
# in inflections.rb.
|
14
7
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
# The Rails core team has stated patches for the inflections library will not be accepted
|
9
|
+
# in order to avoid breaking legacy applications which may be relying on errant inflections.
|
10
|
+
# If you discover an incorrect inflection and require it for your application, you'll need
|
11
|
+
# to correct it yourself (explained below).
|
12
|
+
module Inflector
|
13
|
+
# A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
|
14
|
+
# inflection rules. Examples:
|
15
|
+
#
|
16
|
+
# Inflector.inflections do |inflect|
|
17
|
+
# inflect.plural /^(ox)$/i, '\1\2en'
|
18
|
+
# inflect.singular /^(ox)en/i, '\1'
|
19
|
+
#
|
20
|
+
# inflect.irregular 'octopus', 'octopi'
|
21
|
+
#
|
22
|
+
# inflect.uncountable "equipment"
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
|
26
|
+
# pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
|
27
|
+
# already have been loaded.
|
28
|
+
class Inflections
|
29
|
+
include Singleton
|
29
30
|
|
30
|
-
|
31
|
+
attr_reader :plurals, :singulars, :uncountables
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def initialize
|
34
|
+
@plurals, @singulars, @uncountables = [], [], []
|
35
|
+
end
|
36
|
+
|
37
|
+
# Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
|
38
|
+
# The replacement should always be a string that may include references to the matched data from the rule.
|
39
|
+
def plural(rule, replacement)
|
40
|
+
@plurals.insert(0, [rule, replacement])
|
41
|
+
end
|
42
|
+
|
43
|
+
# Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
|
44
|
+
# The replacement should always be a string that may include references to the matched data from the rule.
|
45
|
+
def singular(rule, replacement)
|
46
|
+
@singulars.insert(0, [rule, replacement])
|
47
|
+
end
|
35
48
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
49
|
+
# Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
|
50
|
+
# for strings, not regular expressions. You simply pass the irregular in singular and plural form.
|
51
|
+
#
|
52
|
+
# Examples:
|
53
|
+
# irregular 'octopus', 'octopi'
|
54
|
+
# irregular 'person', 'people'
|
55
|
+
def irregular(singular, plural)
|
56
|
+
if singular[0,1].upcase == plural[0,1].upcase
|
57
|
+
plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
|
58
|
+
singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
|
59
|
+
else
|
60
|
+
plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
|
61
|
+
plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
|
62
|
+
singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
|
63
|
+
singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Add uncountable words that shouldn't be attempted inflected.
|
68
|
+
#
|
69
|
+
# Examples:
|
70
|
+
# uncountable "money"
|
71
|
+
# uncountable "money", "information"
|
72
|
+
# uncountable %w( money information rice )
|
73
|
+
def uncountable(*words)
|
74
|
+
(@uncountables << words).flatten!
|
75
|
+
end
|
76
|
+
|
77
|
+
# Clears the loaded inflections within a given scope (default is <tt>:all</tt>).
|
78
|
+
# Give the scope as a symbol of the inflection type, the options are: <tt>:plurals</tt>,
|
79
|
+
# <tt>:singulars</tt>, <tt>:uncountables</tt>.
|
80
|
+
#
|
81
|
+
# Examples:
|
82
|
+
# clear :all
|
83
|
+
# clear :plurals
|
84
|
+
def clear(scope = :all)
|
85
|
+
case scope
|
86
|
+
when :all
|
87
|
+
@plurals, @singulars, @uncountables = [], [], []
|
88
|
+
else
|
89
|
+
instance_variable_set "@#{scope}", []
|
90
|
+
end
|
91
|
+
end
|
40
92
|
end
|
41
93
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
94
|
+
extend self
|
95
|
+
|
96
|
+
# Yields a singleton instance of Inflector::Inflections so you can specify additional
|
97
|
+
# inflector rules.
|
98
|
+
#
|
99
|
+
# Example:
|
100
|
+
# Inflector.inflections do |inflect|
|
101
|
+
# inflect.uncountable "rails"
|
102
|
+
# end
|
103
|
+
def inflections
|
104
|
+
if block_given?
|
105
|
+
yield Inflections.instance
|
106
|
+
else
|
107
|
+
Inflections.instance
|
108
|
+
end
|
46
109
|
end
|
47
110
|
|
48
|
-
#
|
49
|
-
# for strings, not regular expressions. You simply pass the irregular in singular and plural form.
|
111
|
+
# Returns the plural form of the word in the string.
|
50
112
|
#
|
51
113
|
# Examples:
|
52
|
-
#
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
114
|
+
# "post".pluralize # => "posts"
|
115
|
+
# "octopus".pluralize # => "octopi"
|
116
|
+
# "sheep".pluralize # => "sheep"
|
117
|
+
# "words".pluralize # => "words"
|
118
|
+
# "the blue mailman".pluralize # => "the blue mailmen"
|
119
|
+
# "CamelOctopus".pluralize # => "CamelOctopi"
|
120
|
+
def pluralize(word)
|
121
|
+
result = word.to_s.dup
|
122
|
+
|
123
|
+
if word.empty? || inflections.uncountables.include?(result.downcase)
|
124
|
+
result
|
58
125
|
else
|
59
|
-
|
60
|
-
|
61
|
-
singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
|
62
|
-
singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
|
126
|
+
inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
|
127
|
+
result
|
63
128
|
end
|
64
129
|
end
|
65
130
|
|
66
|
-
#
|
131
|
+
# The reverse of +pluralize+, returns the singular form of a word in a string.
|
67
132
|
#
|
68
133
|
# Examples:
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
134
|
+
# "posts".singularize # => "post"
|
135
|
+
# "octopi".singularize # => "octopus"
|
136
|
+
# "sheep".singluarize # => "sheep"
|
137
|
+
# "word".singluarize # => "word"
|
138
|
+
# "the blue mailmen".singularize # => "the blue mailman"
|
139
|
+
# "CamelOctopi".singularize # => "CamelOctopus"
|
140
|
+
def singularize(word)
|
141
|
+
result = word.to_s.dup
|
142
|
+
|
143
|
+
if inflections.uncountables.include?(result.downcase)
|
144
|
+
result
|
145
|
+
else
|
146
|
+
inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
|
147
|
+
result
|
148
|
+
end
|
74
149
|
end
|
75
150
|
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
151
|
+
# By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
|
152
|
+
# is set to <tt>:lower</tt> then +camelize+ produces lowerCamelCase.
|
153
|
+
#
|
154
|
+
# +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
|
79
155
|
#
|
80
156
|
# Examples:
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
157
|
+
# "active_record".camelize # => "ActiveRecord"
|
158
|
+
# "active_record".camelize(:lower) # => "activeRecord"
|
159
|
+
# "active_record/errors".camelize # => "ActiveRecord::Errors"
|
160
|
+
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
161
|
+
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
162
|
+
if first_letter_in_uppercase
|
163
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
164
|
+
else
|
165
|
+
lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
|
89
166
|
end
|
90
167
|
end
|
91
|
-
end
|
92
|
-
|
93
|
-
extend self
|
94
168
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
Inflections.instance
|
169
|
+
# Capitalizes all the words and replaces some characters in the string to create
|
170
|
+
# a nicer looking title. +titleize+ is meant for creating pretty output. It is not
|
171
|
+
# used in the Rails internals.
|
172
|
+
#
|
173
|
+
# +titleize+ is also aliased as as +titlecase+.
|
174
|
+
#
|
175
|
+
# Examples:
|
176
|
+
# "man from the boondocks".titleize # => "Man From The Boondocks"
|
177
|
+
# "x-men: the last stand".titleize # => "X Men: The Last Stand"
|
178
|
+
def titleize(word)
|
179
|
+
humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
|
107
180
|
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# Returns the plural form of the word in the string.
|
111
|
-
#
|
112
|
-
# Examples:
|
113
|
-
# "post".pluralize # => "posts"
|
114
|
-
# "octopus".pluralize # => "octopi"
|
115
|
-
# "sheep".pluralize # => "sheep"
|
116
|
-
# "words".pluralize # => "words"
|
117
|
-
# "the blue mailman".pluralize # => "the blue mailmen"
|
118
|
-
# "CamelOctopus".pluralize # => "CamelOctopi"
|
119
|
-
def pluralize(word)
|
120
|
-
result = word.to_s.dup
|
121
181
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
182
|
+
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
183
|
+
#
|
184
|
+
# Changes '::' to '/' to convert namespaces to paths.
|
185
|
+
#
|
186
|
+
# Examples:
|
187
|
+
# "ActiveRecord".underscore # => "active_record"
|
188
|
+
# "ActiveRecord::Errors".underscore # => active_record/errors
|
189
|
+
def underscore(camel_cased_word)
|
190
|
+
camel_cased_word.to_s.gsub(/::/, '/').
|
191
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
192
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
193
|
+
tr("-", "_").
|
194
|
+
downcase
|
127
195
|
end
|
128
|
-
end
|
129
|
-
|
130
|
-
# The reverse of +pluralize+, returns the singular form of a word in a string.
|
131
|
-
#
|
132
|
-
# Examples:
|
133
|
-
# "posts".singularize # => "post"
|
134
|
-
# "octopi".singularize # => "octopus"
|
135
|
-
# "sheep".singluarize # => "sheep"
|
136
|
-
# "word".singluarize # => "word"
|
137
|
-
# "the blue mailmen".singularize # => "the blue mailman"
|
138
|
-
# "CamelOctopi".singularize # => "CamelOctopus"
|
139
|
-
def singularize(word)
|
140
|
-
result = word.to_s.dup
|
141
196
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
197
|
+
# Replaces underscores with dashes in the string.
|
198
|
+
#
|
199
|
+
# Example:
|
200
|
+
# "puni_puni" # => "puni-puni"
|
201
|
+
def dasherize(underscored_word)
|
202
|
+
underscored_word.gsub(/_/, '-')
|
147
203
|
end
|
148
|
-
end
|
149
204
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
# "active_record/errors".camelize # => "ActiveRecord::Errors"
|
159
|
-
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
160
|
-
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
161
|
-
if first_letter_in_uppercase
|
162
|
-
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
163
|
-
else
|
164
|
-
lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
|
205
|
+
# Capitalizes the first word and turns underscores into spaces and strips a
|
206
|
+
# trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
|
207
|
+
#
|
208
|
+
# Examples:
|
209
|
+
# "employee_salary" # => "Employee salary"
|
210
|
+
# "author_id" # => "Author"
|
211
|
+
def humanize(lower_case_and_underscored_word)
|
212
|
+
lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
|
165
213
|
end
|
166
|
-
end
|
167
214
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
# "x-men: the last stand".titleize # => "X Men: The Last Stand"
|
177
|
-
def titleize(word)
|
178
|
-
humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
|
179
|
-
end
|
180
|
-
|
181
|
-
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
182
|
-
#
|
183
|
-
# Changes '::' to '/' to convert namespaces to paths.
|
184
|
-
#
|
185
|
-
# Examples:
|
186
|
-
# "ActiveRecord".underscore # => "active_record"
|
187
|
-
# "ActiveRecord::Errors".underscore # => active_record/errors
|
188
|
-
def underscore(camel_cased_word)
|
189
|
-
camel_cased_word.to_s.gsub(/::/, '/').
|
190
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
191
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
192
|
-
tr("-", "_").
|
193
|
-
downcase
|
194
|
-
end
|
195
|
-
|
196
|
-
# Replaces underscores with dashes in the string.
|
197
|
-
#
|
198
|
-
# Example:
|
199
|
-
# "puni_puni" # => "puni-puni"
|
200
|
-
def dasherize(underscored_word)
|
201
|
-
underscored_word.gsub(/_/, '-')
|
202
|
-
end
|
203
|
-
|
204
|
-
# Capitalizes the first word and turns underscores into spaces and strips a
|
205
|
-
# trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
|
206
|
-
#
|
207
|
-
# Examples:
|
208
|
-
# "employee_salary" # => "Employee salary"
|
209
|
-
# "author_id" # => "Author"
|
210
|
-
def humanize(lower_case_and_underscored_word)
|
211
|
-
lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
|
212
|
-
end
|
215
|
+
# Removes the module part from the expression in the string.
|
216
|
+
#
|
217
|
+
# Examples:
|
218
|
+
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
|
219
|
+
# "Inflections".demodulize # => "Inflections"
|
220
|
+
def demodulize(class_name_in_module)
|
221
|
+
class_name_in_module.to_s.gsub(/^.*::/, '')
|
222
|
+
end
|
213
223
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
224
|
+
# Create the name of a table like Rails does for models to table names. This method
|
225
|
+
# uses the +pluralize+ method on the last word in the string.
|
226
|
+
#
|
227
|
+
# Examples
|
228
|
+
# "RawScaledScorer".tableize # => "raw_scaled_scorers"
|
229
|
+
# "egg_and_ham".tableize # => "egg_and_hams"
|
230
|
+
# "fancyCategory".tableize # => "fancy_categories"
|
231
|
+
def tableize(class_name)
|
232
|
+
pluralize(underscore(class_name))
|
233
|
+
end
|
222
234
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
235
|
+
# Create a class name from a plural table name like Rails does for table names to models.
|
236
|
+
# Note that this returns a string and not a Class. (To convert to an actual class
|
237
|
+
# follow +classify+ with +constantize+.)
|
238
|
+
#
|
239
|
+
# Examples:
|
240
|
+
# "egg_and_hams".classify # => "EggAndHam"
|
241
|
+
# "posts".classify # => "Post"
|
242
|
+
#
|
243
|
+
# Singular names are not handled correctly:
|
244
|
+
# "business".classify # => "Busines"
|
245
|
+
def classify(table_name)
|
246
|
+
# strip out any leading schema name
|
247
|
+
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
|
248
|
+
end
|
233
249
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
# strip out any leading schema name
|
246
|
-
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
|
247
|
-
end
|
250
|
+
# Creates a foreign key name from a class name.
|
251
|
+
# +separate_class_name_and_id_with_underscore+ sets whether
|
252
|
+
# the method should put '_' between the name and 'id'.
|
253
|
+
#
|
254
|
+
# Examples:
|
255
|
+
# "Message".foreign_key # => "message_id"
|
256
|
+
# "Message".foreign_key(false) # => "messageid"
|
257
|
+
# "Admin::Post".foreign_key # => "post_id"
|
258
|
+
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
|
259
|
+
underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
|
260
|
+
end
|
248
261
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
262
|
+
# Tries to find a constant with the name specified in the argument string:
|
263
|
+
#
|
264
|
+
# "Module".constantize # => Module
|
265
|
+
# "Test::Unit".constantize # => Test::Unit
|
266
|
+
#
|
267
|
+
# The name is assumed to be the one of a top-level constant, no matter whether
|
268
|
+
# it starts with "::" or not. No lexical context is taken into account:
|
269
|
+
#
|
270
|
+
# C = 'outside'
|
271
|
+
# module M
|
272
|
+
# C = 'inside'
|
273
|
+
# C # => 'inside'
|
274
|
+
# "C".constantize # => 'outside', same as ::C
|
275
|
+
# end
|
276
|
+
#
|
277
|
+
# NameError is raised when the name is not in CamelCase or the constant is
|
278
|
+
# unknown.
|
279
|
+
def constantize(camel_cased_word)
|
280
|
+
names = camel_cased_word.split('::')
|
281
|
+
names.shift if names.empty? || names.first.empty?
|
260
282
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
# The name is assumed to be the one of a top-level constant, no matter whether
|
267
|
-
# it starts with "::" or not. No lexical context is taken into account:
|
268
|
-
#
|
269
|
-
# C = 'outside'
|
270
|
-
# module M
|
271
|
-
# C = 'inside'
|
272
|
-
# C # => 'inside'
|
273
|
-
# "C".constantize # => 'outside', same as ::C
|
274
|
-
# end
|
275
|
-
#
|
276
|
-
# NameError is raised when the name is not in CamelCase or the constant is
|
277
|
-
# unknown.
|
278
|
-
def constantize(camel_cased_word)
|
279
|
-
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
|
280
|
-
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
|
283
|
+
constant = Object
|
284
|
+
names.each do |name|
|
285
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
286
|
+
end
|
287
|
+
constant
|
281
288
|
end
|
282
289
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
#
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
when 3; "#{number}rd"
|
302
|
-
else "#{number}th"
|
290
|
+
# Turns a number into an ordinal string used to denote the position in an
|
291
|
+
# ordered sequence such as 1st, 2nd, 3rd, 4th.
|
292
|
+
#
|
293
|
+
# Examples:
|
294
|
+
# ordinalize(1) # => "1st"
|
295
|
+
# ordinalize(2) # => "2nd"
|
296
|
+
# ordinalize(1002) # => "1002nd"
|
297
|
+
# ordinalize(1003) # => "1003rd"
|
298
|
+
def ordinalize(number)
|
299
|
+
if (11..13).include?(number.to_i % 100)
|
300
|
+
"#{number}th"
|
301
|
+
else
|
302
|
+
case number.to_i % 10
|
303
|
+
when 1; "#{number}st"
|
304
|
+
when 2; "#{number}nd"
|
305
|
+
when 3; "#{number}rd"
|
306
|
+
else "#{number}th"
|
307
|
+
end
|
303
308
|
end
|
304
309
|
end
|
305
310
|
end
|