csd 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +1 -2
- data/README.rdoc +7 -1
- data/Rakefile +7 -2
- data/VERSION +1 -1
- data/csd.gemspec +18 -216
- data/lib/csd.rb +6 -16
- data/lib/csd/application.rb +2 -2
- data/lib/csd/application/default.rb +15 -14
- data/lib/csd/application/default/base.rb +1 -1
- data/lib/csd/application/minisip.rb +43 -11
- data/lib/csd/application/minisip/about.yml +5 -5
- data/lib/csd/application/minisip/base.rb +82 -70
- data/lib/csd/application/minisip/error.rb +1 -1
- data/lib/csd/application/minisip/options/common.rb +1 -1
- data/lib/csd/application/minisip/options/compile.rb +1 -1
- data/lib/csd/application/minisip/options/package.rb +1 -1
- data/lib/csd/application/minisip/unix.rb +40 -27
- data/lib/csd/application/minisip/unix/darwin.rb +12 -0
- data/lib/csd/application/minisip/unix/linux.rb +1 -11
- data/lib/csd/application/minisip/unix/linux/debian.rb +14 -25
- data/lib/csd/application/minisip/unix/linux/debian/ubuntu10.rb +12 -13
- data/lib/csd/applications.rb +5 -5
- data/lib/csd/commands.rb +164 -89
- data/lib/csd/container.rb +61 -0
- data/lib/csd/error.rb +10 -1
- data/lib/csd/extensions.rb +3 -2
- data/lib/csd/extensions/core/array.rb +29 -1
- data/lib/csd/extensions/core/dir.rb +15 -24
- data/lib/csd/extensions/core/object.rb +10 -2
- data/lib/csd/extensions/core/option_parser.rb +22 -3
- data/lib/csd/extensions/core/pathname.rb +30 -2
- data/lib/csd/extensions/core/string.rb +51 -4
- data/lib/csd/extensions/gem/platform.rb +18 -3
- data/lib/csd/{options.rb → options_parser.rb} +16 -20
- data/lib/csd/path_container.rb +24 -0
- data/lib/csd/user_interface.rb +2 -0
- data/lib/csd/user_interface/base.rb +26 -0
- data/lib/csd/user_interface/cli.rb +37 -0
- data/lib/csd/vendor/active_support/MIT-LICENSE +20 -0
- data/lib/csd/vendor/active_support/inflector.rb +155 -0
- data/lib/csd/vendor/term/GPL2-LICENSE +339 -0
- data/lib/csd/vendor/term/ansicolor.rb +113 -0
- data/lib/csd/version.rb +13 -4
- data/test/application/test_minisip.rb +45 -0
- data/test/functional/test_applications.rb +10 -16
- data/test/functional/test_commands.rb +260 -23
- data/test/unit/test_string.rb +1 -1
- metadata +18 -216
- data/lib/active_support.rb +0 -75
- data/lib/active_support/all.rb +0 -3
- data/lib/active_support/backtrace_cleaner.rb +0 -94
- data/lib/active_support/base64.rb +0 -42
- data/lib/active_support/basic_object.rb +0 -21
- data/lib/active_support/benchmarkable.rb +0 -60
- data/lib/active_support/buffered_logger.rb +0 -132
- data/lib/active_support/builder.rb +0 -6
- data/lib/active_support/cache.rb +0 -626
- data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
- data/lib/active_support/cache/file_store.rb +0 -188
- data/lib/active_support/cache/mem_cache_store.rb +0 -191
- data/lib/active_support/cache/memory_store.rb +0 -159
- data/lib/active_support/cache/strategy/local_cache.rb +0 -164
- data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
- data/lib/active_support/callbacks.rb +0 -600
- data/lib/active_support/concern.rb +0 -29
- data/lib/active_support/configurable.rb +0 -36
- data/lib/active_support/core_ext.rb +0 -3
- data/lib/active_support/core_ext/array.rb +0 -7
- data/lib/active_support/core_ext/array/access.rb +0 -46
- data/lib/active_support/core_ext/array/conversions.rb +0 -164
- data/lib/active_support/core_ext/array/extract_options.rb +0 -29
- data/lib/active_support/core_ext/array/grouping.rb +0 -100
- data/lib/active_support/core_ext/array/random_access.rb +0 -20
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
- data/lib/active_support/core_ext/array/wrap.rb +0 -22
- data/lib/active_support/core_ext/benchmark.rb +0 -7
- data/lib/active_support/core_ext/big_decimal.rb +0 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -27
- data/lib/active_support/core_ext/cgi.rb +0 -1
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
- data/lib/active_support/core_ext/class.rb +0 -4
- data/lib/active_support/core_ext/class/attribute.rb +0 -67
- data/lib/active_support/core_ext/class/attribute_accessors.rb +0 -63
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -232
- data/lib/active_support/core_ext/class/subclasses.rb +0 -55
- data/lib/active_support/core_ext/date/acts_like.rb +0 -8
- data/lib/active_support/core_ext/date/calculations.rb +0 -240
- data/lib/active_support/core_ext/date/conversions.rb +0 -99
- data/lib/active_support/core_ext/date/freeze.rb +0 -31
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -13
- data/lib/active_support/core_ext/date_time/calculations.rb +0 -113
- data/lib/active_support/core_ext/date_time/conversions.rb +0 -102
- data/lib/active_support/core_ext/date_time/zones.rb +0 -17
- data/lib/active_support/core_ext/enumerable.rb +0 -119
- data/lib/active_support/core_ext/exception.rb +0 -3
- data/lib/active_support/core_ext/file.rb +0 -2
- data/lib/active_support/core_ext/file/atomic.rb +0 -41
- data/lib/active_support/core_ext/file/path.rb +0 -5
- data/lib/active_support/core_ext/float.rb +0 -1
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/hash.rb +0 -8
- data/lib/active_support/core_ext/hash/conversions.rb +0 -150
- data/lib/active_support/core_ext/hash/deep_merge.rb +0 -16
- data/lib/active_support/core_ext/hash/diff.rb +0 -13
- data/lib/active_support/core_ext/hash/except.rb +0 -24
- data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -14
- data/lib/active_support/core_ext/hash/keys.rb +0 -45
- data/lib/active_support/core_ext/hash/reverse_merge.rb +0 -28
- data/lib/active_support/core_ext/hash/slice.rb +0 -38
- data/lib/active_support/core_ext/integer.rb +0 -3
- data/lib/active_support/core_ext/integer/inflections.rb +0 -14
- data/lib/active_support/core_ext/integer/multiple.rb +0 -6
- data/lib/active_support/core_ext/integer/time.rb +0 -39
- data/lib/active_support/core_ext/kernel.rb +0 -5
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -16
- data/lib/active_support/core_ext/kernel/reporting.rb +0 -62
- data/lib/active_support/core_ext/kernel/requires.rb +0 -26
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
- data/lib/active_support/core_ext/load_error.rb +0 -23
- data/lib/active_support/core_ext/logger.rb +0 -146
- data/lib/active_support/core_ext/module.rb +0 -12
- data/lib/active_support/core_ext/module/aliasing.rb +0 -70
- data/lib/active_support/core_ext/module/anonymous.rb +0 -24
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
- data/lib/active_support/core_ext/module/attr_internal.rb +0 -32
- data/lib/active_support/core_ext/module/attribute_accessors.rb +0 -66
- data/lib/active_support/core_ext/module/delegation.rb +0 -146
- data/lib/active_support/core_ext/module/deprecation.rb +0 -9
- data/lib/active_support/core_ext/module/introspection.rb +0 -88
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/reachable.rb +0 -10
- data/lib/active_support/core_ext/module/remove_method.rb +0 -6
- data/lib/active_support/core_ext/module/synchronization.rb +0 -42
- data/lib/active_support/core_ext/name_error.rb +0 -18
- data/lib/active_support/core_ext/numeric.rb +0 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +0 -44
- data/lib/active_support/core_ext/numeric/time.rb +0 -77
- data/lib/active_support/core_ext/object.rb +0 -14
- data/lib/active_support/core_ext/object/acts_like.rb +0 -10
- data/lib/active_support/core_ext/object/blank.rb +0 -76
- data/lib/active_support/core_ext/object/conversions.rb +0 -4
- data/lib/active_support/core_ext/object/duplicable.rb +0 -65
- data/lib/active_support/core_ext/object/extending.rb +0 -11
- data/lib/active_support/core_ext/object/instance_variables.rb +0 -67
- data/lib/active_support/core_ext/object/misc.rb +0 -2
- data/lib/active_support/core_ext/object/returning.rb +0 -42
- data/lib/active_support/core_ext/object/to_param.rb +0 -49
- data/lib/active_support/core_ext/object/to_query.rb +0 -27
- data/lib/active_support/core_ext/object/try.rb +0 -36
- data/lib/active_support/core_ext/object/with_options.rb +0 -26
- data/lib/active_support/core_ext/proc.rb +0 -14
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- data/lib/active_support/core_ext/range.rb +0 -4
- data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
- data/lib/active_support/core_ext/range/conversions.rb +0 -21
- data/lib/active_support/core_ext/range/include_range.rb +0 -21
- data/lib/active_support/core_ext/range/overlaps.rb +0 -8
- data/lib/active_support/core_ext/regexp.rb +0 -5
- data/lib/active_support/core_ext/rexml.rb +0 -46
- data/lib/active_support/core_ext/string.rb +0 -12
- data/lib/active_support/core_ext/string/access.rb +0 -99
- data/lib/active_support/core_ext/string/behavior.rb +0 -7
- data/lib/active_support/core_ext/string/conversions.rb +0 -61
- data/lib/active_support/core_ext/string/encoding.rb +0 -11
- data/lib/active_support/core_ext/string/exclude.rb +0 -6
- data/lib/active_support/core_ext/string/filters.rb +0 -49
- data/lib/active_support/core_ext/string/inflections.rb +0 -149
- data/lib/active_support/core_ext/string/interpolation.rb +0 -2
- data/lib/active_support/core_ext/string/multibyte.rb +0 -72
- data/lib/active_support/core_ext/string/output_safety.rb +0 -109
- data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -4
- data/lib/active_support/core_ext/string/xchar.rb +0 -18
- data/lib/active_support/core_ext/time/acts_like.rb +0 -8
- data/lib/active_support/core_ext/time/calculations.rb +0 -282
- data/lib/active_support/core_ext/time/conversions.rb +0 -85
- data/lib/active_support/core_ext/time/marshal.rb +0 -56
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/core_ext/time/zones.rb +0 -78
- data/lib/active_support/core_ext/uri.rb +0 -22
- data/lib/active_support/dependencies.rb +0 -628
- data/lib/active_support/dependencies/autoload.rb +0 -50
- data/lib/active_support/deprecation.rb +0 -18
- data/lib/active_support/deprecation/behaviors.rb +0 -38
- data/lib/active_support/deprecation/method_wrappers.rb +0 -29
- data/lib/active_support/deprecation/proxy_wrappers.rb +0 -74
- data/lib/active_support/deprecation/reporting.rb +0 -56
- data/lib/active_support/duration.rb +0 -105
- data/lib/active_support/gzip.rb +0 -25
- data/lib/active_support/hash_with_indifferent_access.rb +0 -145
- data/lib/active_support/i18n.rb +0 -8
- data/lib/active_support/inflections.rb +0 -56
- data/lib/active_support/inflector.rb +0 -7
- data/lib/active_support/inflector/inflections.rb +0 -211
- data/lib/active_support/inflector/methods.rb +0 -141
- data/lib/active_support/inflector/transliterate.rb +0 -97
- data/lib/active_support/json.rb +0 -2
- data/lib/active_support/json/backends/jsongem.rb +0 -43
- data/lib/active_support/json/backends/yajl.rb +0 -40
- data/lib/active_support/json/backends/yaml.rb +0 -90
- data/lib/active_support/json/decoding.rb +0 -51
- data/lib/active_support/json/encoding.rb +0 -254
- data/lib/active_support/json/variable.rb +0 -11
- data/lib/active_support/lazy_load_hooks.rb +0 -27
- data/lib/active_support/locale/en.yml +0 -36
- data/lib/active_support/memoizable.rb +0 -103
- data/lib/active_support/message_encryptor.rb +0 -71
- data/lib/active_support/message_verifier.rb +0 -62
- data/lib/active_support/multibyte.rb +0 -44
- data/lib/active_support/multibyte/chars.rb +0 -480
- data/lib/active_support/multibyte/exceptions.rb +0 -8
- data/lib/active_support/multibyte/unicode.rb +0 -393
- data/lib/active_support/multibyte/utils.rb +0 -60
- data/lib/active_support/notifications.rb +0 -81
- data/lib/active_support/notifications/fanout.rb +0 -93
- data/lib/active_support/notifications/instrumenter.rb +0 -56
- data/lib/active_support/option_merger.rb +0 -25
- data/lib/active_support/ordered_hash.rb +0 -158
- data/lib/active_support/ordered_options.rb +0 -27
- data/lib/active_support/railtie.rb +0 -100
- data/lib/active_support/rescuable.rb +0 -114
- data/lib/active_support/ruby/shim.rb +0 -22
- data/lib/active_support/secure_random.rb +0 -199
- data/lib/active_support/string_inquirer.rb +0 -21
- data/lib/active_support/test_case.rb +0 -42
- data/lib/active_support/testing/assertions.rb +0 -82
- data/lib/active_support/testing/declarative.rb +0 -40
- data/lib/active_support/testing/default.rb +0 -9
- data/lib/active_support/testing/deprecation.rb +0 -55
- data/lib/active_support/testing/isolation.rb +0 -154
- data/lib/active_support/testing/pending.rb +0 -48
- data/lib/active_support/testing/performance.rb +0 -455
- data/lib/active_support/testing/setup_and_teardown.rb +0 -111
- data/lib/active_support/time.rb +0 -34
- data/lib/active_support/time/autoload.rb +0 -5
- data/lib/active_support/time_with_zone.rb +0 -341
- data/lib/active_support/values/time_zone.rb +0 -377
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +0 -10
- data/lib/active_support/whiny_nil.rb +0 -60
- data/lib/active_support/xml_mini.rb +0 -158
- data/lib/active_support/xml_mini/jdom.rb +0 -168
- data/lib/active_support/xml_mini/libxml.rb +0 -80
- data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
- data/lib/active_support/xml_mini/nokogiri.rb +0 -78
- data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
- data/lib/active_support/xml_mini/rexml.rb +0 -129
- data/lib/csd/extensions/core/file.rb +0 -14
- data/lib/csd/global_open_struct.rb +0 -19
- data/lib/csd/path.rb +0 -32
- data/lib/csd/ui.rb +0 -2
- data/lib/csd/ui/cli.rb +0 -8
- data/lib/csd/ui/ui.rb +0 -45
- data/lib/term/ansicolor.rb +0 -102
- data/lib/term/ansicolor/.keep +0 -0
- 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
|