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,55 +0,0 @@
1
- require 'active_support/core_ext/module/anonymous'
2
- require 'active_support/core_ext/module/reachable'
3
-
4
- class Class #:nodoc:
5
- # Returns an array with the names of the subclasses of +self+ as strings.
6
- #
7
- # Integer.subclasses # => ["Bignum", "Fixnum"]
8
- def subclasses
9
- Class.subclasses_of(self).map { |o| o.to_s }
10
- end
11
-
12
- # Rubinius
13
- if defined?(Class.__subclasses__)
14
- def descendents
15
- subclasses = []
16
- __subclasses__.each {|k| subclasses << k; subclasses.concat k.descendents }
17
- subclasses
18
- end
19
- else
20
- # MRI
21
- begin
22
- ObjectSpace.each_object(Class.new) {}
23
-
24
- def descendents
25
- subclasses = []
26
- ObjectSpace.each_object(class << self; self; end) do |k|
27
- subclasses << k unless k == self
28
- end
29
- subclasses
30
- end
31
- # JRuby
32
- rescue StandardError
33
- def descendents
34
- subclasses = []
35
- ObjectSpace.each_object(Class) do |k|
36
- subclasses << k if k < self
37
- end
38
- subclasses.uniq!
39
- subclasses
40
- end
41
- end
42
- end
43
-
44
- # Exclude this class unless it's a subclass of our supers and is defined.
45
- # We check defined? in case we find a removed class that has yet to be
46
- # garbage collected. This also fails for anonymous classes -- please
47
- # submit a patch if you have a workaround.
48
- def self.subclasses_of(*superclasses) #:nodoc:
49
- subclasses = []
50
- superclasses.each do |klass|
51
- subclasses.concat klass.descendents.select {|k| k.anonymous? || k.reachable?}
52
- end
53
- subclasses
54
- end
55
- end
@@ -1,8 +0,0 @@
1
- require 'active_support/core_ext/object/acts_like'
2
-
3
- class Date
4
- # Duck-types as a Date-like class. See Object#acts_like?.
5
- def acts_like_date?
6
- true
7
- end
8
- end
@@ -1,240 +0,0 @@
1
- require 'date'
2
- require 'active_support/duration'
3
- require 'active_support/core_ext/time/zones'
4
- require 'active_support/core_ext/object/acts_like'
5
-
6
- class Date
7
- if RUBY_VERSION < '1.9'
8
- undef :>>
9
-
10
- # Backported from 1.9. The one in 1.8 leads to incorrect next_month and
11
- # friends for dates where the calendar reform is involved. It additionally
12
- # prevents an infinite loop fixed in r27013.
13
- def >>(n)
14
- y, m = (year * 12 + (mon - 1) + n).divmod(12)
15
- m, = (m + 1) .divmod(1)
16
- d = mday
17
- until jd2 = self.class.valid_civil?(y, m, d, start)
18
- d -= 1
19
- raise ArgumentError, 'invalid date' unless d > 0
20
- end
21
- self + (jd2 - jd)
22
- end
23
- end
24
-
25
- class << self
26
- # Returns a new Date representing the date 1 day ago (i.e. yesterday's date).
27
- def yesterday
28
- ::Date.current.yesterday
29
- end
30
-
31
- # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date).
32
- def tomorrow
33
- ::Date.current.tomorrow
34
- end
35
-
36
- # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today.
37
- def current
38
- ::Time.zone_default ? ::Time.zone.today : ::Date.today
39
- end
40
- end
41
-
42
- # Tells whether the Date object's date lies in the past
43
- def past?
44
- self < ::Date.current
45
- end
46
-
47
- # Tells whether the Date object's date is today
48
- def today?
49
- self.to_date == ::Date.current # we need the to_date because of DateTime
50
- end
51
-
52
- # Tells whether the Date object's date lies in the future
53
- def future?
54
- self > ::Date.current
55
- end
56
-
57
- # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
58
- # and then subtracts the specified number of seconds
59
- def ago(seconds)
60
- to_time.since(-seconds)
61
- end
62
-
63
- # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
64
- # and then adds the specified number of seconds
65
- def since(seconds)
66
- to_time.since(seconds)
67
- end
68
- alias :in :since
69
-
70
- # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
71
- def beginning_of_day
72
- to_time
73
- end
74
- alias :midnight :beginning_of_day
75
- alias :at_midnight :beginning_of_day
76
- alias :at_beginning_of_day :beginning_of_day
77
-
78
- # Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59)
79
- def end_of_day
80
- to_time.end_of_day
81
- end
82
-
83
- def plus_with_duration(other) #:nodoc:
84
- if ActiveSupport::Duration === other
85
- other.since(self)
86
- else
87
- plus_without_duration(other)
88
- end
89
- end
90
- alias_method :plus_without_duration, :+
91
- alias_method :+, :plus_with_duration
92
-
93
- def minus_with_duration(other) #:nodoc:
94
- if ActiveSupport::Duration === other
95
- plus_with_duration(-other)
96
- else
97
- minus_without_duration(other)
98
- end
99
- end
100
- alias_method :minus_without_duration, :-
101
- alias_method :-, :minus_with_duration
102
-
103
- # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
104
- # any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
105
- def advance(options)
106
- options = options.dup
107
- d = self
108
- d = d >> options.delete(:years) * 12 if options[:years]
109
- d = d >> options.delete(:months) if options[:months]
110
- d = d + options.delete(:weeks) * 7 if options[:weeks]
111
- d = d + options.delete(:days) if options[:days]
112
- d
113
- end
114
-
115
- # Returns a new Date where one or more of the elements have been changed according to the +options+ parameter.
116
- #
117
- # Examples:
118
- #
119
- # Date.new(2007, 5, 12).change(:day => 1) # => Date.new(2007, 5, 1)
120
- # Date.new(2007, 5, 12).change(:year => 2005, :month => 1) # => Date.new(2005, 1, 12)
121
- def change(options)
122
- ::Date.new(
123
- options[:year] || self.year,
124
- options[:month] || self.month,
125
- options[:day] || self.day
126
- )
127
- end
128
-
129
- # Returns a new Date/DateTime representing the time a number of specified months ago
130
- def months_ago(months)
131
- advance(:months => -months)
132
- end
133
-
134
- # Returns a new Date/DateTime representing the time a number of specified months in the future
135
- def months_since(months)
136
- advance(:months => months)
137
- end
138
-
139
- # Returns a new Date/DateTime representing the time a number of specified years ago
140
- def years_ago(years)
141
- advance(:years => -years)
142
- end
143
-
144
- # Returns a new Date/DateTime representing the time a number of specified years in the future
145
- def years_since(years)
146
- advance(:years => years)
147
- end
148
-
149
- # Shorthand for years_ago(1)
150
- def prev_year
151
- years_ago(1)
152
- end unless method_defined?(:prev_year)
153
-
154
- # Short-hand for years_since(1)
155
- def next_year
156
- years_since(1)
157
- end unless method_defined?(:next_year)
158
-
159
- # Short-hand for months_ago(1)
160
- def prev_month
161
- months_ago(1)
162
- end unless method_defined?(:prev_month)
163
-
164
- # Short-hand for months_since(1)
165
- def next_month
166
- months_since(1)
167
- end unless method_defined?(:next_month)
168
-
169
- # Returns a new Date/DateTime representing the "start" of this week (i.e, Monday; DateTime objects will have time set to 0:00)
170
- def beginning_of_week
171
- days_to_monday = self.wday!=0 ? self.wday-1 : 6
172
- result = self - days_to_monday
173
- self.acts_like?(:time) ? result.midnight : result
174
- end
175
- alias :monday :beginning_of_week
176
- alias :at_beginning_of_week :beginning_of_week
177
-
178
- # Returns a new Date/DateTime representing the end of this week (Sunday, DateTime objects will have time set to 23:59:59)
179
- def end_of_week
180
- days_to_sunday = self.wday!=0 ? 7-self.wday : 0
181
- result = self + days_to_sunday.days
182
- self.acts_like?(:time) ? result.end_of_day : result
183
- end
184
- alias :sunday :end_of_week
185
- alias :at_end_of_week :end_of_week
186
-
187
- # Returns a new Date/DateTime representing the start of the given day in next week (default is Monday).
188
- def next_week(day = :monday)
189
- days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6}
190
- result = (self + 7).beginning_of_week + days_into_week[day]
191
- self.acts_like?(:time) ? result.change(:hour => 0) : result
192
- end
193
-
194
- # Returns a new ; DateTime objects will have time set to 0:00DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00)
195
- def beginning_of_month
196
- self.acts_like?(:time) ? change(:day => 1,:hour => 0, :min => 0, :sec => 0) : change(:day => 1)
197
- end
198
- alias :at_beginning_of_month :beginning_of_month
199
-
200
- # Returns a new Date/DateTime representing the end of the month (last day of the month; DateTime objects will have time set to 0:00)
201
- def end_of_month
202
- last_day = ::Time.days_in_month( self.month, self.year )
203
- self.acts_like?(:time) ? change(:day => last_day, :hour => 23, :min => 59, :sec => 59) : change(:day => last_day)
204
- end
205
- alias :at_end_of_month :end_of_month
206
-
207
- # Returns a new Date/DateTime representing the start of the quarter (1st of january, april, july, october; DateTime objects will have time set to 0:00)
208
- def beginning_of_quarter
209
- beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= self.month })
210
- end
211
- alias :at_beginning_of_quarter :beginning_of_quarter
212
-
213
- # Returns a new Date/DateTime representing the end of the quarter (last day of march, june, september, december; DateTime objects will have time set to 23:59:59)
214
- def end_of_quarter
215
- beginning_of_month.change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month
216
- end
217
- alias :at_end_of_quarter :end_of_quarter
218
-
219
- # Returns a new Date/DateTime representing the start of the year (1st of january; DateTime objects will have time set to 0:00)
220
- def beginning_of_year
221
- self.acts_like?(:time) ? change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0) : change(:month => 1, :day => 1)
222
- end
223
- alias :at_beginning_of_year :beginning_of_year
224
-
225
- # Returns a new Time representing the end of the year (31st of december; DateTime objects will have time set to 23:59:59)
226
- def end_of_year
227
- self.acts_like?(:time) ? change(:month => 12,:day => 31,:hour => 23, :min => 59, :sec => 59) : change(:month => 12, :day => 31)
228
- end
229
- alias :at_end_of_year :end_of_year
230
-
231
- # Convenience method which returns a new Date/DateTime representing the time 1 day ago
232
- def yesterday
233
- self - 1
234
- end
235
-
236
- # Convenience method which returns a new Date/DateTime representing the time 1 day since the instance time
237
- def tomorrow
238
- self + 1
239
- end
240
- end
@@ -1,99 +0,0 @@
1
- require 'date'
2
- require 'active_support/inflector'
3
- require 'active_support/core_ext/time/calculations'
4
-
5
- class Date
6
- DATE_FORMATS = {
7
- :short => "%e %b",
8
- :long => "%B %e, %Y",
9
- :db => "%Y-%m-%d",
10
- :number => "%Y%m%d",
11
- :long_ordinal => lambda { |date| date.strftime("%B #{ActiveSupport::Inflector.ordinalize(date.day)}, %Y") }, # => "April 25th, 2007"
12
- :rfc822 => "%e %b %Y"
13
- }
14
-
15
- # Ruby 1.9 has Date#to_time which converts to localtime only.
16
- remove_method :to_time if instance_methods.include?(:to_time)
17
-
18
- # Ruby 1.9 has Date#xmlschema which converts to a string without the time component.
19
- remove_method :xmlschema if instance_methods.include?(:xmlschema)
20
-
21
- # Convert to a formatted string. See DATE_FORMATS for predefined formats.
22
- #
23
- # This method is aliased to <tt>to_s</tt>.
24
- #
25
- # ==== Examples
26
- # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
27
- #
28
- # date.to_formatted_s(:db) # => "2007-11-10"
29
- # date.to_s(:db) # => "2007-11-10"
30
- #
31
- # date.to_formatted_s(:short) # => "10 Nov"
32
- # date.to_formatted_s(:long) # => "November 10, 2007"
33
- # date.to_formatted_s(:long_ordinal) # => "November 10th, 2007"
34
- # date.to_formatted_s(:rfc822) # => "10 Nov 2007"
35
- #
36
- # == Adding your own time formats to to_formatted_s
37
- # You can add your own formats to the Date::DATE_FORMATS hash.
38
- # Use the format name as the hash key and either a strftime string
39
- # or Proc instance that takes a date argument as the value.
40
- #
41
- # # config/initializers/time_formats.rb
42
- # Date::DATE_FORMATS[:month_and_year] = "%B %Y"
43
- # Date::DATE_FORMATS[:short_ordinal] = lambda { |date| date.strftime("%B #{date.day.ordinalize}") }
44
- def to_formatted_s(format = :default)
45
- if formatter = DATE_FORMATS[format]
46
- if formatter.respond_to?(:call)
47
- formatter.call(self).to_s
48
- else
49
- strftime(formatter)
50
- end
51
- else
52
- to_default_s
53
- end
54
- end
55
- alias_method :to_default_s, :to_s
56
- alias_method :to_s, :to_formatted_s
57
-
58
- # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
59
- def readable_inspect
60
- strftime("%a, %d %b %Y")
61
- end
62
- alias_method :default_inspect, :inspect
63
- alias_method :inspect, :readable_inspect
64
-
65
- # A method to keep Time, Date and DateTime instances interchangeable on conversions.
66
- # In this case, it simply returns +self+.
67
- def to_date
68
- self
69
- end if RUBY_VERSION < '1.9'
70
-
71
- # Converts a Date instance to a Time, where the time is set to the beginning of the day.
72
- # The timezone can be either :local or :utc (default :local).
73
- #
74
- # ==== Examples
75
- # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
76
- #
77
- # date.to_time # => Sat Nov 10 00:00:00 0800 2007
78
- # date.to_time(:local) # => Sat Nov 10 00:00:00 0800 2007
79
- #
80
- # date.to_time(:utc) # => Sat Nov 10 00:00:00 UTC 2007
81
- def to_time(form = :local)
82
- ::Time.send("#{form}_time", year, month, day)
83
- end
84
-
85
- # Converts a Date instance to a DateTime, where the time is set to the beginning of the day
86
- # and UTC offset is set to 0.
87
- #
88
- # ==== Examples
89
- # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
90
- #
91
- # date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000
92
- def to_datetime
93
- ::DateTime.civil(year, month, day, 0, 0, 0, 0)
94
- end if RUBY_VERSION < '1.9'
95
-
96
- def xmlschema
97
- to_time.xmlschema
98
- end
99
- end
@@ -1,31 +0,0 @@
1
- # Date memoizes some instance methods using metaprogramming to wrap
2
- # the methods with one that caches the result in an instance variable.
3
- #
4
- # If a Date is frozen but the memoized method hasn't been called, the
5
- # first call will result in a frozen object error since the memo
6
- # instance variable is uninitialized.
7
- #
8
- # Work around by eagerly memoizing before freezing.
9
- #
10
- # Ruby 1.9 uses a preinitialized instance variable so it's unaffected.
11
- # This hack is as close as we can get to feature detection:
12
- if RUBY_VERSION < '1.9'
13
- require 'date'
14
- begin
15
- ::Date.today.freeze.jd
16
- rescue => frozen_object_error
17
- if frozen_object_error.message =~ /frozen/
18
- class Date #:nodoc:
19
- def freeze
20
- self.class.private_instance_methods(false).each do |m|
21
- if m.to_s =~ /\A__\d+__\Z/
22
- instance_variable_set(:"@#{m}", [send(m)])
23
- end
24
- end
25
-
26
- super
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,13 +0,0 @@
1
- require 'active_support/core_ext/object/acts_like'
2
-
3
- class DateTime
4
- # Duck-types as a Date-like class. See Object#acts_like?.
5
- def acts_like_date?
6
- true
7
- end
8
-
9
- # Duck-types as a Time-like class. See Object#acts_like?.
10
- def acts_like_time?
11
- true
12
- end
13
- end