csd 0.1.5 → 0.1.6

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 (258) hide show
  1. data/COPYING +1 -2
  2. data/README.rdoc +7 -1
  3. data/Rakefile +7 -2
  4. data/VERSION +1 -1
  5. data/csd.gemspec +18 -216
  6. data/lib/csd.rb +6 -16
  7. data/lib/csd/application.rb +2 -2
  8. data/lib/csd/application/default.rb +15 -14
  9. data/lib/csd/application/default/base.rb +1 -1
  10. data/lib/csd/application/minisip.rb +43 -11
  11. data/lib/csd/application/minisip/about.yml +5 -5
  12. data/lib/csd/application/minisip/base.rb +82 -70
  13. data/lib/csd/application/minisip/error.rb +1 -1
  14. data/lib/csd/application/minisip/options/common.rb +1 -1
  15. data/lib/csd/application/minisip/options/compile.rb +1 -1
  16. data/lib/csd/application/minisip/options/package.rb +1 -1
  17. data/lib/csd/application/minisip/unix.rb +40 -27
  18. data/lib/csd/application/minisip/unix/darwin.rb +12 -0
  19. data/lib/csd/application/minisip/unix/linux.rb +1 -11
  20. data/lib/csd/application/minisip/unix/linux/debian.rb +14 -25
  21. data/lib/csd/application/minisip/unix/linux/debian/ubuntu10.rb +12 -13
  22. data/lib/csd/applications.rb +5 -5
  23. data/lib/csd/commands.rb +164 -89
  24. data/lib/csd/container.rb +61 -0
  25. data/lib/csd/error.rb +10 -1
  26. data/lib/csd/extensions.rb +3 -2
  27. data/lib/csd/extensions/core/array.rb +29 -1
  28. data/lib/csd/extensions/core/dir.rb +15 -24
  29. data/lib/csd/extensions/core/object.rb +10 -2
  30. data/lib/csd/extensions/core/option_parser.rb +22 -3
  31. data/lib/csd/extensions/core/pathname.rb +30 -2
  32. data/lib/csd/extensions/core/string.rb +51 -4
  33. data/lib/csd/extensions/gem/platform.rb +18 -3
  34. data/lib/csd/{options.rb → options_parser.rb} +16 -20
  35. data/lib/csd/path_container.rb +24 -0
  36. data/lib/csd/user_interface.rb +2 -0
  37. data/lib/csd/user_interface/base.rb +26 -0
  38. data/lib/csd/user_interface/cli.rb +37 -0
  39. data/lib/csd/vendor/active_support/MIT-LICENSE +20 -0
  40. data/lib/csd/vendor/active_support/inflector.rb +155 -0
  41. data/lib/csd/vendor/term/GPL2-LICENSE +339 -0
  42. data/lib/csd/vendor/term/ansicolor.rb +113 -0
  43. data/lib/csd/version.rb +13 -4
  44. data/test/application/test_minisip.rb +45 -0
  45. data/test/functional/test_applications.rb +10 -16
  46. data/test/functional/test_commands.rb +260 -23
  47. data/test/unit/test_string.rb +1 -1
  48. metadata +18 -216
  49. data/lib/active_support.rb +0 -75
  50. data/lib/active_support/all.rb +0 -3
  51. data/lib/active_support/backtrace_cleaner.rb +0 -94
  52. data/lib/active_support/base64.rb +0 -42
  53. data/lib/active_support/basic_object.rb +0 -21
  54. data/lib/active_support/benchmarkable.rb +0 -60
  55. data/lib/active_support/buffered_logger.rb +0 -132
  56. data/lib/active_support/builder.rb +0 -6
  57. data/lib/active_support/cache.rb +0 -626
  58. data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
  59. data/lib/active_support/cache/file_store.rb +0 -188
  60. data/lib/active_support/cache/mem_cache_store.rb +0 -191
  61. data/lib/active_support/cache/memory_store.rb +0 -159
  62. data/lib/active_support/cache/strategy/local_cache.rb +0 -164
  63. data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
  64. data/lib/active_support/callbacks.rb +0 -600
  65. data/lib/active_support/concern.rb +0 -29
  66. data/lib/active_support/configurable.rb +0 -36
  67. data/lib/active_support/core_ext.rb +0 -3
  68. data/lib/active_support/core_ext/array.rb +0 -7
  69. data/lib/active_support/core_ext/array/access.rb +0 -46
  70. data/lib/active_support/core_ext/array/conversions.rb +0 -164
  71. data/lib/active_support/core_ext/array/extract_options.rb +0 -29
  72. data/lib/active_support/core_ext/array/grouping.rb +0 -100
  73. data/lib/active_support/core_ext/array/random_access.rb +0 -20
  74. data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
  75. data/lib/active_support/core_ext/array/wrap.rb +0 -22
  76. data/lib/active_support/core_ext/benchmark.rb +0 -7
  77. data/lib/active_support/core_ext/big_decimal.rb +0 -1
  78. data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -27
  79. data/lib/active_support/core_ext/cgi.rb +0 -1
  80. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
  81. data/lib/active_support/core_ext/class.rb +0 -4
  82. data/lib/active_support/core_ext/class/attribute.rb +0 -67
  83. data/lib/active_support/core_ext/class/attribute_accessors.rb +0 -63
  84. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
  85. data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -232
  86. data/lib/active_support/core_ext/class/subclasses.rb +0 -55
  87. data/lib/active_support/core_ext/date/acts_like.rb +0 -8
  88. data/lib/active_support/core_ext/date/calculations.rb +0 -240
  89. data/lib/active_support/core_ext/date/conversions.rb +0 -99
  90. data/lib/active_support/core_ext/date/freeze.rb +0 -31
  91. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -13
  92. data/lib/active_support/core_ext/date_time/calculations.rb +0 -113
  93. data/lib/active_support/core_ext/date_time/conversions.rb +0 -102
  94. data/lib/active_support/core_ext/date_time/zones.rb +0 -17
  95. data/lib/active_support/core_ext/enumerable.rb +0 -119
  96. data/lib/active_support/core_ext/exception.rb +0 -3
  97. data/lib/active_support/core_ext/file.rb +0 -2
  98. data/lib/active_support/core_ext/file/atomic.rb +0 -41
  99. data/lib/active_support/core_ext/file/path.rb +0 -5
  100. data/lib/active_support/core_ext/float.rb +0 -1
  101. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  102. data/lib/active_support/core_ext/hash.rb +0 -8
  103. data/lib/active_support/core_ext/hash/conversions.rb +0 -150
  104. data/lib/active_support/core_ext/hash/deep_merge.rb +0 -16
  105. data/lib/active_support/core_ext/hash/diff.rb +0 -13
  106. data/lib/active_support/core_ext/hash/except.rb +0 -24
  107. data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -14
  108. data/lib/active_support/core_ext/hash/keys.rb +0 -45
  109. data/lib/active_support/core_ext/hash/reverse_merge.rb +0 -28
  110. data/lib/active_support/core_ext/hash/slice.rb +0 -38
  111. data/lib/active_support/core_ext/integer.rb +0 -3
  112. data/lib/active_support/core_ext/integer/inflections.rb +0 -14
  113. data/lib/active_support/core_ext/integer/multiple.rb +0 -6
  114. data/lib/active_support/core_ext/integer/time.rb +0 -39
  115. data/lib/active_support/core_ext/kernel.rb +0 -5
  116. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  117. data/lib/active_support/core_ext/kernel/debugger.rb +0 -16
  118. data/lib/active_support/core_ext/kernel/reporting.rb +0 -62
  119. data/lib/active_support/core_ext/kernel/requires.rb +0 -26
  120. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
  121. data/lib/active_support/core_ext/load_error.rb +0 -23
  122. data/lib/active_support/core_ext/logger.rb +0 -146
  123. data/lib/active_support/core_ext/module.rb +0 -12
  124. data/lib/active_support/core_ext/module/aliasing.rb +0 -70
  125. data/lib/active_support/core_ext/module/anonymous.rb +0 -24
  126. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
  127. data/lib/active_support/core_ext/module/attr_internal.rb +0 -32
  128. data/lib/active_support/core_ext/module/attribute_accessors.rb +0 -66
  129. data/lib/active_support/core_ext/module/delegation.rb +0 -146
  130. data/lib/active_support/core_ext/module/deprecation.rb +0 -9
  131. data/lib/active_support/core_ext/module/introspection.rb +0 -88
  132. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  133. data/lib/active_support/core_ext/module/reachable.rb +0 -10
  134. data/lib/active_support/core_ext/module/remove_method.rb +0 -6
  135. data/lib/active_support/core_ext/module/synchronization.rb +0 -42
  136. data/lib/active_support/core_ext/name_error.rb +0 -18
  137. data/lib/active_support/core_ext/numeric.rb +0 -2
  138. data/lib/active_support/core_ext/numeric/bytes.rb +0 -44
  139. data/lib/active_support/core_ext/numeric/time.rb +0 -77
  140. data/lib/active_support/core_ext/object.rb +0 -14
  141. data/lib/active_support/core_ext/object/acts_like.rb +0 -10
  142. data/lib/active_support/core_ext/object/blank.rb +0 -76
  143. data/lib/active_support/core_ext/object/conversions.rb +0 -4
  144. data/lib/active_support/core_ext/object/duplicable.rb +0 -65
  145. data/lib/active_support/core_ext/object/extending.rb +0 -11
  146. data/lib/active_support/core_ext/object/instance_variables.rb +0 -67
  147. data/lib/active_support/core_ext/object/misc.rb +0 -2
  148. data/lib/active_support/core_ext/object/returning.rb +0 -42
  149. data/lib/active_support/core_ext/object/to_param.rb +0 -49
  150. data/lib/active_support/core_ext/object/to_query.rb +0 -27
  151. data/lib/active_support/core_ext/object/try.rb +0 -36
  152. data/lib/active_support/core_ext/object/with_options.rb +0 -26
  153. data/lib/active_support/core_ext/proc.rb +0 -14
  154. data/lib/active_support/core_ext/process.rb +0 -1
  155. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  156. data/lib/active_support/core_ext/range.rb +0 -4
  157. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  158. data/lib/active_support/core_ext/range/conversions.rb +0 -21
  159. data/lib/active_support/core_ext/range/include_range.rb +0 -21
  160. data/lib/active_support/core_ext/range/overlaps.rb +0 -8
  161. data/lib/active_support/core_ext/regexp.rb +0 -5
  162. data/lib/active_support/core_ext/rexml.rb +0 -46
  163. data/lib/active_support/core_ext/string.rb +0 -12
  164. data/lib/active_support/core_ext/string/access.rb +0 -99
  165. data/lib/active_support/core_ext/string/behavior.rb +0 -7
  166. data/lib/active_support/core_ext/string/conversions.rb +0 -61
  167. data/lib/active_support/core_ext/string/encoding.rb +0 -11
  168. data/lib/active_support/core_ext/string/exclude.rb +0 -6
  169. data/lib/active_support/core_ext/string/filters.rb +0 -49
  170. data/lib/active_support/core_ext/string/inflections.rb +0 -149
  171. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  172. data/lib/active_support/core_ext/string/multibyte.rb +0 -72
  173. data/lib/active_support/core_ext/string/output_safety.rb +0 -109
  174. data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -4
  175. data/lib/active_support/core_ext/string/xchar.rb +0 -18
  176. data/lib/active_support/core_ext/time/acts_like.rb +0 -8
  177. data/lib/active_support/core_ext/time/calculations.rb +0 -282
  178. data/lib/active_support/core_ext/time/conversions.rb +0 -85
  179. data/lib/active_support/core_ext/time/marshal.rb +0 -56
  180. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  181. data/lib/active_support/core_ext/time/zones.rb +0 -78
  182. data/lib/active_support/core_ext/uri.rb +0 -22
  183. data/lib/active_support/dependencies.rb +0 -628
  184. data/lib/active_support/dependencies/autoload.rb +0 -50
  185. data/lib/active_support/deprecation.rb +0 -18
  186. data/lib/active_support/deprecation/behaviors.rb +0 -38
  187. data/lib/active_support/deprecation/method_wrappers.rb +0 -29
  188. data/lib/active_support/deprecation/proxy_wrappers.rb +0 -74
  189. data/lib/active_support/deprecation/reporting.rb +0 -56
  190. data/lib/active_support/duration.rb +0 -105
  191. data/lib/active_support/gzip.rb +0 -25
  192. data/lib/active_support/hash_with_indifferent_access.rb +0 -145
  193. data/lib/active_support/i18n.rb +0 -8
  194. data/lib/active_support/inflections.rb +0 -56
  195. data/lib/active_support/inflector.rb +0 -7
  196. data/lib/active_support/inflector/inflections.rb +0 -211
  197. data/lib/active_support/inflector/methods.rb +0 -141
  198. data/lib/active_support/inflector/transliterate.rb +0 -97
  199. data/lib/active_support/json.rb +0 -2
  200. data/lib/active_support/json/backends/jsongem.rb +0 -43
  201. data/lib/active_support/json/backends/yajl.rb +0 -40
  202. data/lib/active_support/json/backends/yaml.rb +0 -90
  203. data/lib/active_support/json/decoding.rb +0 -51
  204. data/lib/active_support/json/encoding.rb +0 -254
  205. data/lib/active_support/json/variable.rb +0 -11
  206. data/lib/active_support/lazy_load_hooks.rb +0 -27
  207. data/lib/active_support/locale/en.yml +0 -36
  208. data/lib/active_support/memoizable.rb +0 -103
  209. data/lib/active_support/message_encryptor.rb +0 -71
  210. data/lib/active_support/message_verifier.rb +0 -62
  211. data/lib/active_support/multibyte.rb +0 -44
  212. data/lib/active_support/multibyte/chars.rb +0 -480
  213. data/lib/active_support/multibyte/exceptions.rb +0 -8
  214. data/lib/active_support/multibyte/unicode.rb +0 -393
  215. data/lib/active_support/multibyte/utils.rb +0 -60
  216. data/lib/active_support/notifications.rb +0 -81
  217. data/lib/active_support/notifications/fanout.rb +0 -93
  218. data/lib/active_support/notifications/instrumenter.rb +0 -56
  219. data/lib/active_support/option_merger.rb +0 -25
  220. data/lib/active_support/ordered_hash.rb +0 -158
  221. data/lib/active_support/ordered_options.rb +0 -27
  222. data/lib/active_support/railtie.rb +0 -100
  223. data/lib/active_support/rescuable.rb +0 -114
  224. data/lib/active_support/ruby/shim.rb +0 -22
  225. data/lib/active_support/secure_random.rb +0 -199
  226. data/lib/active_support/string_inquirer.rb +0 -21
  227. data/lib/active_support/test_case.rb +0 -42
  228. data/lib/active_support/testing/assertions.rb +0 -82
  229. data/lib/active_support/testing/declarative.rb +0 -40
  230. data/lib/active_support/testing/default.rb +0 -9
  231. data/lib/active_support/testing/deprecation.rb +0 -55
  232. data/lib/active_support/testing/isolation.rb +0 -154
  233. data/lib/active_support/testing/pending.rb +0 -48
  234. data/lib/active_support/testing/performance.rb +0 -455
  235. data/lib/active_support/testing/setup_and_teardown.rb +0 -111
  236. data/lib/active_support/time.rb +0 -34
  237. data/lib/active_support/time/autoload.rb +0 -5
  238. data/lib/active_support/time_with_zone.rb +0 -341
  239. data/lib/active_support/values/time_zone.rb +0 -377
  240. data/lib/active_support/values/unicode_tables.dat +0 -0
  241. data/lib/active_support/version.rb +0 -10
  242. data/lib/active_support/whiny_nil.rb +0 -60
  243. data/lib/active_support/xml_mini.rb +0 -158
  244. data/lib/active_support/xml_mini/jdom.rb +0 -168
  245. data/lib/active_support/xml_mini/libxml.rb +0 -80
  246. data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
  247. data/lib/active_support/xml_mini/nokogiri.rb +0 -78
  248. data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
  249. data/lib/active_support/xml_mini/rexml.rb +0 -129
  250. data/lib/csd/extensions/core/file.rb +0 -14
  251. data/lib/csd/global_open_struct.rb +0 -19
  252. data/lib/csd/path.rb +0 -32
  253. data/lib/csd/ui.rb +0 -2
  254. data/lib/csd/ui/cli.rb +0 -8
  255. data/lib/csd/ui/ui.rb +0 -45
  256. data/lib/term/ansicolor.rb +0 -102
  257. data/lib/term/ansicolor/.keep +0 -0
  258. data/lib/term/ansicolor/version.rb +0 -10
