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,91 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Numeric #:nodoc:
4
+ # Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
5
+ #
6
+ # These methods use Time#advance for precise date calculations when using from_now, ago, etc.
7
+ # as well as adding or subtracting their results from a Time object. For example:
8
+ #
9
+ # # equivalent to Time.now.advance(:months => 1)
10
+ # 1.month.from_now
11
+ #
12
+ # # equivalent to Time.now.advance(:years => 2)
13
+ # 2.years.from_now
14
+ #
15
+ # # equivalent to Time.now.advance(:months => 4, :years => 5)
16
+ # (4.months + 5.years).from_now
17
+ #
18
+ # While these methods provide precise calculation when used as in the examples above, care
19
+ # should be taken to note that this is not true if the result of `months', `years', etc is
20
+ # converted before use:
21
+ #
22
+ # # equivalent to 30.days.to_i.from_now
23
+ # 1.month.to_i.from_now
24
+ #
25
+ # # equivalent to 365.25.days.to_f.from_now
26
+ # 1.year.to_f.from_now
27
+ #
28
+ # In such cases, Ruby's core
29
+ # Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and
30
+ # Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision
31
+ # date and time arithmetic
32
+ module Time
33
+ def seconds
34
+ ActiveSupport::Duration.new(self, [[:seconds, self]])
35
+ end
36
+ alias :second :seconds
37
+
38
+ def minutes
39
+ ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]])
40
+ end
41
+ alias :minute :minutes
42
+
43
+ def hours
44
+ ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]])
45
+ end
46
+ alias :hour :hours
47
+
48
+ def days
49
+ ActiveSupport::Duration.new(self * 24.hours, [[:days, self]])
50
+ end
51
+ alias :day :days
52
+
53
+ def weeks
54
+ ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]])
55
+ end
56
+ alias :week :weeks
57
+
58
+ def fortnights
59
+ ActiveSupport::Duration.new(self * 2.weeks, [[:days, self * 14]])
60
+ end
61
+ alias :fortnight :fortnights
62
+
63
+ def months
64
+ ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
65
+ end
66
+ alias :month :months
67
+
68
+ def years
69
+ ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
70
+ end
71
+ alias :year :years
72
+
73
+ # Reads best without arguments: 10.minutes.ago
74
+ def ago(time = ::Time.now)
75
+ time - self
76
+ end
77
+
78
+ # Reads best with argument: 10.minutes.until(time)
79
+ alias :until :ago
80
+
81
+ # Reads best with argument: 10.minutes.since(time)
82
+ def since(time = ::Time.now)
83
+ time + self
84
+ end
85
+
86
+ # Reads best without arguments: 10.minutes.from_now
87
+ alias :from_now :since
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,4 @@
1
+ require 'active_support/core_ext/object/conversions'
2
+ require 'active_support/core_ext/object/extending'
3
+ require 'active_support/core_ext/object/instance_variables'
4
+ require 'active_support/core_ext/object/misc'
@@ -0,0 +1,14 @@
1
+ class Object
2
+ # Alias of <tt>to_s</tt>.
3
+ def to_param
4
+ to_s
5
+ end
6
+
7
+ # Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
8
+ # param name.
9
+ #
10
+ # Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
11
+ def to_query(key)
12
+ "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ class Object
2
+ def remove_subclasses_of(*superclasses) #:nodoc:
3
+ Class.remove_class(*subclasses_of(*superclasses))
4
+ end
5
+
6
+ def subclasses_of(*superclasses) #:nodoc:
7
+ subclasses = []
8
+
9
+ # Exclude this class unless it's a subclass of our supers and is defined.
10
+ # We check defined? in case we find a removed class that has yet to be
11
+ # garbage collected. This also fails for anonymous classes -- please
12
+ # submit a patch if you have a workaround.
13
+ ObjectSpace.each_object(Class) do |k|
14
+ if superclasses.any? { |superclass| k < superclass } &&
15
+ (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
16
+ subclasses << k
17
+ end
18
+ end
19
+
20
+ subclasses
21
+ end
22
+
23
+ def extended_by #:nodoc:
24
+ ancestors = class << self; ancestors end
25
+ ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ]
26
+ end
27
+
28
+ def extend_with_included_modules_from(object) #:nodoc:
29
+ object.extended_by.each { |mod| extend mod }
30
+ end
31
+
32
+ unless defined? instance_exec # 1.9
33
+ module InstanceExecMethods #:nodoc:
34
+ end
35
+ include InstanceExecMethods
36
+
37
+ # Evaluate the block with the given arguments within the context of
38
+ # this object, so self is set to the method receiver.
39
+ #
40
+ # From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec
41
+ def instance_exec(*args, &block)
42
+ begin
43
+ old_critical, Thread.critical = Thread.critical, true
44
+ n = 0
45
+ n += 1 while respond_to?(method_name = "__instance_exec#{n}")
46
+ InstanceExecMethods.module_eval { define_method(method_name, &block) }
47
+ ensure
48
+ Thread.critical = old_critical
49
+ end
50
+
51
+ begin
52
+ send(method_name, *args)
53
+ ensure
54
+ InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ class Object
2
+ # Available in 1.8.6 and later.
3
+ unless respond_to?(:instance_variable_defined?)
4
+ def instance_variable_defined?(variable)
5
+ instance_variables.include?(variable.to_s)
6
+ end
7
+ end
8
+
9
+ def instance_values #:nodoc:
10
+ instance_variables.inject({}) do |values, name|
11
+ values[name.to_s[1..-1]] = instance_variable_get(name)
12
+ values
13
+ end
14
+ end
15
+
16
+ def copy_instance_variables_from(object, exclude = []) #:nodoc:
17
+ exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables
18
+
19
+ vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s)
20
+ vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
21
+ end
22
+ end
@@ -0,0 +1,59 @@
1
+ class Object
2
+ unless respond_to?(:send!)
3
+ # Anticipating Ruby 1.9 neutering send
4
+ alias send! send
5
+ end
6
+
7
+ # A Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.
8
+ #
9
+ # def foo
10
+ # returning values = [] do
11
+ # values << 'bar'
12
+ # values << 'baz'
13
+ # end
14
+ # end
15
+ #
16
+ # foo # => ['bar', 'baz']
17
+ #
18
+ # def foo
19
+ # returning [] do |values|
20
+ # values << 'bar'
21
+ # values << 'baz'
22
+ # end
23
+ # end
24
+ #
25
+ # foo # => ['bar', 'baz']
26
+ #
27
+ def returning(value)
28
+ yield(value)
29
+ value
30
+ end
31
+
32
+ # An elegant way to refactor out common options
33
+ #
34
+ # with_options :order => 'created_at', :class_name => 'Comment' do |post|
35
+ # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
36
+ # post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
37
+ # post.has_many :all_comments
38
+ # end
39
+ #
40
+ # Can also be used with an explicit receiver:
41
+ #
42
+ # map.with_options :controller => "people" do |people|
43
+ # people.connect "/people", :action => "index"
44
+ # people.connect "/people/:id", :action => "show"
45
+ # end
46
+ #
47
+ def with_options(options)
48
+ yield ActiveSupport::OptionMerger.new(self, options)
49
+ end
50
+
51
+ # A duck-type assistant method. For example, ActiveSupport extends Date
52
+ # to define an acts_like_date? method, and extends Time to define
53
+ # acts_like_time?. As a result, we can do "x.acts_like?(:time)" and
54
+ # "x.acts_like?(:date)" to do duck-type-safe comparisons, since classes that
55
+ # we want to act like Time simply need to define an acts_like_time? method.
56
+ def acts_like?(duck)
57
+ respond_to? "acts_like_#{duck}?"
58
+ end
59
+ end
@@ -0,0 +1,7 @@
1
+ require 'pathname'
2
+ require 'active_support/core_ext/pathname/clean_within'
3
+
4
+ class Pathname#:nodoc:
5
+ extend ActiveSupport::CoreExtensions::Pathname::CleanWithin
6
+ end
7
+
@@ -0,0 +1,14 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Pathname #:nodoc:
4
+ module CleanWithin
5
+ # Clean the paths contained in the provided string.
6
+ def clean_within(string)
7
+ string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
8
+ new(path).cleanpath
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class Proc #:nodoc:
2
+ def bind(object)
3
+ block, time = self, Time.now
4
+ (class << object; self end).class_eval do
5
+ method_name = "__bind_#{time.to_i}_#{time.usec}"
6
+ define_method(method_name, &block)
7
+ method = instance_method(method_name)
8
+ remove_method(method_name)
9
+ method
10
+ end.bind(object)
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'active_support/core_ext/range/conversions'
2
+ require 'active_support/core_ext/range/overlaps'
3
+ require 'active_support/core_ext/range/include_range'
4
+ require 'active_support/core_ext/range/blockless_step'
5
+
6
+ class Range #:nodoc:
7
+ include ActiveSupport::CoreExtensions::Range::Conversions
8
+ include ActiveSupport::CoreExtensions::Range::Overlaps
9
+ include ActiveSupport::CoreExtensions::Range::IncludeRange
10
+ include ActiveSupport::CoreExtensions::Range::BlocklessStep
11
+ end
@@ -0,0 +1,22 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Range #:nodoc:
4
+ # Return an array when step is called without a block.
5
+ module BlocklessStep
6
+ def self.included(base) #:nodoc:
7
+ base.alias_method_chain :step, :blockless
8
+ end
9
+
10
+ def step_with_blockless(value, &block)
11
+ if block_given?
12
+ step_without_blockless(value, &block)
13
+ else
14
+ returning [] do |array|
15
+ step_without_blockless(value) { |step| array << step }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Range #:nodoc:
4
+ # Getting ranges in different convenient string representations and other objects
5
+ module Conversions
6
+ RANGE_FORMATS = {
7
+ :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
8
+ }
9
+
10
+ def self.included(base) #:nodoc:
11
+ base.class_eval do
12
+ alias_method :to_default_s, :to_s
13
+ alias_method :to_s, :to_formatted_s
14
+ end
15
+ end
16
+
17
+ def to_formatted_s(format = :default)
18
+ RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Range #:nodoc:
4
+ # Check if a Range includes another Range.
5
+ module IncludeRange
6
+ def self.included(base) #:nodoc:
7
+ base.alias_method_chain :include?, :range
8
+ end
9
+
10
+ def include_with_range?(value)
11
+ if value.is_a?(::Range)
12
+ operator = exclude_end? ? :< : :<=
13
+ end_value = value.exclude_end? ? last.succ : last
14
+ include?(value.first) && (value.last <=> end_value).send(operator, 0)
15
+ else
16
+ include_without_range?(value)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Range #:nodoc:
4
+ # Check if Ranges overlap.
5
+ module Overlaps
6
+ def overlaps?(other)
7
+ include?(other.first) || other.include?(first)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'active_support/core_ext/string/conversions'
3
+ require 'active_support/core_ext/string/access'
4
+ require 'active_support/core_ext/string/starts_ends_with'
5
+ require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char)
6
+ require 'active_support/core_ext/string/unicode'
7
+ require 'active_support/core_ext/string/xchar'
8
+
9
+ class String #:nodoc:
10
+ include ActiveSupport::CoreExtensions::String::Access
11
+ include ActiveSupport::CoreExtensions::String::Conversions
12
+ include ActiveSupport::CoreExtensions::String::Inflections
13
+ if RUBY_VERSION < '1.9'
14
+ include ActiveSupport::CoreExtensions::String::StartsEndsWith
15
+ else
16
+ alias starts_with? start_with?
17
+ alias ends_with? end_with?
18
+ end
19
+ if defined? ActiveSupport::CoreExtensions::String::Iterators
20
+ include ActiveSupport::CoreExtensions::String::Iterators
21
+ end
22
+ include ActiveSupport::CoreExtensions::String::Unicode
23
+ end
@@ -0,0 +1,58 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module String #:nodoc:
4
+ # Makes it easier to access parts of a string, such as specific characters and substrings.
5
+ module Access
6
+ # Returns the character at the +position+ treating the string as an array (where 0 is the first character).
7
+ #
8
+ # Examples:
9
+ # "hello".at(0) # => "h"
10
+ # "hello".at(4) # => "o"
11
+ # "hello".at(10) # => nil
12
+ def at(position)
13
+ chars[position, 1].to_s
14
+ end
15
+
16
+ # Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character).
17
+ #
18
+ # Examples:
19
+ # "hello".from(0) # => "hello"
20
+ # "hello".from(2) # => "llo"
21
+ # "hello".from(10) # => nil
22
+ def from(position)
23
+ chars[position..-1].to_s
24
+ end
25
+
26
+ # Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character).
27
+ #
28
+ # Examples:
29
+ # "hello".to(0) # => "h"
30
+ # "hello".to(2) # => "hel"
31
+ # "hello".to(10) # => "hello"
32
+ def to(position)
33
+ chars[0..position].to_s
34
+ end
35
+
36
+ # Returns the first character of the string or the first +limit+ characters.
37
+ #
38
+ # Examples:
39
+ # "hello".first # => "h"
40
+ # "hello".first(2) # => "he"
41
+ # "hello".first(10) # => "hello"
42
+ def first(limit = 1)
43
+ chars[0..(limit - 1)].to_s
44
+ end
45
+
46
+ # Returns the last character of the string or the last +limit+ characters.
47
+ #
48
+ # Examples:
49
+ # "hello".last # => "o"
50
+ # "hello".last(2) # => "lo"
51
+ # "hello".last(10) # => "hello"
52
+ def last(limit = 1)
53
+ (chars[(-limit)..-1] || self).to_s
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end