csd 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. data/.gitignore +1 -0
  2. data/COPYING +367 -0
  3. data/Rakefile +10 -10
  4. data/VERSION +1 -1
  5. data/bin/ai +19 -0
  6. data/csd.gemspec +257 -35
  7. data/lib/active_support.rb +75 -0
  8. data/lib/active_support/all.rb +3 -0
  9. data/lib/active_support/backtrace_cleaner.rb +94 -0
  10. data/lib/active_support/base64.rb +42 -0
  11. data/lib/active_support/basic_object.rb +21 -0
  12. data/lib/active_support/benchmarkable.rb +60 -0
  13. data/lib/active_support/buffered_logger.rb +132 -0
  14. data/lib/active_support/builder.rb +6 -0
  15. data/lib/active_support/cache.rb +626 -0
  16. data/lib/active_support/cache/compressed_mem_cache_store.rb +13 -0
  17. data/lib/active_support/cache/file_store.rb +188 -0
  18. data/lib/active_support/cache/mem_cache_store.rb +191 -0
  19. data/lib/active_support/cache/memory_store.rb +159 -0
  20. data/lib/active_support/cache/strategy/local_cache.rb +164 -0
  21. data/lib/active_support/cache/synchronized_memory_store.rb +11 -0
  22. data/lib/active_support/callbacks.rb +600 -0
  23. data/lib/active_support/concern.rb +29 -0
  24. data/lib/active_support/configurable.rb +36 -0
  25. data/lib/active_support/core_ext.rb +3 -0
  26. data/lib/active_support/core_ext/array.rb +7 -0
  27. data/lib/active_support/core_ext/array/access.rb +46 -0
  28. data/lib/active_support/core_ext/array/conversions.rb +164 -0
  29. data/lib/active_support/core_ext/array/extract_options.rb +29 -0
  30. data/lib/active_support/core_ext/array/grouping.rb +100 -0
  31. data/lib/active_support/core_ext/array/random_access.rb +20 -0
  32. data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
  33. data/lib/active_support/core_ext/array/wrap.rb +22 -0
  34. data/lib/active_support/core_ext/benchmark.rb +7 -0
  35. data/lib/active_support/core_ext/big_decimal.rb +1 -0
  36. data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
  37. data/lib/active_support/core_ext/cgi.rb +1 -0
  38. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +19 -0
  39. data/lib/active_support/core_ext/class.rb +4 -0
  40. data/lib/active_support/core_ext/class/attribute.rb +67 -0
  41. data/lib/active_support/core_ext/class/attribute_accessors.rb +63 -0
  42. data/lib/active_support/core_ext/class/delegating_attributes.rb +44 -0
  43. data/lib/active_support/core_ext/class/inheritable_attributes.rb +232 -0
  44. data/lib/active_support/core_ext/class/subclasses.rb +55 -0
  45. data/lib/active_support/core_ext/date/acts_like.rb +8 -0
  46. data/lib/active_support/core_ext/date/calculations.rb +240 -0
  47. data/lib/active_support/core_ext/date/conversions.rb +99 -0
  48. data/lib/active_support/core_ext/date/freeze.rb +31 -0
  49. data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
  50. data/lib/active_support/core_ext/date_time/calculations.rb +113 -0
  51. data/lib/active_support/core_ext/date_time/conversions.rb +102 -0
  52. data/lib/active_support/core_ext/date_time/zones.rb +17 -0
  53. data/lib/active_support/core_ext/enumerable.rb +119 -0
  54. data/lib/active_support/core_ext/exception.rb +3 -0
  55. data/lib/active_support/core_ext/file.rb +2 -0
  56. data/lib/active_support/core_ext/file/atomic.rb +41 -0
  57. data/lib/active_support/core_ext/file/path.rb +5 -0
  58. data/lib/active_support/core_ext/float.rb +1 -0
  59. data/lib/active_support/core_ext/float/rounding.rb +19 -0
  60. data/lib/active_support/core_ext/hash.rb +8 -0
  61. data/lib/active_support/core_ext/hash/conversions.rb +150 -0
  62. data/lib/active_support/core_ext/hash/deep_merge.rb +16 -0
  63. data/lib/active_support/core_ext/hash/diff.rb +13 -0
  64. data/lib/active_support/core_ext/hash/except.rb +24 -0
  65. data/lib/active_support/core_ext/hash/indifferent_access.rb +14 -0
  66. data/lib/active_support/core_ext/hash/keys.rb +45 -0
  67. data/lib/active_support/core_ext/hash/reverse_merge.rb +28 -0
  68. data/lib/active_support/core_ext/hash/slice.rb +38 -0
  69. data/lib/active_support/core_ext/integer.rb +3 -0
  70. data/lib/active_support/core_ext/integer/inflections.rb +14 -0
  71. data/lib/active_support/core_ext/integer/multiple.rb +6 -0
  72. data/lib/active_support/core_ext/integer/time.rb +39 -0
  73. data/lib/active_support/core_ext/kernel.rb +5 -0
  74. data/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
  75. data/lib/active_support/core_ext/kernel/debugger.rb +16 -0
  76. data/lib/active_support/core_ext/kernel/reporting.rb +62 -0
  77. data/lib/active_support/core_ext/kernel/requires.rb +26 -0
  78. data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
  79. data/lib/active_support/core_ext/load_error.rb +23 -0
  80. data/lib/active_support/core_ext/logger.rb +146 -0
  81. data/lib/active_support/core_ext/module.rb +12 -0
  82. data/lib/active_support/core_ext/module/aliasing.rb +70 -0
  83. data/lib/active_support/core_ext/module/anonymous.rb +24 -0
  84. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
  85. data/lib/active_support/core_ext/module/attr_internal.rb +32 -0
  86. data/lib/active_support/core_ext/module/attribute_accessors.rb +66 -0
  87. data/lib/active_support/core_ext/module/delegation.rb +146 -0
  88. data/lib/active_support/core_ext/module/deprecation.rb +9 -0
  89. data/lib/active_support/core_ext/module/introspection.rb +88 -0
  90. data/lib/active_support/core_ext/module/method_names.rb +14 -0
  91. data/lib/active_support/core_ext/module/reachable.rb +10 -0
  92. data/lib/active_support/core_ext/module/remove_method.rb +6 -0
  93. data/lib/active_support/core_ext/module/synchronization.rb +42 -0
  94. data/lib/active_support/core_ext/name_error.rb +18 -0
  95. data/lib/active_support/core_ext/numeric.rb +2 -0
  96. data/lib/active_support/core_ext/numeric/bytes.rb +44 -0
  97. data/lib/active_support/core_ext/numeric/time.rb +77 -0
  98. data/lib/active_support/core_ext/object.rb +14 -0
  99. data/lib/active_support/core_ext/object/acts_like.rb +10 -0
  100. data/lib/active_support/core_ext/object/blank.rb +76 -0
  101. data/lib/active_support/core_ext/object/conversions.rb +4 -0
  102. data/lib/active_support/core_ext/object/duplicable.rb +65 -0
  103. data/lib/active_support/core_ext/object/extending.rb +11 -0
  104. data/lib/active_support/core_ext/object/instance_variables.rb +67 -0
  105. data/lib/active_support/core_ext/object/misc.rb +2 -0
  106. data/lib/active_support/core_ext/object/returning.rb +42 -0
  107. data/lib/active_support/core_ext/object/to_param.rb +49 -0
  108. data/lib/active_support/core_ext/object/to_query.rb +27 -0
  109. data/lib/active_support/core_ext/object/try.rb +36 -0
  110. data/lib/active_support/core_ext/object/with_options.rb +26 -0
  111. data/lib/active_support/core_ext/proc.rb +14 -0
  112. data/lib/active_support/core_ext/process.rb +1 -0
  113. data/lib/active_support/core_ext/process/daemon.rb +23 -0
  114. data/lib/active_support/core_ext/range.rb +4 -0
  115. data/lib/active_support/core_ext/range/blockless_step.rb +29 -0
  116. data/lib/active_support/core_ext/range/conversions.rb +21 -0
  117. data/lib/active_support/core_ext/range/include_range.rb +21 -0
  118. data/lib/active_support/core_ext/range/overlaps.rb +8 -0
  119. data/lib/active_support/core_ext/regexp.rb +5 -0
  120. data/lib/active_support/core_ext/rexml.rb +46 -0
  121. data/lib/active_support/core_ext/string.rb +12 -0
  122. data/lib/active_support/core_ext/string/access.rb +99 -0
  123. data/lib/active_support/core_ext/string/behavior.rb +7 -0
  124. data/lib/active_support/core_ext/string/conversions.rb +61 -0
  125. data/lib/active_support/core_ext/string/encoding.rb +11 -0
  126. data/lib/active_support/core_ext/string/exclude.rb +6 -0
  127. data/lib/active_support/core_ext/string/filters.rb +49 -0
  128. data/lib/active_support/core_ext/string/inflections.rb +149 -0
  129. data/lib/active_support/core_ext/string/interpolation.rb +2 -0
  130. data/lib/active_support/core_ext/string/multibyte.rb +72 -0
  131. data/lib/active_support/core_ext/string/output_safety.rb +109 -0
  132. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -0
  133. data/lib/active_support/core_ext/string/xchar.rb +18 -0
  134. data/lib/active_support/core_ext/time/acts_like.rb +8 -0
  135. data/lib/active_support/core_ext/time/calculations.rb +282 -0
  136. data/lib/active_support/core_ext/time/conversions.rb +85 -0
  137. data/lib/active_support/core_ext/time/marshal.rb +56 -0
  138. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
  139. data/lib/active_support/core_ext/time/zones.rb +78 -0
  140. data/lib/active_support/core_ext/uri.rb +22 -0
  141. data/lib/active_support/dependencies.rb +628 -0
  142. data/lib/active_support/dependencies/autoload.rb +50 -0
  143. data/lib/active_support/deprecation.rb +18 -0
  144. data/lib/active_support/deprecation/behaviors.rb +38 -0
  145. data/lib/active_support/deprecation/method_wrappers.rb +29 -0
  146. data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
  147. data/lib/active_support/deprecation/reporting.rb +56 -0
  148. data/lib/active_support/duration.rb +105 -0
  149. data/lib/active_support/gzip.rb +25 -0
  150. data/lib/active_support/hash_with_indifferent_access.rb +145 -0
  151. data/lib/active_support/i18n.rb +8 -0
  152. data/lib/active_support/inflections.rb +56 -0
  153. data/lib/active_support/inflector.rb +7 -0
  154. data/lib/active_support/inflector/inflections.rb +211 -0
  155. data/lib/active_support/inflector/methods.rb +141 -0
  156. data/lib/active_support/inflector/transliterate.rb +97 -0
  157. data/lib/active_support/json.rb +2 -0
  158. data/lib/active_support/json/backends/jsongem.rb +43 -0
  159. data/lib/active_support/json/backends/yajl.rb +40 -0
  160. data/lib/active_support/json/backends/yaml.rb +90 -0
  161. data/lib/active_support/json/decoding.rb +51 -0
  162. data/lib/active_support/json/encoding.rb +254 -0
  163. data/lib/active_support/json/variable.rb +11 -0
  164. data/lib/active_support/lazy_load_hooks.rb +27 -0
  165. data/lib/active_support/locale/en.yml +36 -0
  166. data/lib/active_support/memoizable.rb +103 -0
  167. data/lib/active_support/message_encryptor.rb +71 -0
  168. data/lib/active_support/message_verifier.rb +62 -0
  169. data/lib/active_support/multibyte.rb +44 -0
  170. data/lib/active_support/multibyte/chars.rb +480 -0
  171. data/lib/active_support/multibyte/exceptions.rb +8 -0
  172. data/lib/active_support/multibyte/unicode.rb +393 -0
  173. data/lib/active_support/multibyte/utils.rb +60 -0
  174. data/lib/active_support/notifications.rb +81 -0
  175. data/lib/active_support/notifications/fanout.rb +93 -0
  176. data/lib/active_support/notifications/instrumenter.rb +56 -0
  177. data/lib/active_support/option_merger.rb +25 -0
  178. data/lib/active_support/ordered_hash.rb +158 -0
  179. data/lib/active_support/ordered_options.rb +27 -0
  180. data/lib/active_support/railtie.rb +100 -0
  181. data/lib/active_support/rescuable.rb +114 -0
  182. data/lib/active_support/ruby/shim.rb +22 -0
  183. data/lib/active_support/secure_random.rb +199 -0
  184. data/lib/active_support/string_inquirer.rb +21 -0
  185. data/lib/active_support/test_case.rb +42 -0
  186. data/lib/active_support/testing/assertions.rb +82 -0
  187. data/lib/active_support/testing/declarative.rb +40 -0
  188. data/lib/active_support/testing/default.rb +9 -0
  189. data/lib/active_support/testing/deprecation.rb +55 -0
  190. data/lib/active_support/testing/isolation.rb +154 -0
  191. data/lib/active_support/testing/pending.rb +48 -0
  192. data/lib/active_support/testing/performance.rb +455 -0
  193. data/lib/active_support/testing/setup_and_teardown.rb +111 -0
  194. data/lib/active_support/time.rb +34 -0
  195. data/lib/active_support/time/autoload.rb +5 -0
  196. data/lib/active_support/time_with_zone.rb +341 -0
  197. data/lib/active_support/values/time_zone.rb +377 -0
  198. data/lib/active_support/values/unicode_tables.dat +0 -0
  199. data/lib/active_support/version.rb +10 -0
  200. data/lib/active_support/whiny_nil.rb +60 -0
  201. data/lib/active_support/xml_mini.rb +158 -0
  202. data/lib/active_support/xml_mini/jdom.rb +168 -0
  203. data/lib/active_support/xml_mini/libxml.rb +80 -0
  204. data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
  205. data/lib/active_support/xml_mini/nokogiri.rb +78 -0
  206. data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
  207. data/lib/active_support/xml_mini/rexml.rb +129 -0
  208. data/lib/csd.rb +82 -2
  209. data/lib/csd/application.rb +2 -0
  210. data/lib/csd/application/default.rb +51 -0
  211. data/lib/csd/application/default/base.rb +15 -0
  212. data/lib/csd/application/minisip.rb +25 -0
  213. data/lib/csd/application/minisip/about.yml +14 -0
  214. data/lib/csd/application/minisip/base.rb +161 -0
  215. data/lib/csd/application/minisip/error.rb +11 -0
  216. data/lib/csd/application/minisip/options/common.rb +0 -0
  217. data/lib/csd/application/minisip/options/compile.rb +59 -0
  218. data/lib/csd/{applications → application}/minisip/unix/base.rb +10 -11
  219. data/lib/csd/application/opensips/about.yml +2 -0
  220. data/lib/csd/applications.rb +55 -0
  221. data/lib/csd/commands.rb +88 -65
  222. data/lib/csd/error.rb +31 -0
  223. data/lib/csd/extensions.rb +1 -0
  224. data/lib/{extensions → csd/extensions}/core/array.rb +2 -2
  225. data/lib/csd/extensions/core/dir.rb +46 -0
  226. data/lib/{extensions → csd/extensions}/core/file.rb +2 -2
  227. data/lib/{extensions → csd/extensions}/core/object.rb +2 -2
  228. data/lib/csd/extensions/core/option_parser.rb +33 -0
  229. data/lib/{extensions → csd/extensions}/core/pathname.rb +12 -3
  230. data/lib/{extensions → csd/extensions}/core/string.rb +2 -2
  231. data/lib/{extensions → csd/extensions}/gem/platform.rb +6 -2
  232. data/lib/csd/global_open_struct.rb +18 -0
  233. data/lib/csd/options.rb +124 -95
  234. data/lib/csd/path.rb +31 -0
  235. data/lib/csd/ui.rb +1 -0
  236. data/lib/csd/ui/cli.rb +7 -0
  237. data/lib/csd/ui/ui.rb +46 -0
  238. data/lib/csd/version.rb +9 -0
  239. data/lib/term/ansicolor.rb +102 -0
  240. data/lib/term/ansicolor/.keep +0 -0
  241. data/lib/term/ansicolor/version.rb +10 -0
  242. data/test/functional/test_applications.rb +86 -0
  243. data/test/functional/test_commands.rb +42 -29
  244. data/test/functional/test_options.rb +98 -0
  245. data/test/helper.rb +14 -0
  246. data/test/unit/test_dir.rb +38 -0
  247. data/test/unit/test_pathname.rb +32 -0
  248. metadata +253 -40
  249. data/LICENSE +0 -20
  250. data/bin/csd +0 -8
  251. data/lib/csd/applications/base.rb +0 -33
  252. data/lib/csd/applications/minisip/base.rb +0 -125
  253. data/lib/csd/applications/minisip/init.rb +0 -20
  254. data/lib/csd/init.rb +0 -69
  255. data/lib/csd/path_container.rb +0 -15
  256. data/publish +0 -29
