swivel 0.0.146 → 0.0.149

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. data/README +4 -1
  2. data/Rakefile +1 -1
  3. data/lib/swivel.rb +1 -1
  4. data/lib/swivel2/benchmarking.rb +1 -0
  5. data/lib/swivel2/config.rb +45 -0
  6. data/lib/swivel2/connection.rb +89 -0
  7. data/lib/swivel2/formats.rb +11 -0
  8. data/lib/swivel2/logging.rb +1 -0
  9. data/lib/swivel2/performance.rb +21 -0
  10. data/lib/swivel2/response.rb +5 -0
  11. data/lib/swivel2/swivelrc.default +5 -0
  12. data/vendor/activeresource-2.0.2-/CHANGELOG +223 -0
  13. data/vendor/activeresource-2.0.2-/README +165 -0
  14. data/vendor/activeresource-2.0.2-/Rakefile +133 -0
  15. data/vendor/activeresource-2.0.2-/lib/active_resource.rb +47 -0
  16. data/vendor/activeresource-2.0.2-/lib/active_resource/base.rb +872 -0
  17. data/vendor/activeresource-2.0.2-/lib/active_resource/connection.rb +172 -0
  18. data/vendor/activeresource-2.0.2-/lib/active_resource/custom_methods.rb +105 -0
  19. data/vendor/activeresource-2.0.2-/lib/active_resource/formats.rb +14 -0
  20. data/vendor/activeresource-2.0.2-/lib/active_resource/formats/json_format.rb +23 -0
  21. data/vendor/activeresource-2.0.2-/lib/active_resource/formats/xml_format.rb +34 -0
  22. data/vendor/activeresource-2.0.2-/lib/active_resource/http_mock.rb +147 -0
  23. data/vendor/activeresource-2.0.2-/lib/active_resource/validations.rb +288 -0
  24. data/vendor/activeresource-2.0.2-/lib/active_resource/version.rb +9 -0
  25. data/vendor/activeresource-2.0.2-/lib/activeresource.rb +1 -0
  26. data/vendor/activeresource-2.0.2-/test/abstract_unit.rb +10 -0
  27. data/vendor/activeresource-2.0.2-/test/authorization_test.rb +82 -0
  28. data/vendor/activeresource-2.0.2-/test/base/custom_methods_test.rb +96 -0
  29. data/vendor/activeresource-2.0.2-/test/base/equality_test.rb +43 -0
  30. data/vendor/activeresource-2.0.2-/test/base/load_test.rb +111 -0
  31. data/vendor/activeresource-2.0.2-/test/base_errors_test.rb +48 -0
  32. data/vendor/activeresource-2.0.2-/test/base_test.rb +454 -0
  33. data/vendor/activeresource-2.0.2-/test/connection_test.rb +170 -0
  34. data/vendor/activeresource-2.0.2-/test/fixtures/beast.rb +14 -0
  35. data/vendor/activeresource-2.0.2-/test/fixtures/person.rb +3 -0
  36. data/vendor/activeresource-2.0.2-/test/fixtures/street_address.rb +4 -0
  37. data/vendor/activeresource-2.0.2-/test/format_test.rb +42 -0
  38. data/vendor/activeresource-2.0.2-/test/setter_trap.rb +27 -0
  39. data/vendor/activesupport-2.0.2-/CHANGELOG +986 -0
  40. data/vendor/activesupport-2.0.2-/README +43 -0
  41. data/vendor/activesupport-2.0.2-/lib/active_support.rb +49 -0
  42. data/vendor/activesupport-2.0.2-/lib/active_support/basic_object.rb +5 -0
  43. data/vendor/activesupport-2.0.2-/lib/active_support/buffered_logger.rb +107 -0
  44. data/vendor/activesupport-2.0.2-/lib/active_support/clean_logger.rb +127 -0
  45. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext.rb +4 -0
  46. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array.rb +13 -0
  47. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/access.rb +28 -0
  48. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/conversions.rb +94 -0
  49. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/extract_options.rb +19 -0
  50. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/grouping.rb +68 -0
  51. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/random_access.rb +12 -0
  52. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal.rb +2 -0
  53. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal/conversions.rb +6 -0
  54. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/blank.rb +50 -0
  55. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi.rb +5 -0
  56. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
  57. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class.rb +4 -0
  58. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/attribute_accessors.rb +48 -0
  59. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/delegating_attributes.rb +40 -0
  60. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
  61. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/removal.rb +24 -0
  62. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date.rb +10 -0
  63. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/behavior.rb +13 -0
  64. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/calculations.rb +188 -0
  65. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/conversions.rb +98 -0
  66. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time.rb +10 -0
  67. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/calculations.rb +77 -0
  68. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/conversions.rb +74 -0
  69. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/duplicable.rb +37 -0
  70. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/enumerable.rb +63 -0
  71. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/exception.rb +33 -0
  72. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/file.rb +21 -0
  73. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float.rb +5 -0
  74. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float/rounding.rb +24 -0
  75. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash.rb +13 -0
  76. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/conversions.rb +242 -0
  77. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/diff.rb +19 -0
  78. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/except.rb +24 -0
  79. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/indifferent_access.rb +102 -0
  80. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/keys.rb +54 -0
  81. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
  82. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/slice.rb +28 -0
  83. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer.rb +7 -0
  84. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/even_odd.rb +24 -0
  85. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/inflections.rb +21 -0
  86. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel.rb +5 -0
  87. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
  88. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/daemonizing.rb +15 -0
  89. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/debugger.rb +13 -0
  90. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/reporting.rb +51 -0
  91. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/requires.rb +24 -0
  92. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/load_error.rb +38 -0
  93. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/logger.rb +16 -0
  94. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module.rb +8 -0
  95. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/aliasing.rb +70 -0
  96. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
  97. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_internal.rb +31 -0
  98. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attribute_accessors.rb +48 -0
  99. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/delegation.rb +62 -0
  100. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/inclusion.rb +11 -0
  101. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/introspection.rb +35 -0
  102. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/loading.rb +13 -0
  103. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/name_error.rb +17 -0
  104. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric.rb +7 -0
  105. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/bytes.rb +44 -0
  106. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/time.rb +91 -0
  107. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object.rb +4 -0
  108. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/conversions.rb +14 -0
  109. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/extending.rb +58 -0
  110. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/instance_variables.rb +22 -0
  111. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/misc.rb +59 -0
  112. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname.rb +7 -0
  113. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
  114. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/proc.rb +12 -0
  115. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range.rb +11 -0
  116. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/blockless_step.rb +22 -0
  117. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/conversions.rb +23 -0
  118. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/include_range.rb +22 -0
  119. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/overlaps.rb +12 -0
  120. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string.rb +23 -0
  121. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/access.rb +58 -0
  122. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/conversions.rb +28 -0
  123. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/inflections.rb +153 -0
  124. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/iterators.rb +17 -0
  125. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/starts_ends_with.rb +27 -0
  126. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/unicode.rb +42 -0
  127. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/xchar.rb +11 -0
  128. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/symbol.rb +14 -0
  129. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test.rb +1 -0
  130. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test/unit/assertions.rb +62 -0
  131. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time.rb +19 -0
  132. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/behavior.rb +13 -0
  133. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/calculations.rb +224 -0
  134. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/conversions.rb +94 -0
  135. data/vendor/activesupport-2.0.2-/lib/active_support/dependencies.rb +540 -0
  136. data/vendor/activesupport-2.0.2-/lib/active_support/deprecation.rb +204 -0
  137. data/vendor/activesupport-2.0.2-/lib/active_support/duration.rb +96 -0
  138. data/vendor/activesupport-2.0.2-/lib/active_support/inflections.rb +53 -0
  139. data/vendor/activesupport-2.0.2-/lib/active_support/inflector.rb +282 -0
  140. data/vendor/activesupport-2.0.2-/lib/active_support/json.rb +31 -0
  141. data/vendor/activesupport-2.0.2-/lib/active_support/json/decoding.rb +60 -0
  142. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date.rb +5 -0
  143. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date_time.rb +5 -0
  144. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/enumerable.rb +12 -0
  145. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/false_class.rb +5 -0
  146. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/hash.rb +50 -0
  147. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/nil_class.rb +5 -0
  148. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/numeric.rb +5 -0
  149. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/object.rb +6 -0
  150. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/regexp.rb +5 -0
  151. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/string.rb +30 -0
  152. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/symbol.rb +5 -0
  153. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/time.rb +5 -0
  154. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/true_class.rb +5 -0
  155. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoding.rb +38 -0
  156. data/vendor/activesupport-2.0.2-/lib/active_support/json/variable.rb +10 -0
  157. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte.rb +9 -0
  158. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/chars.rb +141 -0
  159. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/generators/generate_tables.rb +149 -0
  160. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/passthru_handler.rb +9 -0
  161. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler.rb +564 -0
  162. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler_proc.rb +43 -0
  163. data/vendor/activesupport-2.0.2-/lib/active_support/option_merger.rb +25 -0
  164. data/vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb +49 -0
  165. data/vendor/activesupport-2.0.2-/lib/active_support/test_case.rb +5 -0
  166. data/vendor/activesupport-2.0.2-/lib/active_support/testing.rb +1 -0
  167. data/vendor/activesupport-2.0.2-/lib/active_support/testing/default.rb +12 -0
  168. data/vendor/activesupport-2.0.2-/lib/active_support/values/time_zone.rb +181 -0
  169. data/vendor/activesupport-2.0.2-/lib/active_support/values/unicode_tables.dat +0 -0
  170. data/vendor/activesupport-2.0.2-/lib/active_support/vendor.rb +14 -0
  171. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
  172. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
  173. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
  174. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
  175. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
  176. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
  177. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
  178. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
  179. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
  180. data/vendor/activesupport-2.0.2-/lib/active_support/version.rb +9 -0
  181. data/vendor/activesupport-2.0.2-/lib/active_support/whiny_nil.rb +38 -0
  182. data/vendor/activesupport-2.0.2-/lib/activesupport.rb +1 -0
  183. metadata +222 -2
