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,28 @@
1
+ require 'parsedate'
2
+
3
+ module ActiveSupport #:nodoc:
4
+ module CoreExtensions #:nodoc:
5
+ module String #:nodoc:
6
+ # Converting strings to other objects
7
+ module Conversions
8
+ # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
9
+ def ord
10
+ self[0]
11
+ end if RUBY_VERSION < '1.9'
12
+
13
+ # Form can be either :utc (default) or :local.
14
+ def to_time(form = :utc)
15
+ ::Time.send("#{form}_time", *ParseDate.parsedate(self)[0..5].map {|arg| arg || 0})
16
+ end
17
+
18
+ def to_date
19
+ ::Date.new(*ParseDate.parsedate(self)[0..2])
20
+ end
21
+
22
+ def to_datetime
23
+ ::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,153 @@
1
+ require 'active_support/inflector'
2
+
3
+ module ActiveSupport #:nodoc:
4
+ module CoreExtensions #:nodoc:
5
+ module String #:nodoc:
6
+ # String inflections define new methods on the String class to transform names for different purposes.
7
+ # For instance, you can figure out the name of a database from the name of a class.
8
+ # "ScaleScore".tableize => "scale_scores"
9
+ module Inflections
10
+ # Returns the plural form of the word in the string.
11
+ #
12
+ # Examples
13
+ # "post".pluralize #=> "posts"
14
+ # "octopus".pluralize #=> "octopi"
15
+ # "sheep".pluralize #=> "sheep"
16
+ # "words".pluralize #=> "words"
17
+ # "the blue mailman".pluralize #=> "the blue mailmen"
18
+ # "CamelOctopus".pluralize #=> "CamelOctopi"
19
+ def pluralize
20
+ Inflector.pluralize(self)
21
+ end
22
+
23
+ # The reverse of pluralize, returns the singular form of a word in a string.
24
+ #
25
+ # Examples
26
+ # "posts".singularize #=> "post"
27
+ # "octopi".singularize #=> "octopus"
28
+ # "sheep".singluarize #=> "sheep"
29
+ # "word".singluarize #=> "word"
30
+ # "the blue mailmen".singularize #=> "the blue mailman"
31
+ # "CamelOctopi".singularize #=> "CamelOctopus"
32
+ def singularize
33
+ Inflector.singularize(self)
34
+ end
35
+
36
+ # By default, camelize converts strings to UpperCamelCase. If the argument to camelize
37
+ # is set to ":lower" then camelize produces lowerCamelCase.
38
+ #
39
+ # camelize will also convert '/' to '::' which is useful for converting paths to namespaces
40
+ #
41
+ # Examples
42
+ # "active_record".camelize #=> "ActiveRecord"
43
+ # "active_record".camelize(:lower) #=> "activeRecord"
44
+ # "active_record/errors".camelize #=> "ActiveRecord::Errors"
45
+ # "active_record/errors".camelize(:lower) #=> "activeRecord::Errors"
46
+ def camelize(first_letter = :upper)
47
+ case first_letter
48
+ when :upper then Inflector.camelize(self, true)
49
+ when :lower then Inflector.camelize(self, false)
50
+ end
51
+ end
52
+ alias_method :camelcase, :camelize
53
+
54
+ # Capitalizes all the words and replaces some characters in the string to create
55
+ # a nicer looking title. Titleize is meant for creating pretty output. It is not
56
+ # used in the Rails internals.
57
+ #
58
+ # titleize is also aliased as as titlecase
59
+ #
60
+ # Examples
61
+ # "man from the boondocks".titleize #=> "Man From The Boondocks"
62
+ # "x-men: the last stand".titleize #=> "X Men: The Last Stand"
63
+ def titleize
64
+ Inflector.titleize(self)
65
+ end
66
+ alias_method :titlecase, :titleize
67
+
68
+ # The reverse of +camelize+. Makes an underscored form from the expression in the string.
69
+ #
70
+ # Changes '::' to '/' to convert namespaces to paths.
71
+ #
72
+ # Examples
73
+ # "ActiveRecord".underscore #=> "active_record"
74
+ # "ActiveRecord::Errors".underscore #=> active_record/errors
75
+ def underscore
76
+ Inflector.underscore(self)
77
+ end
78
+
79
+ # Replaces underscores with dashes in the string.
80
+ #
81
+ # Example
82
+ # "puni_puni" #=> "puni-puni"
83
+ def dasherize
84
+ Inflector.dasherize(self)
85
+ end
86
+
87
+ # Removes the module part from the expression in the string
88
+ #
89
+ # Examples
90
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections"
91
+ # "Inflections".demodulize #=> "Inflections"
92
+ def demodulize
93
+ Inflector.demodulize(self)
94
+ end
95
+
96
+ # Create the name of a table like Rails does for models to table names. This method
97
+ # uses the pluralize method on the last word in the string.
98
+ #
99
+ # Examples
100
+ # "RawScaledScorer".tableize #=> "raw_scaled_scorers"
101
+ # "egg_and_ham".tableize #=> "egg_and_hams"
102
+ # "fancyCategory".tableize #=> "fancy_categories"
103
+ def tableize
104
+ Inflector.tableize(self)
105
+ end
106
+
107
+ # Create a class name from a table name like Rails does for table names to models.
108
+ # Note that this returns a string and not a Class. (To convert to an actual class
109
+ # follow classify with constantize.)
110
+ #
111
+ # Examples
112
+ # "egg_and_hams".classify #=> "EggAndHam"
113
+ # "post".classify #=> "Post"
114
+ def classify
115
+ Inflector.classify(self)
116
+ end
117
+
118
+ # Capitalizes the first word and turns underscores into spaces and strips _id.
119
+ # Like titleize, this is meant for creating pretty output.
120
+ #
121
+ # Examples
122
+ # "employee_salary" #=> "Employee salary"
123
+ # "author_id" #=> "Author"
124
+ def humanize
125
+ Inflector.humanize(self)
126
+ end
127
+
128
+ # Creates a foreign key name from a class name.
129
+ # +separate_class_name_and_id_with_underscore+ sets whether
130
+ # the method should put '_' between the name and 'id'.
131
+ #
132
+ # Examples
133
+ # "Message".foreign_key #=> "message_id"
134
+ # "Message".foreign_key(false) #=> "messageid"
135
+ # "Admin::Post".foreign_key #=> "post_id"
136
+ def foreign_key(separate_class_name_and_id_with_underscore = true)
137
+ Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
138
+ end
139
+
140
+ # Constantize tries to find a declared constant with the name specified
141
+ # in the string. It raises a NameError when the name is not in CamelCase
142
+ # or is not initialized.
143
+ #
144
+ # Examples
145
+ # "Module".constantize #=> Module
146
+ # "Class".constantize #=> Class
147
+ def constantize
148
+ Inflector.constantize(self)
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,17 @@
1
+ require 'strscan'
2
+
3
+ module ActiveSupport #:nodoc:
4
+ module CoreExtensions #:nodoc:
5
+ module String #:nodoc:
6
+ # Custom string iterators
7
+ module Iterators
8
+ # Yields a single-character string for each character in the string.
9
+ # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
10
+ def each_char
11
+ scanner, char = StringScanner.new(self), /./mu
12
+ loop { yield(scanner.scan(char) || break) }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module String #:nodoc:
4
+ # Additional string tests.
5
+ module StartsEndsWith
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias_method :start_with?, :starts_with?
9
+ alias_method :end_with?, :ends_with?
10
+ end
11
+ end
12
+
13
+ # Does the string start with the specified +prefix+?
14
+ def starts_with?(prefix)
15
+ prefix = prefix.to_s
16
+ self[0, prefix.length] == prefix
17
+ end
18
+
19
+ # Does the string end with the specified +suffix+?
20
+ def ends_with?(suffix)
21
+ suffix = suffix.to_s
22
+ self[-suffix.length, suffix.length] == suffix
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module String #:nodoc:
4
+ # Define methods for handling unicode data.
5
+ module Unicode
6
+ # +chars+ is a Unicode safe proxy for string methods. It creates and returns an instance of the
7
+ # ActiveSupport::Multibyte::Chars class which encapsulates the original string. A Unicode safe version of all
8
+ # the String methods are defined on this proxy class. Undefined methods are forwarded to String, so all of the
9
+ # string overrides can also be called through the +chars+ proxy.
10
+ #
11
+ # name = 'Claus Müller'
12
+ # name.reverse #=> "rell??M sualC"
13
+ # name.length #=> 13
14
+ #
15
+ # name.chars.reverse.to_s #=> "rellüM sualC"
16
+ # name.chars.length #=> 12
17
+ #
18
+ #
19
+ # All the methods on the chars proxy which normally return a string will return a Chars object. This allows
20
+ # method chaining on the result of any of these methods.
21
+ #
22
+ # name.chars.reverse.length #=> 12
23
+ #
24
+ # The Char object tries to be as interchangeable with String objects as possible: sorting and comparing between
25
+ # String and Char work like expected. The bang! methods change the internal string representation in the Chars
26
+ # object. Interoperability problems can be resolved easily with a +to_s+ call.
27
+ #
28
+ # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars and
29
+ # ActiveSupport::Multibyte::Handlers::UTF8Handler
30
+ def chars
31
+ ActiveSupport::Multibyte::Chars.new(self)
32
+ end
33
+
34
+ # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have
35
+ # them), returns false otherwise.
36
+ def is_utf8?
37
+ ActiveSupport::Multibyte::Handlers::UTF8Handler.consumes?(self)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ begin
2
+ # See http://bogomips.org/fast_xs/ by Eric Wong
3
+ require 'fast_xs'
4
+
5
+ class String
6
+ alias_method :original_xs, :to_xs if method_defined?(:to_xs)
7
+ alias_method :to_xs, :fast_xs
8
+ end
9
+ rescue LoadError
10
+ # fast_xs extension unavailable.
11
+ end
@@ -0,0 +1,14 @@
1
+ unless :test.respond_to?(:to_proc)
2
+ class Symbol
3
+ # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
4
+ #
5
+ # # The same as people.collect { |p| p.name }
6
+ # people.collect(&:name)
7
+ #
8
+ # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
9
+ # people.select(&:manager?).collect(&:salary)
10
+ def to_proc
11
+ Proc.new { |*args| args.shift.__send__(self, *args) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ require 'active_support/core_ext/test/unit/assertions'
@@ -0,0 +1,62 @@
1
+ module Test #:nodoc:
2
+ module Unit #:nodoc:
3
+ # FIXME: no Proc#binding in Ruby 2, must change this API
4
+ module Assertions #:nodoc:
5
+ # Test numeric difference between the return value of an expression as a result of what is evaluated
6
+ # in the yielded block.
7
+ #
8
+ # assert_difference 'Article.count' do
9
+ # post :create, :article => {...}
10
+ # end
11
+ #
12
+ # An arbitrary expression is passed in and evaluated.
13
+ #
14
+ # assert_difference 'assigns(:article).comments(:reload).size' do
15
+ # post :create, :comment => {...}
16
+ # end
17
+ #
18
+ # An arbitrary positive or negative difference can be specified. The default is +1.
19
+ #
20
+ # assert_difference 'Article.count', -1 do
21
+ # post :delete, :id => ...
22
+ # end
23
+ #
24
+ # An array of expressions can also be passed in and evaluated.
25
+ #
26
+ # assert_difference [ 'Article.count', 'Post.count' ], +2 do
27
+ # post :create, :article => {...}
28
+ # end
29
+ #
30
+ # A error message can be specified.
31
+ #
32
+ # assert_difference 'Article.count', -1, "An Article should be destroyed" do
33
+ # post :delete, :id => ...
34
+ # end
35
+ def assert_difference(expressions, difference = 1, message = nil, &block)
36
+ expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send!(:binding)) } }
37
+
38
+ original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
39
+ yield
40
+ expression_evaluations.each_with_index do |expression, i|
41
+ assert_equal original_values[i] + difference, expression.call, message
42
+ end
43
+ end
44
+
45
+ # Assertion that the numeric result of evaluating an expression is not changed before and after
46
+ # invoking the passed in block.
47
+ #
48
+ # assert_no_difference 'Article.count' do
49
+ # post :create, :article => invalid_attributes
50
+ # end
51
+ #
52
+ # A error message can be specified.
53
+ #
54
+ # assert_no_difference 'Article.count', "An Article should not be destroyed" do
55
+ # post :create, :article => invalid_attributes
56
+ # end
57
+ def assert_no_difference(expressions, message = nil, &block)
58
+ assert_difference expressions, 0, message, &block
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,19 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ # Ruby 1.8-cvs and 1.9 define private Time#to_date
5
+ class Time
6
+ %w(to_date to_datetime).each do |method|
7
+ public method if private_instance_methods.include?(method)
8
+ end
9
+ end
10
+
11
+ require 'active_support/core_ext/time/behavior'
12
+ require 'active_support/core_ext/time/calculations'
13
+ require 'active_support/core_ext/time/conversions'
14
+
15
+ class Time#:nodoc:
16
+ include ActiveSupport::CoreExtensions::Time::Behavior
17
+ include ActiveSupport::CoreExtensions::Time::Calculations
18
+ include ActiveSupport::CoreExtensions::Time::Conversions
19
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Time #:nodoc:
4
+ module Behavior
5
+ # Enable more predictable duck-typing on Time-like classes. See
6
+ # Object#acts_like?.
7
+ def acts_like_time?
8
+ true
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,224 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Time #:nodoc:
4
+ # Enables the use of time calculations within Time itself
5
+ module Calculations
6
+ def self.included(base) #:nodoc:
7
+ base.extend ClassMethods
8
+
9
+ base.class_eval do
10
+ alias_method :plus_without_duration, :+
11
+ alias_method :+, :plus_with_duration
12
+ alias_method :minus_without_duration, :-
13
+ alias_method :-, :minus_with_duration
14
+ end
15
+ end
16
+
17
+ module ClassMethods
18
+ # Return the number of days in the given month. If a year is given,
19
+ # February will return the correct number of days for leap years.
20
+ # Otherwise, this method will always report February as having 28
21
+ # days.
22
+ def days_in_month(month, year=nil)
23
+ if month == 2
24
+ !year.nil? && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) ? 29 : 28
25
+ elsif month <= 7
26
+ month % 2 == 0 ? 30 : 31
27
+ else
28
+ month % 2 == 0 ? 31 : 30
29
+ end
30
+ end
31
+
32
+ # Returns a new Time if requested year can be accommodated by Ruby's Time class
33
+ # (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture);
34
+ # otherwise returns a DateTime
35
+ def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
36
+ ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
37
+ rescue
38
+ offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0
39
+ ::DateTime.civil(year, month, day, hour, min, sec, offset)
40
+ end
41
+
42
+ # wraps class method time_with_datetime_fallback with utc_or_local == :utc
43
+ def utc_time(*args)
44
+ time_with_datetime_fallback(:utc, *args)
45
+ end
46
+
47
+ # wraps class method time_with_datetime_fallback with utc_or_local == :local
48
+ def local_time(*args)
49
+ time_with_datetime_fallback(:local, *args)
50
+ end
51
+ end
52
+
53
+ # Seconds since midnight: Time.now.seconds_since_midnight
54
+ def seconds_since_midnight
55
+ self.to_i - self.change(:hour => 0).to_i + (self.usec/1.0e+6)
56
+ end
57
+
58
+ # Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options
59
+ # (hour, minute, sec, usec) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0. If the hour and
60
+ # minute is passed, then sec and usec is set to 0.
61
+ def change(options)
62
+ ::Time.send(
63
+ self.utc? ? :utc_time : :local_time,
64
+ options[:year] || self.year,
65
+ options[:month] || self.month,
66
+ options[:day] || self.day,
67
+ options[:hour] || self.hour,
68
+ options[:min] || (options[:hour] ? 0 : self.min),
69
+ options[:sec] || ((options[:hour] || options[:min]) ? 0 : self.sec),
70
+ options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : self.usec)
71
+ )
72
+ end
73
+
74
+ # Uses Date to provide precise Time calculations for years, months, and days. The +options+ parameter takes a hash with
75
+ # any of these keys: :years, :months, :weeks, :days, :hours, :minutes, :seconds.
76
+ def advance(options)
77
+ d = to_date.advance(options)
78
+ time_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
79
+ seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
80
+ seconds_to_advance == 0 ? time_advanced_by_date : time_advanced_by_date.since(seconds_to_advance)
81
+ end
82
+
83
+ # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension
84
+ # Do not use this method in combination with x.months, use months_ago instead!
85
+ def ago(seconds)
86
+ self.since(-seconds)
87
+ end
88
+
89
+ # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around
90
+ # the Numeric extension. Do not use this method in combination with x.months, use months_since instead!
91
+ def since(seconds)
92
+ initial_dst = self.dst? ? 1 : 0
93
+ f = seconds.since(self)
94
+ final_dst = f.dst? ? 1 : 0
95
+ (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f
96
+ rescue
97
+ self.to_datetime.since(seconds)
98
+ end
99
+ alias :in :since
100
+
101
+ # Returns a new Time representing the time a number of specified months ago
102
+ def months_ago(months)
103
+ advance(:months => -months)
104
+ end
105
+
106
+ # Returns a new Time representing the time a number of specified months in the future
107
+ def months_since(months)
108
+ advance(:months => months)
109
+ end
110
+
111
+ # Returns a new Time representing the time a number of specified years ago
112
+ def years_ago(years)
113
+ advance(:years => -years)
114
+ end
115
+
116
+ # Returns a new Time representing the time a number of specified years in the future
117
+ def years_since(years)
118
+ advance(:years => years)
119
+ end
120
+
121
+ # Short-hand for years_ago(1)
122
+ def last_year
123
+ years_ago(1)
124
+ end
125
+
126
+ # Short-hand for years_since(1)
127
+ def next_year
128
+ years_since(1)
129
+ end
130
+
131
+
132
+ # Short-hand for months_ago(1)
133
+ def last_month
134
+ months_ago(1)
135
+ end
136
+
137
+ # Short-hand for months_since(1)
138
+ def next_month
139
+ months_since(1)
140
+ end
141
+
142
+ # Returns a new Time representing the "start" of this week (Monday, 0:00)
143
+ def beginning_of_week
144
+ days_to_monday = self.wday!=0 ? self.wday-1 : 6
145
+ (self - days_to_monday.days).midnight
146
+ end
147
+ alias :monday :beginning_of_week
148
+ alias :at_beginning_of_week :beginning_of_week
149
+
150
+ # Returns a new Time representing the start of the given day in next week (default is Monday).
151
+ def next_week(day = :monday)
152
+ days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6}
153
+ since(1.week).beginning_of_week.since(days_into_week[day].day).change(:hour => 0)
154
+ end
155
+
156
+ # Returns a new Time representing the start of the day (0:00)
157
+ def beginning_of_day
158
+ (self - self.seconds_since_midnight).change(:usec => 0)
159
+ end
160
+ alias :midnight :beginning_of_day
161
+ alias :at_midnight :beginning_of_day
162
+ alias :at_beginning_of_day :beginning_of_day
163
+
164
+ # Returns a new Time representing the end of the day (23:59:59)
165
+ def end_of_day
166
+ change(:hour => 23, :min => 59, :sec => 59)
167
+ end
168
+
169
+ # Returns a new Time representing the start of the month (1st of the month, 0:00)
170
+ def beginning_of_month
171
+ #self - ((self.mday-1).days + self.seconds_since_midnight)
172
+ change(:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0)
173
+ end
174
+ alias :at_beginning_of_month :beginning_of_month
175
+
176
+ # Returns a new Time representing the end of the month (last day of the month, 0:00)
177
+ def end_of_month
178
+ #self - ((self.mday-1).days + self.seconds_since_midnight)
179
+ last_day = ::Time.days_in_month( self.month, self.year )
180
+ change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 0)
181
+ end
182
+ alias :at_end_of_month :end_of_month
183
+
184
+ # Returns a new Time representing the start of the quarter (1st of january, april, july, october, 0:00)
185
+ def beginning_of_quarter
186
+ beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= self.month })
187
+ end
188
+ alias :at_beginning_of_quarter :beginning_of_quarter
189
+
190
+ # Returns a new Time representing the start of the year (1st of january, 0:00)
191
+ def beginning_of_year
192
+ change(:month => 1,:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0)
193
+ end
194
+ alias :at_beginning_of_year :beginning_of_year
195
+
196
+ # Convenience method which returns a new Time representing the time 1 day ago
197
+ def yesterday
198
+ self.ago(1.day)
199
+ end
200
+
201
+ # Convenience method which returns a new Time representing the time 1 day since the instance time
202
+ def tomorrow
203
+ self.since(1.day)
204
+ end
205
+
206
+ def plus_with_duration(other) #:nodoc:
207
+ if ActiveSupport::Duration === other
208
+ other.since(self)
209
+ else
210
+ plus_without_duration(other)
211
+ end
212
+ end
213
+
214
+ def minus_with_duration(other) #:nodoc:
215
+ if ActiveSupport::Duration === other
216
+ other.until(self)
217
+ else
218
+ minus_without_duration(other)
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end