@@ -0,0 +1,377 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'active_support/core_ext/object/try'
3
+ begin
4
+ require 'tzinfo'
5
+ rescue LoadError => e
6
+ $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
7
+ raise e
8
+ end
9
+
10
+ # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
11
+ #
12
+ # * Limit the set of zones provided by TZInfo to a meaningful subset of 142 zones.
13
+ # * Retrieve and display zones with a friendlier name (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
14
+ # * Lazily load TZInfo::Timezone instances only when they're needed.
15
+ # * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+, +parse+, +at+ and +now+ methods.
16
+ #
17
+ # If you set <tt>config.time_zone</tt> in the Rails Initializer, you can access this TimeZone object via <tt>Time.zone</tt>:
18
+ #
19
+ # # environment.rb:
20
+ # Rails::Initializer.run do |config|
21
+ # config.time_zone = "Eastern Time (US & Canada)"
22
+ # end
23
+ #
24
+ # Time.zone # => #<TimeZone:0x514834...>
25
+ # Time.zone.name # => "Eastern Time (US & Canada)"
26
+ # Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
27
+ #
28
+ # The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones
29
+ # defined by the TimeZone class. If you need to use zones that aren't defined by TimeZone, you'll need to install the TZInfo gem
30
+ # (if a recent version of the gem is installed locally, this will be used instead of the bundled version.)
31
+ module ActiveSupport
32
+ class TimeZone
33
+ unless const_defined?(:MAPPING)
34
+ # Keys are Rails TimeZone names, values are TZInfo identifiers
35
+ MAPPING = {
36
+ "International Date Line West" => "Pacific/Midway",
37
+ "Midway Island" => "Pacific/Midway",
38
+ "Samoa" => "Pacific/Pago_Pago",
39
+ "Hawaii" => "Pacific/Honolulu",
40
+ "Alaska" => "America/Juneau",
41
+ "Pacific Time (US & Canada)" => "America/Los_Angeles",
42
+ "Tijuana" => "America/Tijuana",
43
+ "Mountain Time (US & Canada)" => "America/Denver",
44
+ "Arizona" => "America/Phoenix",
45
+ "Chihuahua" => "America/Chihuahua",
46
+ "Mazatlan" => "America/Mazatlan",
47
+ "Central Time (US & Canada)" => "America/Chicago",
48
+ "Saskatchewan" => "America/Regina",
49
+ "Guadalajara" => "America/Mexico_City",
50
+ "Mexico City" => "America/Mexico_City",
51
+ "Monterrey" => "America/Monterrey",
52
+ "Central America" => "America/Guatemala",
53
+ "Eastern Time (US & Canada)" => "America/New_York",
54
+ "Indiana (East)" => "America/Indiana/Indianapolis",
55
+ "Bogota" => "America/Bogota",
56
+ "Lima" => "America/Lima",
57
+ "Quito" => "America/Lima",
58
+ "Atlantic Time (Canada)" => "America/Halifax",
59
+ "Caracas" => "America/Caracas",
60
+ "La Paz" => "America/La_Paz",
61
+ "Santiago" => "America/Santiago",
62
+ "Newfoundland" => "America/St_Johns",
63
+ "Brasilia" => "America/Sao_Paulo",
64
+ "Buenos Aires" => "America/Argentina/Buenos_Aires",
65
+ "Georgetown" => "America/Guyana",
66
+ "Greenland" => "America/Godthab",
67
+ "Mid-Atlantic" => "Atlantic/South_Georgia",
68
+ "Azores" => "Atlantic/Azores",
69
+ "Cape Verde Is." => "Atlantic/Cape_Verde",
70
+ "Dublin" => "Europe/Dublin",
71
+ "Edinburgh" => "Europe/London",
72
+ "Lisbon" => "Europe/Lisbon",
73
+ "London" => "Europe/London",
74
+ "Casablanca" => "Africa/Casablanca",
75
+ "Monrovia" => "Africa/Monrovia",
76
+ "UTC" => "Etc/UTC",
77
+ "Belgrade" => "Europe/Belgrade",
78
+ "Bratislava" => "Europe/Bratislava",
79
+ "Budapest" => "Europe/Budapest",
80
+ "Ljubljana" => "Europe/Ljubljana",
81
+ "Prague" => "Europe/Prague",
82
+ "Sarajevo" => "Europe/Sarajevo",
83
+ "Skopje" => "Europe/Skopje",
84
+ "Warsaw" => "Europe/Warsaw",
85
+ "Zagreb" => "Europe/Zagreb",
86
+ "Brussels" => "Europe/Brussels",
87
+ "Copenhagen" => "Europe/Copenhagen",
88
+ "Madrid" => "Europe/Madrid",
89
+ "Paris" => "Europe/Paris",
90
+ "Amsterdam" => "Europe/Amsterdam",
91
+ "Berlin" => "Europe/Berlin",
92
+ "Bern" => "Europe/Berlin",
93
+ "Rome" => "Europe/Rome",
94
+ "Stockholm" => "Europe/Stockholm",
95
+ "Vienna" => "Europe/Vienna",
96
+ "West Central Africa" => "Africa/Algiers",
97
+ "Bucharest" => "Europe/Bucharest",
98
+ "Cairo" => "Africa/Cairo",
99
+ "Helsinki" => "Europe/Helsinki",
100
+ "Kyiv" => "Europe/Kiev",
101
+ "Riga" => "Europe/Riga",
102
+ "Sofia" => "Europe/Sofia",
103
+ "Tallinn" => "Europe/Tallinn",
104
+ "Vilnius" => "Europe/Vilnius",
105
+ "Athens" => "Europe/Athens",
106
+ "Istanbul" => "Europe/Istanbul",
107
+ "Minsk" => "Europe/Minsk",
108
+ "Jerusalem" => "Asia/Jerusalem",
109
+ "Harare" => "Africa/Harare",
110
+ "Pretoria" => "Africa/Johannesburg",
111
+ "Moscow" => "Europe/Moscow",
112
+ "St. Petersburg" => "Europe/Moscow",
113
+ "Volgograd" => "Europe/Moscow",
114
+ "Kuwait" => "Asia/Kuwait",
115
+ "Riyadh" => "Asia/Riyadh",
116
+ "Nairobi" => "Africa/Nairobi",
117
+ "Baghdad" => "Asia/Baghdad",
118
+ "Tehran" => "Asia/Tehran",
119
+ "Abu Dhabi" => "Asia/Muscat",
120
+ "Muscat" => "Asia/Muscat",
121
+ "Baku" => "Asia/Baku",
122
+ "Tbilisi" => "Asia/Tbilisi",
123
+ "Yerevan" => "Asia/Yerevan",
124
+ "Kabul" => "Asia/Kabul",
125
+ "Ekaterinburg" => "Asia/Yekaterinburg",
126
+ "Islamabad" => "Asia/Karachi",
127
+ "Karachi" => "Asia/Karachi",
128
+ "Tashkent" => "Asia/Tashkent",
129
+ "Chennai" => "Asia/Kolkata",
130
+ "Kolkata" => "Asia/Kolkata",
131
+ "Mumbai" => "Asia/Kolkata",
132
+ "New Delhi" => "Asia/Kolkata",
133
+ "Kathmandu" => "Asia/Kathmandu",
134
+ "Astana" => "Asia/Dhaka",
135
+ "Dhaka" => "Asia/Dhaka",
136
+ "Sri Jayawardenepura" => "Asia/Colombo",
137
+ "Almaty" => "Asia/Almaty",
138
+ "Novosibirsk" => "Asia/Novosibirsk",
139
+ "Rangoon" => "Asia/Rangoon",
140
+ "Bangkok" => "Asia/Bangkok",
141
+ "Hanoi" => "Asia/Bangkok",
142
+ "Jakarta" => "Asia/Jakarta",
143
+ "Krasnoyarsk" => "Asia/Krasnoyarsk",
144
+ "Beijing" => "Asia/Shanghai",
145
+ "Chongqing" => "Asia/Chongqing",
146
+ "Hong Kong" => "Asia/Hong_Kong",
147
+ "Urumqi" => "Asia/Urumqi",
148
+ "Kuala Lumpur" => "Asia/Kuala_Lumpur",
149
+ "Singapore" => "Asia/Singapore",
150
+ "Taipei" => "Asia/Taipei",
151
+ "Perth" => "Australia/Perth",
152
+ "Irkutsk" => "Asia/Irkutsk",
153
+ "Ulaan Bataar" => "Asia/Ulaanbaatar",
154
+ "Seoul" => "Asia/Seoul",
155
+ "Osaka" => "Asia/Tokyo",
156
+ "Sapporo" => "Asia/Tokyo",
157
+ "Tokyo" => "Asia/Tokyo",
158
+ "Yakutsk" => "Asia/Yakutsk",
159
+ "Darwin" => "Australia/Darwin",
160
+ "Adelaide" => "Australia/Adelaide",
161
+ "Canberra" => "Australia/Melbourne",
162
+ "Melbourne" => "Australia/Melbourne",
163
+ "Sydney" => "Australia/Sydney",
164
+ "Brisbane" => "Australia/Brisbane",
165
+ "Hobart" => "Australia/Hobart",
166
+ "Vladivostok" => "Asia/Vladivostok",
167
+ "Guam" => "Pacific/Guam",
168
+ "Port Moresby" => "Pacific/Port_Moresby",
169
+ "Magadan" => "Asia/Magadan",
170
+ "Solomon Is." => "Asia/Magadan",
171
+ "New Caledonia" => "Pacific/Noumea",
172
+ "Fiji" => "Pacific/Fiji",
173
+ "Kamchatka" => "Asia/Kamchatka",
174
+ "Marshall Is." => "Pacific/Majuro",
175
+ "Auckland" => "Pacific/Auckland",
176
+ "Wellington" => "Pacific/Auckland",
177
+ "Nuku'alofa" => "Pacific/Tongatapu"
178
+ }.each { |name, zone| name.freeze; zone.freeze }
179
+ MAPPING.freeze
180
+ end
181
+
182
+ UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
183
+ UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
184
+
185
+ # Assumes self represents an offset from UTC in seconds (as returned from Time#utc_offset)
186
+ # and turns this into an +HH:MM formatted string. Example:
187
+ #
188
+ # TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
189
+ def self.seconds_to_utc_offset(seconds, colon = true)
190
+ format = colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON
191
+ sign = (seconds < 0 ? '-' : '+')
192
+ hours = seconds.abs / 3600
193
+ minutes = (seconds.abs % 3600) / 60
194
+ format % [sign, hours, minutes]
195
+ end
196
+
197
+ include Comparable
198
+ attr_reader :name
199
+ attr_reader :tzinfo
200
+
201
+ # Create a new TimeZone object with the given name and offset. The
202
+ # offset is the number of seconds that this time zone is offset from UTC
203
+ # (GMT). Seconds were chosen as the offset unit because that is the unit that
204
+ # Ruby uses to represent time zone offsets (see Time#utc_offset).
205
+ def initialize(name, utc_offset = nil, tzinfo = nil)
206
+ @name = name
207
+ @utc_offset = utc_offset
208
+ @tzinfo = tzinfo || TimeZone.find_tzinfo(name)
209
+ @current_period = nil
210
+ end
211
+
212
+ def utc_offset
213
+ if @utc_offset
214
+ @utc_offset
215
+ else
216
+ @current_period ||= tzinfo.try(:current_period)
217
+ @current_period.try(:utc_offset)
218
+ end
219
+ end
220
+
221
+ # Returns the offset of this time zone as a formatted string, of the
222
+ # format "+HH:MM".
223
+ def formatted_offset(colon=true, alternate_utc_string = nil)
224
+ utc_offset == 0 && alternate_utc_string || self.class.seconds_to_utc_offset(utc_offset, colon)
225
+ end
226
+
227
+ # Compare this time zone to the parameter. The two are comapred first on
228
+ # their offsets, and then by name.
229
+ def <=>(zone)
230
+ result = (utc_offset <=> zone.utc_offset)
231
+ result = (name <=> zone.name) if result == 0
232
+ result
233
+ end
234
+
235
+ # Compare #name and TZInfo identifier to a supplied regexp, returning true
236
+ # if a match is found.
237
+ def =~(re)
238
+ return true if name =~ re || MAPPING[name] =~ re
239
+ end
240
+
241
+ # Returns a textual representation of this time zone.
242
+ def to_s
243
+ "(GMT#{formatted_offset}) #{name}"
244
+ end
245
+
246
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
247
+ #
248
+ # Time.zone = "Hawaii" # => "Hawaii"
249
+ # Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
250
+ def local(*args)
251
+ time = Time.utc_time(*args)
252
+ ActiveSupport::TimeWithZone.new(nil, self, time)
253
+ end
254
+
255
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example:
256
+ #
257
+ # Time.zone = "Hawaii" # => "Hawaii"
258
+ # Time.utc(2000).to_f # => 946684800.0
259
+ # Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
260
+ def at(secs)
261
+ utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs)
262
+ utc.in_time_zone(self)
263
+ end
264
+
265
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
266
+ #
267
+ # Time.zone = "Hawaii" # => "Hawaii"
268
+ # Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
269
+ #
270
+ # If upper components are missing from the string, they are supplied from TimeZone#now:
271
+ #
272
+ # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
273
+ # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
274
+ def parse(str, now=now)
275
+ date_parts = Date._parse(str)
276
+ return if date_parts.blank?
277
+ time = Time.parse(str, now) rescue DateTime.parse(str)
278
+ if date_parts[:offset].nil?
279
+ ActiveSupport::TimeWithZone.new(nil, self, time)
280
+ else
281
+ time.in_time_zone(self)
282
+ end
283
+ end
284
+
285
+ # Returns an ActiveSupport::TimeWithZone instance representing the current time
286
+ # in the time zone represented by +self+. Example:
287
+ #
288
+ # Time.zone = 'Hawaii' # => "Hawaii"
289
+ # Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
290
+ def now
291
+ Time.now.utc.in_time_zone(self)
292
+ end
293
+
294
+ # Return the current date in this time zone.
295
+ def today
296
+ tzinfo.now.to_date
297
+ end
298
+
299
+ # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a
300
+ # Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
301
+ def utc_to_local(time)
302
+ tzinfo.utc_to_local(time)
303
+ end
304
+
305
+ # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
306
+ def local_to_utc(time, dst=true)
307
+ tzinfo.local_to_utc(time, dst)
308
+ end
309
+
310
+ # Available so that TimeZone instances respond like TZInfo::Timezone instances
311
+ def period_for_utc(time)
312
+ tzinfo.period_for_utc(time)
313
+ end
314
+
315
+ # Available so that TimeZone instances respond like TZInfo::Timezone instances
316
+ def period_for_local(time, dst=true)
317
+ tzinfo.period_for_local(time, dst)
318
+ end
319
+
320
+ # TODO: Preload instead of lazy load for thread safety
321
+ def self.find_tzinfo(name)
322
+ require 'active_support/tzinfo' unless defined?(::TZInfo)
323
+ ::TZInfo::TimezoneProxy.new(MAPPING[name] || name)
324
+ end
325
+
326
+ class << self
327
+ alias_method :create, :new
328
+
329
+ # Return a TimeZone instance with the given name, or +nil+ if no
330
+ # such TimeZone instance exists. (This exists to support the use of
331
+ # this class with the +composed_of+ macro.)
332
+ def new(name)
333
+ self[name]
334
+ end
335
+
336
+ # Return an array of all TimeZone objects. There are multiple
337
+ # TimeZone objects per time zone, in many cases, to make it easier
338
+ # for users to find their own time zone.
339
+ def all
340
+ @zones ||= zones_map.values.sort
341
+ end
342
+
343
+ def zones_map
344
+ @zones_map ||= Hash[MAPPING.map { |place, _| [place, create(place)] }]
345
+ end
346
+
347
+ # Locate a specific time zone object. If the argument is a string, it
348
+ # is interpreted to mean the name of the timezone to locate. If it is a
349
+ # numeric value it is either the hour offset, or the second offset, of the
350
+ # timezone to find. (The first one with that offset will be returned.)
351
+ # Returns +nil+ if no such time zone is known to the system.
352
+ def [](arg)
353
+ case arg
354
+ when String
355
+ zones_map[arg] ||= lookup(arg)
356
+ when Numeric, ActiveSupport::Duration
357
+ arg *= 3600 if arg.abs <= 13
358
+ all.find { |z| z.utc_offset == arg.to_i }
359
+ else
360
+ raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
361
+ end
362
+ end
363
+
364
+ # A convenience method for returning a collection of TimeZone objects
365
+ # for time zones in the USA.
366
+ def us_zones
367
+ @us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
368
+ end
369
+
370
+ private
371
+
372
+ def lookup(name)
373
+ (tzinfo = find_tzinfo(name)) && create(tzinfo.name.freeze)
374
+ end
375
+ end
376
+ end
377
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveSupport
2
+ module VERSION #:nodoc:
3
+ MAJOR = 3
4
+ MINOR = 0
5
+ TINY = 0
6
+ BUILD = "beta4"
7
+
8
+ STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
9
+ end
10
+ end
@@ -0,0 +1,60 @@
1
+ # Extensions to +nil+ which allow for more helpful error messages for people who
2
+ # are new to Rails.
3
+ #
4
+ # Ruby raises NoMethodError if you invoke a method on an object that does not
5
+ # respond to it:
6
+ #
7
+ # $ ruby -e nil.destroy
8
+ # -e:1: undefined method `destroy' for nil:NilClass (NoMethodError)
9
+ #
10
+ # With these extensions, if the method belongs to the public interface of the
11
+ # classes in NilClass::WHINERS the error message suggests which could be the
12
+ # actual intended class:
13
+ #
14
+ # $ rails runner nil.destroy
15
+ # ...
16
+ # You might have expected an instance of ActiveRecord::Base.
17
+ # ...
18
+ #
19
+ # NilClass#id exists in Ruby 1.8 (though it is deprecated). Since +id+ is a fundamental
20
+ # method of Active Record models NilClass#id is redefined as well to raise a RuntimeError
21
+ # and warn the user. She probably wanted a model database identifier and the 4
22
+ # returned by the original method could result in obscure bugs.
23
+ #
24
+ # The flag <tt>config.whiny_nils</tt> determines whether this feature is enabled.
25
+ # By default it is on in development and test modes, and it is off in production
26
+ # mode.
27
+ class NilClass
28
+ METHOD_CLASS_MAP = Hash.new
29
+
30
+ def self.add_whiner(klass)
31
+ methods = klass.public_instance_methods - public_instance_methods
32
+ class_name = klass.name
33
+ methods.each { |method| METHOD_CLASS_MAP[method.to_sym] = class_name }
34
+ end
35
+
36
+ add_whiner ::Array
37
+
38
+ # Raises a RuntimeError when you attempt to call +id+ on +nil+.
39
+ def id
40
+ raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller
41
+ end
42
+
43
+ private
44
+ def method_missing(method, *args, &block)
45
+ if klass = METHOD_CLASS_MAP[method]
46
+ raise_nil_warning_for klass, method, caller
47
+ else
48
+ super
49
+ end
50
+ end
51
+
52
+ # Raises a NoMethodError when you attempt to call a method on +nil+.
53
+ def raise_nil_warning_for(class_name = nil, selector = nil, with_caller = nil)
54
+ message = "You have a nil object when you didn't expect it!"
55
+ message << "\nYou might have expected an instance of #{class_name}." if class_name
56
+ message << "\nThe error occurred while evaluating nil.#{selector}" if selector
57
+
58
+ raise NoMethodError, message, with_caller || caller
59
+ end
60
+ end