@@ -1,113 +0,0 @@
1
- require 'rational' unless RUBY_VERSION >= '1.9.2'
2
- require 'active_support/core_ext/object/acts_like'
3
-
4
- class DateTime
5
- class << self
6
- # DateTimes aren't aware of DST rules, so use a consistent non-DST offset when creating a DateTime with an offset in the local zone
7
- def local_offset
8
- ::Time.local(2007).utc_offset.to_r / 86400
9
- end
10
-
11
- def current
12
- ::Time.zone_default ? ::Time.zone.now.to_datetime : ::Time.now.to_datetime
13
- end
14
- end
15
-
16
- # Tells whether the DateTime object's datetime lies in the past
17
- def past?
18
- self < ::DateTime.current
19
- end
20
-
21
- # Tells whether the DateTime object's datetime lies in the future
22
- def future?
23
- self > ::DateTime.current
24
- end
25
-
26
- # Seconds since midnight: DateTime.now.seconds_since_midnight
27
- def seconds_since_midnight
28
- sec + (min * 60) + (hour * 3600)
29
- end
30
-
31
- # Returns a new DateTime where one or more of the elements have been changed according to the +options+ parameter. The time options
32
- # (hour, minute, sec) reset cascadingly, so if only the hour is passed, then minute and sec is set to 0. If the hour and
33
- # minute is passed, then sec is set to 0.
34
- def change(options)
35
- ::DateTime.civil(
36
- options[:year] || year,
37
- options[:month] || month,
38
- options[:day] || day,
39
- options[:hour] || hour,
40
- options[:min] || (options[:hour] ? 0 : min),
41
- options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
42
- options[:offset] || offset,
43
- options[:start] || start
44
- )
45
- end
46
-
47
- # Uses Date to provide precise Time calculations for years, months, and days.
48
- # The +options+ parameter takes a hash with any of these keys: <tt>:years</tt>,
49
- # <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, <tt>:hours</tt>,
50
- # <tt>:minutes</tt>, <tt>:seconds</tt>.
51
- def advance(options)
52
- d = to_date.advance(options)
53
- datetime_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
54
- seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
55
- seconds_to_advance == 0 ? datetime_advanced_by_date : datetime_advanced_by_date.since(seconds_to_advance)
56
- end
57
-
58
- # Returns a new DateTime representing the time a number of seconds ago
59
- # Do not use this method in combination with x.months, use months_ago instead!
60
- def ago(seconds)
61
- since(-seconds)
62
- end
63
-
64
- # Returns a new DateTime representing the time a number of seconds since the instance time
65
- # Do not use this method in combination with x.months, use months_since instead!
66
- def since(seconds)
67
- self + Rational(seconds.round, 86400)
68
- end
69
- alias :in :since
70
-
71
- # Returns a new DateTime representing the start of the day (0:00)
72
- def beginning_of_day
73
- change(:hour => 0)
74
- end
75
- alias :midnight :beginning_of_day
76
- alias :at_midnight :beginning_of_day
77
- alias :at_beginning_of_day :beginning_of_day
78
-
79
- # Returns a new DateTime representing the end of the day (23:59:59)
80
- def end_of_day
81
- change(:hour => 23, :min => 59, :sec => 59)
82
- end
83
-
84
- # Adjusts DateTime to UTC by adding its offset value; offset is set to 0
85
- #
86
- # Example:
87
- #
88
- # DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)) # => Mon, 21 Feb 2005 10:11:12 -0600
89
- # DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc # => Mon, 21 Feb 2005 16:11:12 +0000
90
- def utc
91
- new_offset(0)
92
- end
93
- alias_method :getutc, :utc
94
-
95
- # Returns true if offset == 0
96
- def utc?
97
- offset == 0
98
- end
99
-
100
- # Returns the offset value in seconds
101
- def utc_offset
102
- (offset * 86400).to_i
103
- end
104
-
105
- # Layers additional behavior on DateTime#<=> so that Time and ActiveSupport::TimeWithZone instances can be compared with a DateTime
106
- def compare_with_coercion(other)
107
- other = other.comparable_time if other.respond_to?(:comparable_time)
108
- other = other.to_datetime unless other.acts_like?(:date)
109
- compare_without_coercion(other)
110
- end
111
- alias_method :compare_without_coercion, :<=>
112
- alias_method :<=>, :compare_with_coercion
113
- end
@@ -1,102 +0,0 @@
1
- require 'active_support/inflector'
2
- require 'active_support/core_ext/time/conversions'
3
- require 'active_support/core_ext/date_time/calculations'
4
-
5
- class DateTime
6
- # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
7
- # DateTimes outside the range of what can be created with Time.
8
- remove_method :to_time if instance_methods.include?(:to_time)
9
-
10
- # Convert to a formatted string. See Time::DATE_FORMATS for predefined formats.
11
- #
12
- # This method is aliased to <tt>to_s</tt>.
13
- #
14
- # === Examples
15
- # datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
16
- #
17
- # datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
18
- # datetime.to_s(:db) # => "2007-12-04 00:00:00"
19
- # datetime.to_s(:number) # => "20071204000000"
20
- # datetime.to_formatted_s(:short) # => "04 Dec 00:00"
21
- # datetime.to_formatted_s(:long) # => "December 04, 2007 00:00"
22
- # datetime.to_formatted_s(:long_ordinal) # => "December 4th, 2007 00:00"
23
- # datetime.to_formatted_s(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"
24
- #
25
- # == Adding your own datetime formats to to_formatted_s
26
- # DateTime formats are shared with Time. You can add your own to the
27
- # Time::DATE_FORMATS hash. Use the format name as the hash key and
28
- # either a strftime string or Proc instance that takes a time or
29
- # datetime argument as the value.
30
- #
31
- # # config/initializers/time_formats.rb
32
- # Time::DATE_FORMATS[:month_and_year] = "%B %Y"
33
- # Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") }
34
- def to_formatted_s(format = :default)
35
- if formatter = ::Time::DATE_FORMATS[format]
36
- formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
37
- else
38
- to_default_s
39
- end
40
- end
41
- alias_method :to_default_s, :to_s unless (instance_methods(false) & [:to_s, 'to_s']).empty?
42
- alias_method :to_s, :to_formatted_s
43
-
44
- # Returns the +utc_offset+ as an +HH:MM formatted string. Examples:
45
- #
46
- # datetime = DateTime.civil(2000, 1, 1, 0, 0, 0, Rational(-6, 24))
47
- # datetime.formatted_offset # => "-06:00"
48
- # datetime.formatted_offset(false) # => "-0600"
49
- def formatted_offset(colon = true, alternate_utc_string = nil)
50
- utc? && alternate_utc_string || ActiveSupport::TimeZone.seconds_to_utc_offset(utc_offset, colon)
51
- end
52
-
53
- # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000"
54
- def readable_inspect
55
- to_s(:rfc822)
56
- end
57
- alias_method :default_inspect, :inspect
58
- alias_method :inspect, :readable_inspect
59
-
60
- # Converts self to a Ruby Date object; time portion is discarded
61
- def to_date
62
- ::Date.new(year, month, day)
63
- end unless instance_methods(false).include?(:to_date)
64
-
65
- # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class
66
- # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
67
- def to_time
68
- self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self
69
- end
70
-
71
- # To be able to keep Times, Dates and DateTimes interchangeable on conversions
72
- def to_datetime
73
- self
74
- end unless instance_methods(false).include?(:to_datetime)
75
-
76
- def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0)
77
- offset = utc_or_local.to_sym == :local ? local_offset : 0
78
- civil(year, month, day, hour, min, sec, offset)
79
- end
80
-
81
- # Converts datetime to an appropriate format for use in XML
82
- def xmlschema
83
- strftime("%Y-%m-%dT%H:%M:%S%Z")
84
- end unless instance_methods(false).include?(:xmlschema)
85
-
86
- # Converts self to a floating-point number of seconds since the Unix epoch
87
- def to_f
88
- seconds_since_unix_epoch.to_f
89
- end
90
-
91
- # Converts self to an integer number of seconds since the Unix epoch
92
- def to_i
93
- seconds_since_unix_epoch.to_i
94
- end
95
-
96
- private
97
-
98
- def seconds_since_unix_epoch
99
- seconds_per_day = 86_400
100
- (self - ::DateTime.civil(1970)) * seconds_per_day
101
- end
102
- end
@@ -1,17 +0,0 @@
1
- class DateTime
2
- # Returns the simultaneous time in <tt>Time.zone</tt>.
3
- #
4
- # Time.zone = 'Hawaii' # => 'Hawaii'
5
- # DateTime.new(2000).in_time_zone # => Fri, 31 Dec 1999 14:00:00 HST -10:00
6
- #
7
- # This method is similar to Time#localtime, except that it uses <tt>Time.zone</tt> as the local zone
8
- # instead of the operating system's time zone.
9
- #
10
- # You can also pass in a TimeZone instance or string that identifies a TimeZone as an argument,
11
- # and the conversion will be based on that zone instead of <tt>Time.zone</tt>.
12
- #
13
- # DateTime.new(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00
14
- def in_time_zone(zone = ::Time.zone)
15
- ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.__send__(:get_zone, zone))
16
- end
17
- end
@@ -1,119 +0,0 @@
1
- require 'active_support/ordered_hash'
2
-
3
- module Enumerable
4
- # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
5
- remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9'
6
-
7
- # Collect an enumerable into sets, grouped by the result of a block. Useful,
8
- # for example, for grouping records by date.
9
- #
10
- # Example:
11
- #
12
- # latest_transcripts.group_by(&:day).each do |day, transcripts|
13
- # p "#{day} -> #{transcripts.map(&:class).join(', ')}"
14
- # end
15
- # "2006-03-01 -> Transcript"
16
- # "2006-02-28 -> Transcript"
17
- # "2006-02-27 -> Transcript, Transcript"
18
- # "2006-02-26 -> Transcript, Transcript"
19
- # "2006-02-25 -> Transcript"
20
- # "2006-02-24 -> Transcript, Transcript"
21
- # "2006-02-23 -> Transcript"
22
- def group_by
23
- assoc = ActiveSupport::OrderedHash.new
24
-
25
- each do |element|
26
- key = yield(element)
27
-
28
- if assoc.has_key?(key)
29
- assoc[key] << element
30
- else
31
- assoc[key] = [element]
32
- end
33
- end
34
-
35
- assoc
36
- end unless [].respond_to?(:group_by)
37
-
38
- # Calculates a sum from the elements. Examples:
39
- #
40
- # payments.sum { |p| p.price * p.tax_rate }
41
- # payments.sum(&:price)
42
- #
43
- # The latter is a shortcut for:
44
- #
45
- # payments.inject(0) { |sum, p| sum + p.price }
46
- #
47
- # It can also calculate the sum without the use of a block.
48
- #
49
- # [5, 15, 10].sum # => 30
50
- # ["foo", "bar"].sum # => "foobar"
51
- # [[1, 2], [3, 1, 5]].sum => [1, 2, 3, 1, 5]
52
- #
53
- # The default sum of an empty list is zero. You can override this default:
54
- #
55
- # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
56
- #
57
- def sum(identity = 0, &block)
58
- if block_given?
59
- map(&block).sum(identity)
60
- else
61
- inject { |sum, element| sum + element } || identity
62
- end
63
- end
64
-
65
- # Iterates over a collection, passing the current element *and* the
66
- # +memo+ to the block. Handy for building up hashes or
67
- # reducing collections down to one object. Examples:
68
- #
69
- # %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'}
70
- #
71
- # *Note* that you can't use immutable objects like numbers, true or false as
72
- # the memo. You would think the following returns 120, but since the memo is
73
- # never changed, it does not.
74
- #
75
- # (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1
76
- #
77
- def each_with_object(memo, &block)
78
- each do |element|
79
- block.call(element, memo)
80
- end
81
- memo
82
- end unless [].respond_to?(:each_with_object)
83
-
84
- # Convert an enumerable to a hash. Examples:
85
- #
86
- # people.index_by(&:login)
87
- # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...}
88
- # people.index_by { |person| "#{person.first_name} #{person.last_name}" }
89
- # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
90
- #
91
- def index_by
92
- inject({}) do |accum, elem|
93
- accum[yield(elem)] = elem
94
- accum
95
- end
96
- end
97
-
98
- # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1.
99
- # Works with a block too ala any?, so people.many? { |p| p.age > 26 } # => returns true if more than 1 person is over 26.
100
- def many?(&block)
101
- size = block_given? ? select(&block).size : self.size
102
- size > 1
103
- end
104
-
105
- # The negative of the Enumerable#include?. Returns true if the collection does not include the object.
106
- def exclude?(object)
107
- !include?(object)
108
- end
109
- end
110
-
111
- class Range #:nodoc:
112
- # Optimize range sum to use arithmetic progression if a block is not given and
113
- # we have a range of numeric values.
114
- def sum(identity = 0)
115
- return super if block_given? || !(first.instance_of?(Integer) && last.instance_of?(Integer))
116
- actual_last = exclude_end? ? (last - 1) : last
117
- (actual_last - first + 1) * (actual_last + first) / 2
118
- end
119
- end
@@ -1,3 +0,0 @@
1
- module ActiveSupport
2
- FrozenObjectError = RUBY_VERSION < '1.9' ? TypeError : RuntimeError
3
- end
@@ -1,2 +0,0 @@
1
- require 'active_support/core_ext/file/atomic'
2
- require 'active_support/core_ext/file/path'
@@ -1,41 +0,0 @@
1
- class File
2
- # Write to a file atomically. Useful for situations where you don't
3
- # want other processes or threads to see half-written files.
4
- #
5
- # File.atomic_write("important.file") do |file|
6
- # file.write("hello")
7
- # end
8
- #
9
- # If your temp directory is not on the same filesystem as the file you're
10
- # trying to write, you can provide a different temporary directory.
11
- #
12
- # File.atomic_write("/data/something.important", "/data/tmp") do |file|
13
- # file.write("hello")
14
- # end
15
- def self.atomic_write(file_name, temp_dir = Dir.tmpdir)
16
- require 'tempfile' unless defined?(Tempfile)
17
- require 'fileutils' unless defined?(FileUtils)
18
-
19
- temp_file = Tempfile.new(basename(file_name), temp_dir)
20
- yield temp_file
21
- temp_file.close
22
-
23
- begin
24
- # Get original file permissions
25
- old_stat = stat(file_name)
26
- rescue Errno::ENOENT
27
- # No old permissions, write a temp file to determine the defaults
28
- check_name = join(dirname(file_name), ".permissions_check.#{Thread.current.object_id}.#{Process.pid}.#{rand(1000000)}")
29
- open(check_name, "w") { }
30
- old_stat = stat(check_name)
31
- unlink(check_name)
32
- end
33
-
34
- # Overwrite original file with temp file
35
- FileUtils.mv(temp_file.path, file_name)
36
-
37
- # Set correct permissions on new file
38
- chown(old_stat.uid, old_stat.gid, file_name)
39
- chmod(old_stat.mode, file_name)
40
- end
41
- end
@@ -1,5 +0,0 @@
1
- class File
2
- unless File.allocate.respond_to?(:to_path)
3
- alias to_path path
4
- end
5
- end
@@ -1 +0,0 @@
1
- require 'active_support/core_ext/float/rounding'
@@ -1,19 +0,0 @@
1
- class Float
2
- alias precisionless_round round
3
- private :precisionless_round
4
-
5
- # Rounds the float with the specified precision.
6
- #
7
- # x = 1.337
8
- # x.round # => 1
9
- # x.round(1) # => 1.3
10
- # x.round(2) # => 1.34
11
- def round(precision = nil)
12
- if precision
13
- magnitude = 10.0 ** precision
14
- (self * magnitude).round / magnitude
15
- else
16
- precisionless_round
17
- end
18
- end
19
- end
@@ -1,8 +0,0 @@
1
- require 'active_support/core_ext/hash/conversions'
2
- require 'active_support/core_ext/hash/deep_merge'
3
- require 'active_support/core_ext/hash/diff'
4
- require 'active_support/core_ext/hash/except'
5
- require 'active_support/core_ext/hash/indifferent_access'
6
- require 'active_support/core_ext/hash/keys'
7
- require 'active_support/core_ext/hash/reverse_merge'
8
- require 'active_support/core_ext/hash/slice'
@@ -1,150 +0,0 @@
1
- require 'active_support/xml_mini'
2
- require 'active_support/time'
3
- require 'active_support/core_ext/array/wrap'
4
- require 'active_support/core_ext/hash/reverse_merge'
5
- require 'active_support/core_ext/object/blank'
6
- require 'active_support/core_ext/string/inflections'
7
-
8
- class Hash
9
- # Returns a string containing an XML representation of its receiver:
10
- #
11
- # {"foo" => 1, "bar" => 2}.to_xml
12
- # # =>
13
- # # <?xml version="1.0" encoding="UTF-8"?>
14
- # # <hash>
15
- # # <foo type="integer">1</foo>
16
- # # <bar type="integer">2</bar>
17
- # # </hash>
18
- #
19
- # To do so, the method loops over the pairs and builds nodes that depend on
20
- # the _values_. Given a pair +key+, +value+:
21
- #
22
- # * If +value+ is a hash there's a recursive call with +key+ as <tt>:root</tt>.
23
- #
24
- # * If +value+ is an array there's a recursive call with +key+ as <tt>:root</tt>,
25
- # and +key+ singularized as <tt>:children</tt>.
26
- #
27
- # * If +value+ is a callable object it must expect one or two arguments. Depending
28
- # on the arity, the callable is invoked with the +options+ hash as first argument
29
- # with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. Its
30
- # return value becomes a new node.
31
- #
32
- # * If +value+ responds to +to_xml+ the method is invoked with +key+ as <tt>:root</tt>.
33
- #
34
- # * Otherwise, a node with +key+ as tag is created with a string representation of
35
- # +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added.
36
- # Unless the option <tt>:skip_types</tt> exists and is true, an attribute "type" is
37
- # added as well according to the following mapping:
38
- #
39
- # XML_TYPE_NAMES = {
40
- # "Symbol" => "symbol",
41
- # "Fixnum" => "integer",
42
- # "Bignum" => "integer",
43
- # "BigDecimal" => "decimal",
44
- # "Float" => "float",
45
- # "TrueClass" => "boolean",
46
- # "FalseClass" => "boolean",
47
- # "Date" => "date",
48
- # "DateTime" => "datetime",
49
- # "Time" => "datetime"
50
- # }
51
- #
52
- # By default the root node is "hash", but that's configurable via the <tt>:root</tt> option.
53
- #
54
- # The default XML builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can
55
- # configure your own builder with the <tt>:builder</tt> option. The method also accepts
56
- # options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.
57
- def to_xml(options = {})
58
- require 'active_support/builder' unless defined?(Builder)
59
-
60
- options = options.dup
61
- options[:indent] ||= 2
62
- options[:root] ||= "hash"
63
- options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
64
-
65
- builder = options[:builder]
66
- builder.instruct! unless options.delete(:skip_instruct)
67
-
68
- root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
69
-
70
- builder.__send__(:method_missing, root) do
71
- each { |key, value| ActiveSupport::XmlMini.to_tag(key, value, options) }
72
- yield builder if block_given?
73
- end
74
- end
75
-
76
- class << self
77
- def from_xml(xml)
78
- typecast_xml_value(unrename_keys(ActiveSupport::XmlMini.parse(xml)))
79
- end
80
-
81
- private
82
- def typecast_xml_value(value)
83
- case value.class.to_s
84
- when 'Hash'
85
- if value['type'] == 'array'
86
- child_key, entries = Array.wrap(value.detect { |k,v| k != 'type' }) # child_key is throwaway
87
- if entries.nil? || (c = value['__content__'] && c.blank?)
88
- []
89
- else
90
- case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a?
91
- when "Array"
92
- entries.collect { |v| typecast_xml_value(v) }
93
- when "Hash"
94
- [typecast_xml_value(entries)]
95
- else
96
- raise "can't typecast #{entries.inspect}"
97
- end
98
- end
99
- elsif value.has_key?("__content__")
100
- content = value["__content__"]
101
- if parser = ActiveSupport::XmlMini::PARSING[value["type"]]
102
- parser.arity == 1 ? parser.call(content) : parser.call(content, value)
103
- else
104
- content
105
- end
106
- elsif value['type'] == 'string' && value['nil'] != 'true'
107
- ""
108
- # blank or nil parsed values are represented by nil
109
- elsif value.blank? || value['nil'] == 'true'
110
- nil
111
- # If the type is the only element which makes it then
112
- # this still makes the value nil, except if type is
113
- # a XML node(where type['value'] is a Hash)
114
- elsif value['type'] && value.size == 1 && !value['type'].is_a?(::Hash)
115
- nil
116
- else
117
- xml_value = value.inject({}) do |h,(k,v)|
118
- h[k] = typecast_xml_value(v)
119
- h
120
- end
121
-
122
- # Turn { :files => { :file => #<StringIO> } into { :files => #<StringIO> } so it is compatible with
123
- # how multipart uploaded files from HTML appear
124
- xml_value["file"].is_a?(StringIO) ? xml_value["file"] : xml_value
125
- end
126
- when 'Array'
127
- value.map! { |i| typecast_xml_value(i) }
128
- value.length > 1 ? value : value.first
129
- when 'String'
130
- value
131
- else
132
- raise "can't typecast #{value.class.name} - #{value.inspect}"
133
- end
134
- end
135
-
136
- def unrename_keys(params)
137
- case params.class.to_s
138
- when "Hash"
139
- params.inject({}) do |h,(k,v)|
140
- h[k.to_s.tr("-", "_")] = unrename_keys(v)
141
- h
142
- end
143
- when "Array"
144
- params.map { |v| unrename_keys(v) }
145
- else
146
- params
147
- end
148
- end
149
- end
150
- end