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,114 +0,0 @@
1
- require 'active_support/concern'
2
- require 'active_support/core_ext/class/attribute'
3
- require 'active_support/core_ext/proc'
4
- require 'active_support/core_ext/string/inflections'
5
- require 'active_support/core_ext/array/extract_options'
6
-
7
- module ActiveSupport
8
- # Rescuable module adds support for easier exception handling.
9
- module Rescuable
10
- extend Concern
11
-
12
- included do
13
- class_attribute :rescue_handlers
14
- self.rescue_handlers = []
15
- end
16
-
17
- module ClassMethods
18
- # Rescue exceptions raised in controller actions.
19
- #
20
- # <tt>rescue_from</tt> receives a series of exception classes or class
21
- # names, and a trailing <tt>:with</tt> option with the name of a method
22
- # or a Proc object to be called to handle them. Alternatively a block can
23
- # be given.
24
- #
25
- # Handlers that take one argument will be called with the exception, so
26
- # that the exception can be inspected when dealing with it.
27
- #
28
- # Handlers are inherited. They are searched from right to left, from
29
- # bottom to top, and up the hierarchy. The handler of the first class for
30
- # which <tt>exception.is_a?(klass)</tt> holds true is the one invoked, if
31
- # any.
32
- #
33
- # class ApplicationController < ActionController::Base
34
- # rescue_from User::NotAuthorized, :with => :deny_access # self defined exception
35
- # rescue_from ActiveRecord::RecordInvalid, :with => :show_errors
36
- #
37
- # rescue_from 'MyAppError::Base' do |exception|
38
- # render :xml => exception, :status => 500
39
- # end
40
- #
41
- # protected
42
- # def deny_access
43
- # ...
44
- # end
45
- #
46
- # def show_errors(exception)
47
- # exception.record.new_record? ? ...
48
- # end
49
- # end
50
- def rescue_from(*klasses, &block)
51
- options = klasses.extract_options!
52
-
53
- unless options.has_key?(:with)
54
- if block_given?
55
- options[:with] = block
56
- else
57
- raise ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument."
58
- end
59
- end
60
-
61
- klasses.each do |klass|
62
- key = if klass.is_a?(Class) && klass <= Exception
63
- klass.name
64
- elsif klass.is_a?(String)
65
- klass
66
- else
67
- raise ArgumentError, "#{klass} is neither an Exception nor a String"
68
- end
69
-
70
- # put the new handler at the end because the list is read in reverse
71
- self.rescue_handlers += [[key, options[:with]]]
72
- end
73
- end
74
- end
75
-
76
- # Tries to rescue the exception by looking up and calling a registered handler.
77
- def rescue_with_handler(exception)
78
- if handler = handler_for_rescue(exception)
79
- handler.arity != 0 ? handler.call(exception) : handler.call
80
- true # don't rely on the return value of the handler
81
- end
82
- end
83
-
84
- def handler_for_rescue(exception)
85
- # We go from right to left because pairs are pushed onto rescue_handlers
86
- # as rescue_from declarations are found.
87
- _, rescuer = self.class.rescue_handlers.reverse.detect do |klass_name, handler|
88
- # The purpose of allowing strings in rescue_from is to support the
89
- # declaration of handler associations for exception classes whose
90
- # definition is yet unknown.
91
- #
92
- # Since this loop needs the constants it would be inconsistent to
93
- # assume they should exist at this point. An early raised exception
94
- # could trigger some other handler and the array could include
95
- # precisely a string whose corresponding constant has not yet been
96
- # seen. This is why we are tolerant to unknown constants.
97
- #
98
- # Note that this tolerance only matters if the exception was given as
99
- # a string, otherwise a NameError will be raised by the interpreter
100
- # itself when rescue_from CONSTANT is executed.
101
- klass = self.class.const_get(klass_name) rescue nil
102
- klass ||= klass_name.constantize rescue nil
103
- exception.is_a?(klass) if klass
104
- end
105
-
106
- case rescuer
107
- when Symbol
108
- method(rescuer)
109
- when Proc
110
- rescuer.bind(self)
111
- end
112
- end
113
- end
114
- end
@@ -1,22 +0,0 @@
1
- # Backported Ruby builtins so you can code with the latest & greatest
2
- # but still run on any Ruby 1.8.x.
3
- #
4
- # Date next_year, next_month
5
- # DateTime to_date, to_datetime, xmlschema
6
- # Enumerable group_by, each_with_object, none?
7
- # Process Process.daemon
8
- # REXML security fix
9
- # String ord
10
- # Time to_date, to_time, to_datetime
11
- require 'active_support'
12
- require 'active_support/core_ext/date/calculations'
13
- require 'active_support/core_ext/date_time/conversions'
14
- require 'active_support/core_ext/enumerable'
15
- require 'active_support/core_ext/process/daemon'
16
- require 'active_support/core_ext/string/conversions'
17
- require 'active_support/core_ext/string/interpolation'
18
- require 'active_support/core_ext/string/encoding'
19
- require 'active_support/core_ext/rexml'
20
- require 'active_support/core_ext/time/conversions'
21
- require 'active_support/core_ext/file/path'
22
- require 'active_support/core_ext/module/method_names'
@@ -1,199 +0,0 @@
1
- begin
2
- require 'securerandom'
3
- rescue LoadError
4
- end
5
-
6
- module ActiveSupport
7
- if defined?(::SecureRandom)
8
- # Use Ruby's SecureRandom library if available.
9
- SecureRandom = ::SecureRandom # :nodoc:
10
- else
11
- # = Secure random number generator interface.
12
- #
13
- # This library is an interface for secure random number generator which is
14
- # suitable for generating session key in HTTP cookies, etc.
15
- #
16
- # It supports following secure random number generators.
17
- #
18
- # * openssl
19
- # * /dev/urandom
20
- # * Win32
21
- #
22
- # *Note*: This module is based on the SecureRandom library from Ruby 1.9,
23
- # revision 18786, August 23 2008. It's 100% interface-compatible with Ruby 1.9's
24
- # SecureRandom library.
25
- #
26
- # == Example
27
- #
28
- # # random hexadecimal string.
29
- # p SecureRandom.hex(10) #=> "52750b30ffbc7de3b362"
30
- # p SecureRandom.hex(10) #=> "92b15d6c8dc4beb5f559"
31
- # p SecureRandom.hex(11) #=> "6aca1b5c58e4863e6b81b8"
32
- # p SecureRandom.hex(12) #=> "94b2fff3e7fd9b9c391a2306"
33
- # p SecureRandom.hex(13) #=> "39b290146bea6ce975c37cfc23"
34
- # ...
35
- #
36
- # # random base64 string.
37
- # p SecureRandom.base64(10) #=> "EcmTPZwWRAozdA=="
38
- # p SecureRandom.base64(10) #=> "9b0nsevdwNuM/w=="
39
- # p SecureRandom.base64(10) #=> "KO1nIU+p9DKxGg=="
40
- # p SecureRandom.base64(11) #=> "l7XEiFja+8EKEtY="
41
- # p SecureRandom.base64(12) #=> "7kJSM/MzBJI+75j8"
42
- # p SecureRandom.base64(13) #=> "vKLJ0tXBHqQOuIcSIg=="
43
- # ...
44
- #
45
- # # random binary string.
46
- # p SecureRandom.random_bytes(10) #=> "\016\t{\370g\310pbr\301"
47
- # p SecureRandom.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337"
48
- # ...
49
- module SecureRandom
50
- # SecureRandom.random_bytes generates a random binary string.
51
- #
52
- # The argument n specifies the length of the result string.
53
- #
54
- # If n is not specified, 16 is assumed.
55
- # It may be larger in future.
56
- #
57
- # If secure random number generator is not available,
58
- # NotImplementedError is raised.
59
- def self.random_bytes(n=nil)
60
- n ||= 16
61
-
62
- unless defined? OpenSSL
63
- begin
64
- require 'openssl'
65
- rescue LoadError
66
- end
67
- end
68
-
69
- if defined? OpenSSL::Random
70
- return OpenSSL::Random.random_bytes(n)
71
- end
72
-
73
- if !defined?(@has_urandom) || @has_urandom
74
- flags = File::RDONLY
75
- flags |= File::NONBLOCK if defined? File::NONBLOCK
76
- flags |= File::NOCTTY if defined? File::NOCTTY
77
- flags |= File::NOFOLLOW if defined? File::NOFOLLOW
78
- begin
79
- File.open("/dev/urandom", flags) {|f|
80
- unless f.stat.chardev?
81
- raise Errno::ENOENT
82
- end
83
- @has_urandom = true
84
- ret = f.readpartial(n)
85
- if ret.length != n
86
- raise NotImplementedError, "Unexpected partial read from random device"
87
- end
88
- return ret
89
- }
90
- rescue Errno::ENOENT
91
- @has_urandom = false
92
- end
93
- end
94
-
95
- if !defined?(@has_win32)
96
- begin
97
- require 'Win32API'
98
-
99
- crypt_acquire_context = Win32API.new("advapi32", "CryptAcquireContext", 'PPPII', 'L')
100
- @crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom", 'LIP', 'L')
101
-
102
- hProvStr = " " * 4
103
- prov_rsa_full = 1
104
- crypt_verifycontext = 0xF0000000
105
-
106
- if crypt_acquire_context.call(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0
107
- raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}"
108
- end
109
- @hProv, = hProvStr.unpack('L')
110
-
111
- @has_win32 = true
112
- rescue LoadError
113
- @has_win32 = false
114
- end
115
- end
116
- if @has_win32
117
- bytes = " " * n
118
- if @crypt_gen_random.call(@hProv, bytes.size, bytes) == 0
119
- raise SystemCallError, "CryptGenRandom failed: #{lastWin32ErrorMessage}"
120
- end
121
- return bytes
122
- end
123
-
124
- raise NotImplementedError, "No random device"
125
- end
126
-
127
- # SecureRandom.hex generates a random hex string.
128
- #
129
- # The argument n specifies the length of the random length.
130
- # The length of the result string is twice of n.
131
- #
132
- # If n is not specified, 16 is assumed.
133
- # It may be larger in future.
134
- #
135
- # If secure random number generator is not available,
136
- # NotImplementedError is raised.
137
- def self.hex(n=nil)
138
- random_bytes(n).unpack("H*")[0]
139
- end
140
-
141
- # SecureRandom.base64 generates a random base64 string.
142
- #
143
- # The argument n specifies the length of the random length.
144
- # The length of the result string is about 4/3 of n.
145
- #
146
- # If n is not specified, 16 is assumed.
147
- # It may be larger in future.
148
- #
149
- # If secure random number generator is not available,
150
- # NotImplementedError is raised.
151
- def self.base64(n=nil)
152
- [random_bytes(n)].pack("m*").delete("\n")
153
- end
154
-
155
- # SecureRandom.random_number generates a random number.
156
- #
157
- # If an positive integer is given as n,
158
- # SecureRandom.random_number returns an integer:
159
- # 0 <= SecureRandom.random_number(n) < n.
160
- #
161
- # If 0 is given or an argument is not given,
162
- # SecureRandom.random_number returns an float:
163
- # 0.0 <= SecureRandom.random_number() < 1.0.
164
- def self.random_number(n=0)
165
- if 0 < n
166
- hex = n.to_s(16)
167
- hex = '0' + hex if (hex.length & 1) == 1
168
- bin = [hex].pack("H*")
169
- mask = bin[0]
170
- mask |= mask >> 1
171
- mask |= mask >> 2
172
- mask |= mask >> 4
173
- begin
174
- rnd = SecureRandom.random_bytes(bin.length)
175
- rnd[0] = rnd[0] & mask
176
- end until rnd < bin
177
- rnd.unpack("H*")[0].hex
178
- else
179
- # assumption: Float::MANT_DIG <= 64
180
- i64 = SecureRandom.random_bytes(8).unpack("Q")[0]
181
- Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG)
182
- end
183
- end
184
-
185
- # Following code is based on David Garamond's GUID library for Ruby.
186
- def self.lastWin32ErrorMessage # :nodoc:
187
- get_last_error = Win32API.new("kernel32", "GetLastError", '', 'L')
188
- format_message = Win32API.new("kernel32", "FormatMessageA", 'LPLLPLPPPPPPPP', 'L')
189
- format_message_ignore_inserts = 0x00000200
190
- format_message_from_system = 0x00001000
191
-
192
- code = get_last_error.call
193
- msg = "\0" * 1024
194
- len = format_message.call(format_message_ignore_inserts + format_message_from_system, 0, code, 0, msg, 1024, nil, nil, nil, nil, nil, nil, nil, nil)
195
- msg[0, len].tr("\r", '').chomp
196
- end
197
- end
198
- end
199
- end
@@ -1,21 +0,0 @@
1
- module ActiveSupport
2
- # Wrapping a string in this class gives you a prettier way to test
3
- # for equality. The value returned by <tt>Rails.env</tt> is wrapped
4
- # in a StringInquirer object so instead of calling this:
5
- #
6
- # Rails.env == "production"
7
- #
8
- # you can call this:
9
- #
10
- # Rails.env.production?
11
- #
12
- class StringInquirer < String
13
- def method_missing(method_name, *arguments)
14
- if method_name.to_s[-1,1] == "?"
15
- self == method_name.to_s[0..-2]
16
- else
17
- super
18
- end
19
- end
20
- end
21
- end
@@ -1,42 +0,0 @@
1
- require 'test/unit/testcase'
2
- require 'active_support/testing/setup_and_teardown'
3
- require 'active_support/testing/assertions'
4
- require 'active_support/testing/deprecation'
5
- require 'active_support/testing/declarative'
6
- require 'active_support/testing/pending'
7
- require 'active_support/testing/isolation'
8
- require 'active_support/core_ext/kernel/reporting'
9
-
10
- begin
11
- silence_warnings { require 'mocha' }
12
- rescue LoadError
13
- # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
14
- Object.const_set :Mocha, Module.new
15
- Mocha.const_set :ExpectationError, Class.new(StandardError)
16
- end
17
-
18
- module ActiveSupport
19
- class TestCase < ::Test::Unit::TestCase
20
- if defined? MiniTest
21
- Assertion = MiniTest::Assertion
22
- alias_method :method_name, :name if method_defined? :name
23
- alias_method :method_name, :__name__ if method_defined? :__name__
24
- else
25
- Assertion = Test::Unit::AssertionFailedError
26
-
27
- require 'active_support/testing/default'
28
- include ActiveSupport::Testing::Default
29
- end
30
-
31
- $tags = {}
32
- def self.for_tag(tag)
33
- yield if $tags[tag]
34
- end
35
-
36
- include ActiveSupport::Testing::SetupAndTeardown
37
- include ActiveSupport::Testing::Assertions
38
- include ActiveSupport::Testing::Deprecation
39
- include ActiveSupport::Testing::Pending
40
- extend ActiveSupport::Testing::Declarative
41
- end
42
- end
@@ -1,82 +0,0 @@
1
- require 'active_support/core_ext/array/wrap'
2
- require 'active_support/core_ext/object/blank'
3
-
4
- module ActiveSupport
5
- module Testing
6
- module Assertions
7
- # Test numeric difference between the return value of an expression as a result of what is evaluated
8
- # in the yielded block.
9
- #
10
- # assert_difference 'Article.count' do
11
- # post :create, :article => {...}
12
- # end
13
- #
14
- # An arbitrary expression is passed in and evaluated.
15
- #
16
- # assert_difference 'assigns(:article).comments(:reload).size' do
17
- # post :create, :comment => {...}
18
- # end
19
- #
20
- # An arbitrary positive or negative difference can be specified. The default is +1.
21
- #
22
- # assert_difference 'Article.count', -1 do
23
- # post :delete, :id => ...
24
- # end
25
- #
26
- # An array of expressions can also be passed in and evaluated.
27
- #
28
- # assert_difference [ 'Article.count', 'Post.count' ], +2 do
29
- # post :create, :article => {...}
30
- # end
31
- #
32
- # A error message can be specified.
33
- #
34
- # assert_difference 'Article.count', -1, "An Article should be destroyed" do
35
- # post :delete, :id => ...
36
- # end
37
- def assert_difference(expression, difference = 1, message = nil, &block)
38
- b = block.send(:binding)
39
- exps = Array.wrap(expression)
40
- before = exps.map { |e| eval(e, b) }
41
-
42
- yield
43
-
44
- exps.each_with_index do |e, i|
45
- error = "#{e.inspect} didn't change by #{difference}"
46
- error = "#{message}.\n#{error}" if message
47
- assert_equal(before[i] + difference, eval(e, b), error)
48
- end
49
- end
50
-
51
- # Assertion that the numeric result of evaluating an expression is not changed before and after
52
- # invoking the passed in block.
53
- #
54
- # assert_no_difference 'Article.count' do
55
- # post :create, :article => invalid_attributes
56
- # end
57
- #
58
- # A error message can be specified.
59
- #
60
- # assert_no_difference 'Article.count', "An Article should not be destroyed" do
61
- # post :create, :article => invalid_attributes
62
- # end
63
- def assert_no_difference(expression, message = nil, &block)
64
- assert_difference expression, 0, message, &block
65
- end
66
-
67
- # Test if an expression is blank. Passes if object.blank? is true.
68
- #
69
- # assert_blank [] # => true
70
- def assert_blank(object)
71
- assert object.blank?, "#{object.inspect} is not blank"
72
- end
73
-
74
- # Test if an expression is not blank. Passes if object.present? is true.
75
- #
76
- # assert_present {:data => 'x' } # => true
77
- def assert_present(object)
78
- assert object.present?, "#{object.inspect} is blank"
79
- end
80
- end
81
- end
82
- end