@@ -0,0 +1,204 @@
1
+ require 'yaml'
2
+
3
+ module ActiveSupport
4
+ module Deprecation #:nodoc:
5
+ mattr_accessor :debug
6
+ self.debug = false
7
+
8
+ # Choose the default warn behavior according to RAILS_ENV.
9
+ # Ignore deprecation warnings in production.
10
+ DEFAULT_BEHAVIORS = {
11
+ 'test' => Proc.new { |message, callstack|
12
+ $stderr.puts(message)
13
+ $stderr.puts callstack.join("\n ") if debug
14
+ },
15
+ 'development' => Proc.new { |message, callstack|
16
+ logger = defined?(::RAILS_DEFAULT_LOGGER) ? ::RAILS_DEFAULT_LOGGER : Logger.new($stderr)
17
+ logger.warn message
18
+ logger.debug callstack.join("\n ") if debug
19
+ }
20
+ }
21
+
22
+ class << self
23
+ def warn(message = nil, callstack = caller)
24
+ behavior.call(deprecation_message(callstack, message), callstack) if behavior && !silenced?
25
+ end
26
+
27
+ def default_behavior
28
+ if defined?(RAILS_ENV)
29
+ DEFAULT_BEHAVIORS[RAILS_ENV.to_s]
30
+ else
31
+ DEFAULT_BEHAVIORS['test']
32
+ end
33
+ end
34
+
35
+ # Have deprecations been silenced?
36
+ def silenced?
37
+ @silenced = false unless defined?(@silenced)
38
+ @silenced
39
+ end
40
+
41
+ # Silence deprecation warnings within the block.
42
+ def silence
43
+ old_silenced, @silenced = @silenced, true
44
+ yield
45
+ ensure
46
+ @silenced = old_silenced
47
+ end
48
+
49
+ attr_writer :silenced
50
+
51
+
52
+ private
53
+ def deprecation_message(callstack, message = nil)
54
+ message ||= "You are using deprecated behavior which will be removed from Rails 2.0."
55
+ "DEPRECATION WARNING: #{message} See http://www.rubyonrails.org/deprecation for details. #{deprecation_caller_message(callstack)}"
56
+ end
57
+
58
+ def deprecation_caller_message(callstack)
59
+ file, line, method = extract_callstack(callstack)
60
+ if file
61
+ if line && method
62
+ "(called from #{method} at #{file}:#{line})"
63
+ else
64
+ "(called from #{file}:#{line})"
65
+ end
66
+ end
67
+ end
68
+
69
+ def extract_callstack(callstack)
70
+ if md = callstack.first.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
71
+ md.captures
72
+ else
73
+ callstack.first
74
+ end
75
+ end
76
+ end
77
+
78
+ # Behavior is a block that takes a message argument.
79
+ mattr_accessor :behavior
80
+ self.behavior = default_behavior
81
+
82
+ # Warnings are not silenced by default.
83
+ self.silenced = false
84
+
85
+ module ClassMethods #:nodoc:
86
+ # Declare that a method has been deprecated.
87
+ def deprecate(*method_names)
88
+ options = method_names.extract_options!
89
+ method_names = method_names + options.keys
90
+ method_names.each do |method_name|
91
+ alias_method_chain(method_name, :deprecation) do |target, punctuation|
92
+ class_eval(<<-EOS, __FILE__, __LINE__)
93
+ def #{target}_with_deprecation#{punctuation}(*args, &block)
94
+ ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), caller)
95
+ #{target}_without_deprecation#{punctuation}(*args, &block)
96
+ end
97
+ EOS
98
+ end
99
+ end
100
+ end
101
+
102
+ def deprecated_method_warning(method_name, message=nil)
103
+ warning = "#{method_name} is deprecated and will be removed from Rails #{deprecation_horizon}"
104
+ case message
105
+ when Symbol then "#{warning} (use #{message} instead)"
106
+ when String then "#{warning} (#{message})"
107
+ else warning
108
+ end
109
+ end
110
+
111
+ def deprecation_horizon
112
+ '2.0'
113
+ end
114
+ end
115
+
116
+ module Assertions #:nodoc:
117
+ def assert_deprecated(match = nil, &block)
118
+ result, warnings = collect_deprecations(&block)
119
+ assert !warnings.empty?, "Expected a deprecation warning within the block but received none"
120
+ if match
121
+ match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp)
122
+ assert warnings.any? { |w| w =~ match }, "No deprecation warning matched #{match}: #{warnings.join(', ')}"
123
+ end
124
+ result
125
+ end
126
+
127
+ def assert_not_deprecated(&block)
128
+ result, deprecations = collect_deprecations(&block)
129
+ assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}"
130
+ result
131
+ end
132
+
133
+ private
134
+ def collect_deprecations
135
+ old_behavior = ActiveSupport::Deprecation.behavior
136
+ deprecations = []
137
+ ActiveSupport::Deprecation.behavior = Proc.new do |message, callstack|
138
+ deprecations << message
139
+ end
140
+ result = yield
141
+ [result, deprecations]
142
+ ensure
143
+ ActiveSupport::Deprecation.behavior = old_behavior
144
+ end
145
+ end
146
+
147
+ # Stand-in for @request, @attributes, @params, etc which emits deprecation
148
+ # warnings on any method call (except #inspect).
149
+ class DeprecatedInstanceVariableProxy #:nodoc:
150
+ silence_warnings do
151
+ instance_methods.each { |m| undef_method m unless m =~ /^__/ }
152
+ end
153
+
154
+ def initialize(instance, method, var = "@#{method}")
155
+ @instance, @method, @var = instance, method, var
156
+ end
157
+
158
+ # Don't give a deprecation warning on inspect since test/unit and error
159
+ # logs rely on it for diagnostics.
160
+ def inspect
161
+ target.inspect
162
+ end
163
+
164
+ private
165
+ def method_missing(called, *args, &block)
166
+ warn caller, called, args
167
+ target.__send__(called, *args, &block)
168
+ end
169
+
170
+ def target
171
+ @instance.__send__(@method)
172
+ end
173
+
174
+ def warn(callstack, called, args)
175
+ ActiveSupport::Deprecation.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ class Module
182
+ include ActiveSupport::Deprecation::ClassMethods
183
+ end
184
+
185
+ require 'test/unit/error'
186
+
187
+ module Test
188
+ module Unit
189
+ class TestCase
190
+ include ActiveSupport::Deprecation::Assertions
191
+ end
192
+
193
+ class Error # :nodoc:
194
+ # Silence warnings when reporting test errors.
195
+ def message_with_silenced_deprecation
196
+ ActiveSupport::Deprecation.silence do
197
+ message_without_silenced_deprecation
198
+ end
199
+ end
200
+
201
+ alias_method_chain :message, :silenced_deprecation
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,96 @@
1
+ module ActiveSupport
2
+ # Provides accurate date and time measurements using Date#advance and
3
+ # Time#advance, respectively. It mainly supports the methods on Numeric,
4
+ # such as in this example:
5
+ #
6
+ # 1.month.ago # equivalent to Time.now.advance(:months => -1)
7
+ class Duration < BasicObject
8
+ attr_accessor :value, :parts
9
+
10
+ def initialize(value, parts) #:nodoc:
11
+ @value, @parts = value, parts
12
+ end
13
+
14
+ # Adds another Duration or a Numeric to this Duration. Numeric values
15
+ # are treated as seconds.
16
+ def +(other)
17
+ if Duration === other
18
+ Duration.new(value + other.value, @parts + other.parts)
19
+ else
20
+ Duration.new(value + other, @parts + [[:seconds, other]])
21
+ end
22
+ end
23
+
24
+ # Subtracts another Duration or a Numeric from this Duration. Numeric
25
+ # values are treated as seconds.
26
+ def -(other)
27
+ self + (-other)
28
+ end
29
+
30
+ def -@ #:nodoc:
31
+ Duration.new(-value, parts.map { |type,number| [type, -number] })
32
+ end
33
+
34
+ def is_a?(klass) #:nodoc:
35
+ klass == Duration || super
36
+ end
37
+
38
+ # Returns true if <tt>other</tt> is also a Duration instance with the
39
+ # same <tt>value</tt>, or if <tt>other == value</tt>.
40
+ def ==(other)
41
+ if Duration === other
42
+ other.value == value
43
+ else
44
+ other == value
45
+ end
46
+ end
47
+
48
+ def self.===(other) #:nodoc:
49
+ other.is_a?(Duration) rescue super
50
+ end
51
+
52
+ # Calculates a new Time or Date that is as far in the future
53
+ # as this Duration represents.
54
+ def since(time = ::Time.now)
55
+ sum(1, time)
56
+ end
57
+ alias :from_now :since
58
+
59
+ # Calculates a new Time or Date that is as far in the past
60
+ # as this Duration represents.
61
+ def ago(time = ::Time.now)
62
+ sum(-1, time)
63
+ end
64
+ alias :until :ago
65
+
66
+ def inspect #:nodoc:
67
+ consolidated = parts.inject(::Hash.new(0)) { |h,part| h[part.first] += part.last; h }
68
+ [:years, :months, :days, :minutes, :seconds].map do |length|
69
+ n = consolidated[length]
70
+ "#{n} #{n == 1 ? length.to_s.singularize : length.to_s}" if n.nonzero?
71
+ end.compact.to_sentence
72
+ end
73
+
74
+ protected
75
+
76
+ def sum(sign, time = ::Time.now) #:nodoc:
77
+ parts.inject(time) do |t,(type,number)|
78
+ if t.acts_like?(:time) || t.acts_like?(:date)
79
+ if type == :seconds
80
+ t.since(sign * number)
81
+ else
82
+ t.advance(type => sign * number)
83
+ end
84
+ else
85
+ raise ArgumentError, "expected a time or date, got #{time.inspect}"
86
+ end
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ def method_missing(method, *args, &block) #:nodoc:
93
+ value.send(method, *args)
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,53 @@
1
+ Inflector.inflections do |inflect|
2
+ inflect.plural(/$/, 's')
3
+ inflect.plural(/s$/i, 's')
4
+ inflect.plural(/(ax|test)is$/i, '\1es')
5
+ inflect.plural(/(octop|vir)us$/i, '\1i')
6
+ inflect.plural(/(alias|status)$/i, '\1es')
7
+ inflect.plural(/(bu)s$/i, '\1ses')
8
+ inflect.plural(/(buffal|tomat)o$/i, '\1oes')
9
+ inflect.plural(/([ti])um$/i, '\1a')
10
+ inflect.plural(/sis$/i, 'ses')
11
+ inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
12
+ inflect.plural(/(hive)$/i, '\1s')
13
+ inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
14
+ inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
15
+ inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
16
+ inflect.plural(/([m|l])ouse$/i, '\1ice')
17
+ inflect.plural(/^(ox)$/i, '\1en')
18
+ inflect.plural(/(quiz)$/i, '\1zes')
19
+
20
+ inflect.singular(/s$/i, '')
21
+ inflect.singular(/(n)ews$/i, '\1ews')
22
+ inflect.singular(/([ti])a$/i, '\1um')
23
+ inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
24
+ inflect.singular(/(^analy)ses$/i, '\1sis')
25
+ inflect.singular(/([^f])ves$/i, '\1fe')
26
+ inflect.singular(/(hive)s$/i, '\1')
27
+ inflect.singular(/(tive)s$/i, '\1')
28
+ inflect.singular(/([lr])ves$/i, '\1f')
29
+ inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
30
+ inflect.singular(/(s)eries$/i, '\1eries')
31
+ inflect.singular(/(m)ovies$/i, '\1ovie')
32
+ inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
33
+ inflect.singular(/([m|l])ice$/i, '\1ouse')
34
+ inflect.singular(/(bus)es$/i, '\1')
35
+ inflect.singular(/(o)es$/i, '\1')
36
+ inflect.singular(/(shoe)s$/i, '\1')
37
+ inflect.singular(/(cris|ax|test)es$/i, '\1is')
38
+ inflect.singular(/(octop|vir)i$/i, '\1us')
39
+ inflect.singular(/(alias|status)es$/i, '\1')
40
+ inflect.singular(/^(ox)en/i, '\1')
41
+ inflect.singular(/(vert|ind)ices$/i, '\1ex')
42
+ inflect.singular(/(matr)ices$/i, '\1ix')
43
+ inflect.singular(/(quiz)zes$/i, '\1')
44
+
45
+ inflect.irregular('person', 'people')
46
+ inflect.irregular('man', 'men')
47
+ inflect.irregular('child', 'children')
48
+ inflect.irregular('sex', 'sexes')
49
+ inflect.irregular('move', 'moves')
50
+ inflect.irregular('cow', 'kine')
51
+
52
+ inflect.uncountable(%w(equipment information rice money species series fish sheep))
53
+ end
@@ -0,0 +1,282 @@
1
+ require 'singleton'
2
+
3
+ # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
4
+ # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
5
+ # in inflections.rb.
6
+ module Inflector
7
+ # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
8
+ # inflection rules. Examples:
9
+ #
10
+ # Inflector.inflections do |inflect|
11
+ # inflect.plural /^(ox)$/i, '\1\2en'
12
+ # inflect.singular /^(ox)en/i, '\1'
13
+ #
14
+ # inflect.irregular 'octopus', 'octopi'
15
+ #
16
+ # inflect.uncountable "equipment"
17
+ # end
18
+ #
19
+ # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
20
+ # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
21
+ # already have been loaded.
22
+ class Inflections
23
+ include Singleton
24
+
25
+ attr_reader :plurals, :singulars, :uncountables
26
+
27
+ def initialize
28
+ @plurals, @singulars, @uncountables = [], [], []
29
+ end
30
+
31
+ # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
32
+ # The replacement should always be a string that may include references to the matched data from the rule.
33
+ def plural(rule, replacement)
34
+ @plurals.insert(0, [rule, replacement])
35
+ end
36
+
37
+ # Specifies a new singularization 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 singular(rule, replacement)
40
+ @singulars.insert(0, [rule, replacement])
41
+ end
42
+
43
+ # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
44
+ # for strings, not regular expressions. You simply pass the irregular in singular and plural form.
45
+ #
46
+ # Examples:
47
+ # irregular 'octopus', 'octopi'
48
+ # irregular 'person', 'people'
49
+ def irregular(singular, plural)
50
+ if singular[0,1].upcase == plural[0,1].upcase
51
+ plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
52
+ singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
53
+ else
54
+ plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
55
+ plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
56
+ singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
57
+ singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
58
+ end
59
+ end
60
+
61
+ # Add uncountable words that shouldn't be attempted inflected.
62
+ #
63
+ # Examples:
64
+ # uncountable "money"
65
+ # uncountable "money", "information"
66
+ # uncountable %w( money information rice )
67
+ def uncountable(*words)
68
+ (@uncountables << words).flatten!
69
+ end
70
+
71
+ # Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type,
72
+ # the options are: :plurals, :singulars, :uncountables
73
+ #
74
+ # Examples:
75
+ # clear :all
76
+ # clear :plurals
77
+ def clear(scope = :all)
78
+ case scope
79
+ when :all
80
+ @plurals, @singulars, @uncountables = [], [], []
81
+ else
82
+ instance_variable_set "@#{scope}", []
83
+ end
84
+ end
85
+ end
86
+
87
+ extend self
88
+
89
+ def inflections
90
+ if block_given?
91
+ yield Inflections.instance
92
+ else
93
+ Inflections.instance
94
+ end
95
+ end
96
+
97
+ # Returns the plural form of the word in the string.
98
+ #
99
+ # Examples
100
+ # "post".pluralize #=> "posts"
101
+ # "octopus".pluralize #=> "octopi"
102
+ # "sheep".pluralize #=> "sheep"
103
+ # "words".pluralize #=> "words"
104
+ # "the blue mailman".pluralize #=> "the blue mailmen"
105
+ # "CamelOctopus".pluralize #=> "CamelOctopi"
106
+ def pluralize(word)
107
+ result = word.to_s.dup
108
+
109
+ if word.empty? || inflections.uncountables.include?(result.downcase)
110
+ result
111
+ else
112
+ inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
113
+ result
114
+ end
115
+ end
116
+
117
+ # The reverse of pluralize, returns the singular form of a word in a string.
118
+ #
119
+ # Examples
120
+ # "posts".singularize #=> "post"
121
+ # "octopi".singularize #=> "octopus"
122
+ # "sheep".singluarize #=> "sheep"
123
+ # "word".singluarize #=> "word"
124
+ # "the blue mailmen".singularize #=> "the blue mailman"
125
+ # "CamelOctopi".singularize #=> "CamelOctopus"
126
+ def singularize(word)
127
+ result = word.to_s.dup
128
+
129
+ if inflections.uncountables.include?(result.downcase)
130
+ result
131
+ else
132
+ inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
133
+ result
134
+ end
135
+ end
136
+
137
+ # By default, camelize converts strings to UpperCamelCase. If the argument to camelize
138
+ # is set to ":lower" then camelize produces lowerCamelCase.
139
+ #
140
+ # camelize will also convert '/' to '::' which is useful for converting paths to namespaces
141
+ #
142
+ # Examples
143
+ # "active_record".camelize #=> "ActiveRecord"
144
+ # "active_record".camelize(:lower) #=> "activeRecord"
145
+ # "active_record/errors".camelize #=> "ActiveRecord::Errors"
146
+ # "active_record/errors".camelize(:lower) #=> "activeRecord::Errors"
147
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
148
+ if first_letter_in_uppercase
149
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
150
+ else
151
+ lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
152
+ end
153
+ end
154
+
155
+ # Capitalizes all the words and replaces some characters in the string to create
156
+ # a nicer looking title. Titleize is meant for creating pretty output. It is not
157
+ # used in the Rails internals.
158
+ #
159
+ # titleize is also aliased as as titlecase
160
+ #
161
+ # Examples
162
+ # "man from the boondocks".titleize #=> "Man From The Boondocks"
163
+ # "x-men: the last stand".titleize #=> "X Men: The Last Stand"
164
+ def titleize(word)
165
+ humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
166
+ end
167
+
168
+ # The reverse of +camelize+. Makes an underscored form from the expression in the string.
169
+ #
170
+ # Changes '::' to '/' to convert namespaces to paths.
171
+ #
172
+ # Examples
173
+ # "ActiveRecord".underscore #=> "active_record"
174
+ # "ActiveRecord::Errors".underscore #=> active_record/errors
175
+ def underscore(camel_cased_word)
176
+ camel_cased_word.to_s.gsub(/::/, '/').
177
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
178
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
179
+ tr("-", "_").
180
+ downcase
181
+ end
182
+
183
+ # Replaces underscores with dashes in the string.
184
+ #
185
+ # Example
186
+ # "puni_puni" #=> "puni-puni"
187
+ def dasherize(underscored_word)
188
+ underscored_word.gsub(/_/, '-')
189
+ end
190
+
191
+ # Capitalizes the first word and turns underscores into spaces and strips _id.
192
+ # Like titleize, this is meant for creating pretty output.
193
+ #
194
+ # Examples
195
+ # "employee_salary" #=> "Employee salary"
196
+ # "author_id" #=> "Author"
197
+ def humanize(lower_case_and_underscored_word)
198
+ lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
199
+ end
200
+
201
+ # Removes the module part from the expression in the string
202
+ #
203
+ # Examples
204
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections"
205
+ # "Inflections".demodulize #=> "Inflections"
206
+ def demodulize(class_name_in_module)
207
+ class_name_in_module.to_s.gsub(/^.*::/, '')
208
+ end
209
+
210
+ # Create the name of a table like Rails does for models to table names. This method
211
+ # uses the pluralize method on the last word in the string.
212
+ #
213
+ # Examples
214
+ # "RawScaledScorer".tableize #=> "raw_scaled_scorers"
215
+ # "egg_and_ham".tableize #=> "egg_and_hams"
216
+ # "fancyCategory".tableize #=> "fancy_categories"
217
+ def tableize(class_name)
218
+ pluralize(underscore(class_name))
219
+ end
220
+
221
+ # Create a class name from a table name like Rails does for table names to models.
222
+ # Note that this returns a string and not a Class. (To convert to an actual class
223
+ # follow classify with constantize.)
224
+ #
225
+ # Examples
226
+ # "egg_and_hams".classify #=> "EggAndHam"
227
+ # "post".classify #=> "Post"
228
+ def classify(table_name)
229
+ # strip out any leading schema name
230
+ camelize(singularize(table_name.to_s.sub(/.*\./, '')))
231
+ end
232
+
233
+ # Creates a foreign key name from a class name.
234
+ # +separate_class_name_and_id_with_underscore+ sets whether
235
+ # the method should put '_' between the name and 'id'.
236
+ #
237
+ # Examples
238
+ # "Message".foreign_key #=> "message_id"
239
+ # "Message".foreign_key(false) #=> "messageid"
240
+ # "Admin::Post".foreign_key #=> "post_id"
241
+ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
242
+ underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
243
+ end
244
+
245
+ # Constantize tries to find a declared constant with the name specified
246
+ # in the string. It raises a NameError when the name is not in CamelCase
247
+ # or is not initialized.
248
+ #
249
+ # Examples
250
+ # "Module".constantize #=> Module
251
+ # "Class".constantize #=> Class
252
+ def constantize(camel_cased_word)
253
+ unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
254
+ raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
255
+ end
256
+
257
+ Object.module_eval("::#{$1}", __FILE__, __LINE__)
258
+ end
259
+
260
+ # Ordinalize turns a number into an ordinal string used to denote the
261
+ # position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
262
+ #
263
+ # Examples
264
+ # ordinalize(1) # => "1st"
265
+ # ordinalize(2) # => "2nd"
266
+ # ordinalize(1002) # => "1002nd"
267
+ # ordinalize(1003) # => "1003rd"
268
+ def ordinalize(number)
269
+ if (11..13).include?(number.to_i % 100)
270
+ "#{number}th"
271
+ else
272
+ case number.to_i % 10
273
+ when 1; "#{number}st"
274
+ when 2; "#{number}nd"
275
+ when 3; "#{number}rd"
276
+ else "#{number}th"
277
+ end
278
+ end
279
+ end
280
+ end
281
+
282
+ require File.dirname(__FILE__) + '/inflections'