csd 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/COPYING +367 -0
- data/Rakefile +10 -10
- data/VERSION +1 -1
- data/bin/ai +19 -0
- data/csd.gemspec +257 -35
- data/lib/active_support.rb +75 -0
- data/lib/active_support/all.rb +3 -0
- data/lib/active_support/backtrace_cleaner.rb +94 -0
- data/lib/active_support/base64.rb +42 -0
- data/lib/active_support/basic_object.rb +21 -0
- data/lib/active_support/benchmarkable.rb +60 -0
- data/lib/active_support/buffered_logger.rb +132 -0
- data/lib/active_support/builder.rb +6 -0
- data/lib/active_support/cache.rb +626 -0
- data/lib/active_support/cache/compressed_mem_cache_store.rb +13 -0
- data/lib/active_support/cache/file_store.rb +188 -0
- data/lib/active_support/cache/mem_cache_store.rb +191 -0
- data/lib/active_support/cache/memory_store.rb +159 -0
- data/lib/active_support/cache/strategy/local_cache.rb +164 -0
- data/lib/active_support/cache/synchronized_memory_store.rb +11 -0
- data/lib/active_support/callbacks.rb +600 -0
- data/lib/active_support/concern.rb +29 -0
- data/lib/active_support/configurable.rb +36 -0
- data/lib/active_support/core_ext.rb +3 -0
- data/lib/active_support/core_ext/array.rb +7 -0
- data/lib/active_support/core_ext/array/access.rb +46 -0
- data/lib/active_support/core_ext/array/conversions.rb +164 -0
- data/lib/active_support/core_ext/array/extract_options.rb +29 -0
- data/lib/active_support/core_ext/array/grouping.rb +100 -0
- data/lib/active_support/core_ext/array/random_access.rb +20 -0
- data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
- data/lib/active_support/core_ext/array/wrap.rb +22 -0
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal.rb +1 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
- data/lib/active_support/core_ext/cgi.rb +1 -0
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +19 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/class/attribute.rb +67 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +63 -0
- data/lib/active_support/core_ext/class/delegating_attributes.rb +44 -0
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +232 -0
- data/lib/active_support/core_ext/class/subclasses.rb +55 -0
- data/lib/active_support/core_ext/date/acts_like.rb +8 -0
- data/lib/active_support/core_ext/date/calculations.rb +240 -0
- data/lib/active_support/core_ext/date/conversions.rb +99 -0
- data/lib/active_support/core_ext/date/freeze.rb +31 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +113 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +102 -0
- data/lib/active_support/core_ext/date_time/zones.rb +17 -0
- data/lib/active_support/core_ext/enumerable.rb +119 -0
- data/lib/active_support/core_ext/exception.rb +3 -0
- data/lib/active_support/core_ext/file.rb +2 -0
- data/lib/active_support/core_ext/file/atomic.rb +41 -0
- data/lib/active_support/core_ext/file/path.rb +5 -0
- data/lib/active_support/core_ext/float.rb +1 -0
- data/lib/active_support/core_ext/float/rounding.rb +19 -0
- data/lib/active_support/core_ext/hash.rb +8 -0
- data/lib/active_support/core_ext/hash/conversions.rb +150 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +16 -0
- data/lib/active_support/core_ext/hash/diff.rb +13 -0
- data/lib/active_support/core_ext/hash/except.rb +24 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +14 -0
- data/lib/active_support/core_ext/hash/keys.rb +45 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +28 -0
- data/lib/active_support/core_ext/hash/slice.rb +38 -0
- data/lib/active_support/core_ext/integer.rb +3 -0
- data/lib/active_support/core_ext/integer/inflections.rb +14 -0
- data/lib/active_support/core_ext/integer/multiple.rb +6 -0
- data/lib/active_support/core_ext/integer/time.rb +39 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/lib/active_support/core_ext/kernel/debugger.rb +16 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +62 -0
- data/lib/active_support/core_ext/kernel/requires.rb +26 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
- data/lib/active_support/core_ext/load_error.rb +23 -0
- data/lib/active_support/core_ext/logger.rb +146 -0
- data/lib/active_support/core_ext/module.rb +12 -0
- data/lib/active_support/core_ext/module/aliasing.rb +70 -0
- data/lib/active_support/core_ext/module/anonymous.rb +24 -0
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +32 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +66 -0
- data/lib/active_support/core_ext/module/delegation.rb +146 -0
- data/lib/active_support/core_ext/module/deprecation.rb +9 -0
- data/lib/active_support/core_ext/module/introspection.rb +88 -0
- data/lib/active_support/core_ext/module/method_names.rb +14 -0
- data/lib/active_support/core_ext/module/reachable.rb +10 -0
- data/lib/active_support/core_ext/module/remove_method.rb +6 -0
- data/lib/active_support/core_ext/module/synchronization.rb +42 -0
- data/lib/active_support/core_ext/name_error.rb +18 -0
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +44 -0
- data/lib/active_support/core_ext/numeric/time.rb +77 -0
- data/lib/active_support/core_ext/object.rb +14 -0
- data/lib/active_support/core_ext/object/acts_like.rb +10 -0
- data/lib/active_support/core_ext/object/blank.rb +76 -0
- data/lib/active_support/core_ext/object/conversions.rb +4 -0
- data/lib/active_support/core_ext/object/duplicable.rb +65 -0
- data/lib/active_support/core_ext/object/extending.rb +11 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +67 -0
- data/lib/active_support/core_ext/object/misc.rb +2 -0
- data/lib/active_support/core_ext/object/returning.rb +42 -0
- data/lib/active_support/core_ext/object/to_param.rb +49 -0
- data/lib/active_support/core_ext/object/to_query.rb +27 -0
- data/lib/active_support/core_ext/object/try.rb +36 -0
- data/lib/active_support/core_ext/object/with_options.rb +26 -0
- data/lib/active_support/core_ext/proc.rb +14 -0
- data/lib/active_support/core_ext/process.rb +1 -0
- data/lib/active_support/core_ext/process/daemon.rb +23 -0
- data/lib/active_support/core_ext/range.rb +4 -0
- data/lib/active_support/core_ext/range/blockless_step.rb +29 -0
- data/lib/active_support/core_ext/range/conversions.rb +21 -0
- data/lib/active_support/core_ext/range/include_range.rb +21 -0
- data/lib/active_support/core_ext/range/overlaps.rb +8 -0
- data/lib/active_support/core_ext/regexp.rb +5 -0
- data/lib/active_support/core_ext/rexml.rb +46 -0
- data/lib/active_support/core_ext/string.rb +12 -0
- data/lib/active_support/core_ext/string/access.rb +99 -0
- data/lib/active_support/core_ext/string/behavior.rb +7 -0
- data/lib/active_support/core_ext/string/conversions.rb +61 -0
- data/lib/active_support/core_ext/string/encoding.rb +11 -0
- data/lib/active_support/core_ext/string/exclude.rb +6 -0
- data/lib/active_support/core_ext/string/filters.rb +49 -0
- data/lib/active_support/core_ext/string/inflections.rb +149 -0
- data/lib/active_support/core_ext/string/interpolation.rb +2 -0
- data/lib/active_support/core_ext/string/multibyte.rb +72 -0
- data/lib/active_support/core_ext/string/output_safety.rb +109 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -0
- data/lib/active_support/core_ext/string/xchar.rb +18 -0
- data/lib/active_support/core_ext/time/acts_like.rb +8 -0
- data/lib/active_support/core_ext/time/calculations.rb +282 -0
- data/lib/active_support/core_ext/time/conversions.rb +85 -0
- data/lib/active_support/core_ext/time/marshal.rb +56 -0
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
- data/lib/active_support/core_ext/time/zones.rb +78 -0
- data/lib/active_support/core_ext/uri.rb +22 -0
- data/lib/active_support/dependencies.rb +628 -0
- data/lib/active_support/dependencies/autoload.rb +50 -0
- data/lib/active_support/deprecation.rb +18 -0
- data/lib/active_support/deprecation/behaviors.rb +38 -0
- data/lib/active_support/deprecation/method_wrappers.rb +29 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
- data/lib/active_support/deprecation/reporting.rb +56 -0
- data/lib/active_support/duration.rb +105 -0
- data/lib/active_support/gzip.rb +25 -0
- data/lib/active_support/hash_with_indifferent_access.rb +145 -0
- data/lib/active_support/i18n.rb +8 -0
- data/lib/active_support/inflections.rb +56 -0
- data/lib/active_support/inflector.rb +7 -0
- data/lib/active_support/inflector/inflections.rb +211 -0
- data/lib/active_support/inflector/methods.rb +141 -0
- data/lib/active_support/inflector/transliterate.rb +97 -0
- data/lib/active_support/json.rb +2 -0
- data/lib/active_support/json/backends/jsongem.rb +43 -0
- data/lib/active_support/json/backends/yajl.rb +40 -0
- data/lib/active_support/json/backends/yaml.rb +90 -0
- data/lib/active_support/json/decoding.rb +51 -0
- data/lib/active_support/json/encoding.rb +254 -0
- data/lib/active_support/json/variable.rb +11 -0
- data/lib/active_support/lazy_load_hooks.rb +27 -0
- data/lib/active_support/locale/en.yml +36 -0
- data/lib/active_support/memoizable.rb +103 -0
- data/lib/active_support/message_encryptor.rb +71 -0
- data/lib/active_support/message_verifier.rb +62 -0
- data/lib/active_support/multibyte.rb +44 -0
- data/lib/active_support/multibyte/chars.rb +480 -0
- data/lib/active_support/multibyte/exceptions.rb +8 -0
- data/lib/active_support/multibyte/unicode.rb +393 -0
- data/lib/active_support/multibyte/utils.rb +60 -0
- data/lib/active_support/notifications.rb +81 -0
- data/lib/active_support/notifications/fanout.rb +93 -0
- data/lib/active_support/notifications/instrumenter.rb +56 -0
- data/lib/active_support/option_merger.rb +25 -0
- data/lib/active_support/ordered_hash.rb +158 -0
- data/lib/active_support/ordered_options.rb +27 -0
- data/lib/active_support/railtie.rb +100 -0
- data/lib/active_support/rescuable.rb +114 -0
- data/lib/active_support/ruby/shim.rb +22 -0
- data/lib/active_support/secure_random.rb +199 -0
- data/lib/active_support/string_inquirer.rb +21 -0
- data/lib/active_support/test_case.rb +42 -0
- data/lib/active_support/testing/assertions.rb +82 -0
- data/lib/active_support/testing/declarative.rb +40 -0
- data/lib/active_support/testing/default.rb +9 -0
- data/lib/active_support/testing/deprecation.rb +55 -0
- data/lib/active_support/testing/isolation.rb +154 -0
- data/lib/active_support/testing/pending.rb +48 -0
- data/lib/active_support/testing/performance.rb +455 -0
- data/lib/active_support/testing/setup_and_teardown.rb +111 -0
- data/lib/active_support/time.rb +34 -0
- data/lib/active_support/time/autoload.rb +5 -0
- data/lib/active_support/time_with_zone.rb +341 -0
- data/lib/active_support/values/time_zone.rb +377 -0
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +10 -0
- data/lib/active_support/whiny_nil.rb +60 -0
- data/lib/active_support/xml_mini.rb +158 -0
- data/lib/active_support/xml_mini/jdom.rb +168 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
- data/lib/active_support/xml_mini/nokogiri.rb +78 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
- data/lib/active_support/xml_mini/rexml.rb +129 -0
- data/lib/csd.rb +82 -2
- data/lib/csd/application.rb +2 -0
- data/lib/csd/application/default.rb +51 -0
- data/lib/csd/application/default/base.rb +15 -0
- data/lib/csd/application/minisip.rb +25 -0
- data/lib/csd/application/minisip/about.yml +14 -0
- data/lib/csd/application/minisip/base.rb +161 -0
- data/lib/csd/application/minisip/error.rb +11 -0
- data/lib/csd/application/minisip/options/common.rb +0 -0
- data/lib/csd/application/minisip/options/compile.rb +59 -0
- data/lib/csd/{applications → application}/minisip/unix/base.rb +10 -11
- data/lib/csd/application/opensips/about.yml +2 -0
- data/lib/csd/applications.rb +55 -0
- data/lib/csd/commands.rb +88 -65
- data/lib/csd/error.rb +31 -0
- data/lib/csd/extensions.rb +1 -0
- data/lib/{extensions → csd/extensions}/core/array.rb +2 -2
- data/lib/csd/extensions/core/dir.rb +46 -0
- data/lib/{extensions → csd/extensions}/core/file.rb +2 -2
- data/lib/{extensions → csd/extensions}/core/object.rb +2 -2
- data/lib/csd/extensions/core/option_parser.rb +33 -0
- data/lib/{extensions → csd/extensions}/core/pathname.rb +12 -3
- data/lib/{extensions → csd/extensions}/core/string.rb +2 -2
- data/lib/{extensions → csd/extensions}/gem/platform.rb +6 -2
- data/lib/csd/global_open_struct.rb +18 -0
- data/lib/csd/options.rb +124 -95
- data/lib/csd/path.rb +31 -0
- data/lib/csd/ui.rb +1 -0
- data/lib/csd/ui/cli.rb +7 -0
- data/lib/csd/ui/ui.rb +46 -0
- data/lib/csd/version.rb +9 -0
- data/lib/term/ansicolor.rb +102 -0
- data/lib/term/ansicolor/.keep +0 -0
- data/lib/term/ansicolor/version.rb +10 -0
- data/test/functional/test_applications.rb +86 -0
- data/test/functional/test_commands.rb +42 -29
- data/test/functional/test_options.rb +98 -0
- data/test/helper.rb +14 -0
- data/test/unit/test_dir.rb +38 -0
- data/test/unit/test_pathname.rb +32 -0
- metadata +253 -40
- data/LICENSE +0 -20
- data/bin/csd +0 -8
- data/lib/csd/applications/base.rb +0 -33
- data/lib/csd/applications/minisip/base.rb +0 -125
- data/lib/csd/applications/minisip/init.rb +0 -20
- data/lib/csd/init.rb +0 -69
- data/lib/csd/path_container.rb +0 -15
- data/publish +0 -29
@@ -0,0 +1,42 @@
|
|
1
|
+
class Object
|
2
|
+
# Returns +value+ after yielding +value+ to the block. This simplifies the
|
3
|
+
# process of constructing an object, performing work on the object, and then
|
4
|
+
# returning the object from a method. It is a Ruby-ized realization of the K
|
5
|
+
# combinator, courtesy of Mikael Brockman.
|
6
|
+
#
|
7
|
+
# ==== Examples
|
8
|
+
#
|
9
|
+
# # Without returning
|
10
|
+
# def foo
|
11
|
+
# values = []
|
12
|
+
# values << "bar"
|
13
|
+
# values << "baz"
|
14
|
+
# return values
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# foo # => ['bar', 'baz']
|
18
|
+
#
|
19
|
+
# # returning with a local variable
|
20
|
+
# def foo
|
21
|
+
# returning values = [] do
|
22
|
+
# values << 'bar'
|
23
|
+
# values << 'baz'
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# foo # => ['bar', 'baz']
|
28
|
+
#
|
29
|
+
# # returning with a block argument
|
30
|
+
# def foo
|
31
|
+
# returning [] do |values|
|
32
|
+
# values << 'bar'
|
33
|
+
# values << 'baz'
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# foo # => ['bar', 'baz']
|
38
|
+
def returning(value)
|
39
|
+
yield(value)
|
40
|
+
value
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# Alias of <tt>to_s</tt>.
|
5
|
+
def to_param
|
6
|
+
to_s
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class NilClass
|
11
|
+
def to_param
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TrueClass
|
17
|
+
def to_param
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class FalseClass
|
23
|
+
def to_param
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Array
|
29
|
+
# Calls <tt>to_param</tt> on all its elements and joins the result with
|
30
|
+
# slashes. This is used by <tt>url_for</tt> in Action Pack.
|
31
|
+
def to_param
|
32
|
+
collect { |e| e.to_param }.join '/'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Hash
|
37
|
+
# Converts a hash into a string suitable for use as a URL query string. An optional <tt>namespace</tt> can be
|
38
|
+
# passed to enclose the param names (see example below).
|
39
|
+
#
|
40
|
+
# ==== Examples
|
41
|
+
# { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish"
|
42
|
+
#
|
43
|
+
# { :name => 'David', :nationality => 'Danish' }.to_param('user') # => "user[name]=David&user[nationality]=Danish"
|
44
|
+
def to_param(namespace = nil)
|
45
|
+
collect do |key, value|
|
46
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
47
|
+
end.sort * '&'
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_support/core_ext/object/to_param'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
|
5
|
+
# param name.
|
6
|
+
#
|
7
|
+
# Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
|
8
|
+
def to_query(key)
|
9
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
10
|
+
"#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(to_param.to_s)}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Array
|
15
|
+
# Converts an array into a string suitable for use as a URL query string,
|
16
|
+
# using the given +key+ as the param name.
|
17
|
+
#
|
18
|
+
# ['Rails', 'coding'].to_query('hobbies') # => "hobbies[]=Rails&hobbies[]=coding"
|
19
|
+
def to_query(key)
|
20
|
+
prefix = "#{key}[]"
|
21
|
+
collect { |value| value.to_query(prefix) }.join '&'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Hash
|
26
|
+
alias_method :to_query, :to_param
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Object
|
2
|
+
# Invokes the method identified by the symbol +method+, passing it any arguments
|
3
|
+
# and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does.
|
4
|
+
#
|
5
|
+
# *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
|
6
|
+
# and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
|
7
|
+
#
|
8
|
+
# ==== Examples
|
9
|
+
#
|
10
|
+
# Without try
|
11
|
+
# @person && @person.name
|
12
|
+
# or
|
13
|
+
# @person ? @person.name : nil
|
14
|
+
#
|
15
|
+
# With try
|
16
|
+
# @person.try(:name)
|
17
|
+
#
|
18
|
+
# +try+ also accepts arguments and/or a block, for the method it is trying
|
19
|
+
# Person.try(:find, 1)
|
20
|
+
# @people.try(:collect) {|p| p.name}
|
21
|
+
#--
|
22
|
+
# This method definition below is for rdoc purposes only. The alias_method call
|
23
|
+
# below overrides it as an optimization since +try+ behaves like +Object#send+,
|
24
|
+
# unless called on +NilClass+.
|
25
|
+
def try(method, *args, &block)
|
26
|
+
send(method, *args, &block)
|
27
|
+
end
|
28
|
+
remove_method :try
|
29
|
+
alias_method :try, :__send__
|
30
|
+
end
|
31
|
+
|
32
|
+
class NilClass #:nodoc:
|
33
|
+
def try(*args)
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_support/option_merger'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# An elegant way to factor duplication out of options passed to a series of
|
5
|
+
# method calls. Each method called in the block, with the block variable as
|
6
|
+
# the receiver, will have its options merged with the default +options+ hash
|
7
|
+
# provided. Each method called on the block variable must take an options
|
8
|
+
# hash as its final argument.
|
9
|
+
#
|
10
|
+
# with_options :order => 'created_at', :class_name => 'Comment' do |post|
|
11
|
+
# post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
|
12
|
+
# post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
|
13
|
+
# post.has_many :all_comments
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Can also be used with an explicit receiver:
|
17
|
+
#
|
18
|
+
# map.with_options :controller => "people" do |people|
|
19
|
+
# people.connect "/people", :action => "index"
|
20
|
+
# people.connect "/people/:id", :action => "show"
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
def with_options(options)
|
24
|
+
yield ActiveSupport::OptionMerger.new(self, options)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "active_support/core_ext/kernel/singleton_class"
|
2
|
+
|
3
|
+
class Proc #:nodoc:
|
4
|
+
def bind(object)
|
5
|
+
block, time = self, Time.now
|
6
|
+
object.class_eval do
|
7
|
+
method_name = "__bind_#{time.to_i}_#{time.usec}"
|
8
|
+
define_method(method_name, &block)
|
9
|
+
method = instance_method(method_name)
|
10
|
+
remove_method(method_name)
|
11
|
+
method
|
12
|
+
end.bind(object)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_support/core_ext/process/daemon'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Process
|
2
|
+
def self.daemon(nochdir = nil, noclose = nil)
|
3
|
+
exit if fork # Parent exits, child continues.
|
4
|
+
Process.setsid # Become session leader.
|
5
|
+
exit if fork # Zap session leader. See [1].
|
6
|
+
|
7
|
+
unless nochdir
|
8
|
+
Dir.chdir "/" # Release old working directory.
|
9
|
+
end
|
10
|
+
|
11
|
+
File.umask 0000 # Ensure sensible umask. Adjust as needed.
|
12
|
+
|
13
|
+
unless noclose
|
14
|
+
STDIN.reopen "/dev/null" # Free file descriptors and
|
15
|
+
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
|
16
|
+
STDERR.reopen '/dev/null', 'a'
|
17
|
+
end
|
18
|
+
|
19
|
+
trap("TERM") { exit }
|
20
|
+
|
21
|
+
return 0
|
22
|
+
end unless respond_to?(:daemon)
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support/core_ext/module/aliasing'
|
2
|
+
|
3
|
+
class Range
|
4
|
+
begin
|
5
|
+
(1..2).step
|
6
|
+
# Range#step doesn't return an Enumerator
|
7
|
+
rescue LocalJumpError
|
8
|
+
# Return an array when step is called without a block.
|
9
|
+
def step_with_blockless(*args, &block)
|
10
|
+
if block_given?
|
11
|
+
step_without_blockless(*args, &block)
|
12
|
+
else
|
13
|
+
array = []
|
14
|
+
step_without_blockless(*args) { |step| array << step }
|
15
|
+
array
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
def step_with_blockless(*args, &block) #:nodoc:
|
20
|
+
if block_given?
|
21
|
+
step_without_blockless(*args, &block)
|
22
|
+
else
|
23
|
+
step_without_blockless(*args).to_a
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method_chain :step, :blockless
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Range
|
2
|
+
RANGE_FORMATS = {
|
3
|
+
:db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
|
4
|
+
}
|
5
|
+
|
6
|
+
# Gives a human readable format of the range.
|
7
|
+
#
|
8
|
+
# ==== Example
|
9
|
+
#
|
10
|
+
# [1..100].to_formatted_s # => "1..100"
|
11
|
+
def to_formatted_s(format = :default)
|
12
|
+
if formatter = RANGE_FORMATS[format]
|
13
|
+
formatter.call(first, last)
|
14
|
+
else
|
15
|
+
to_default_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :to_default_s, :to_s
|
20
|
+
alias_method :to_s, :to_formatted_s
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Range
|
2
|
+
# Extends the default Range#include? to support range comparisons.
|
3
|
+
# (1..5).include?(1..5) # => true
|
4
|
+
# (1..5).include?(2..3) # => true
|
5
|
+
# (1..5).include?(2..6) # => false
|
6
|
+
#
|
7
|
+
# The native Range#include? behavior is untouched.
|
8
|
+
# ("a".."f").include?("c") # => true
|
9
|
+
# (5..9).include?(11) # => false
|
10
|
+
def include_with_range?(value)
|
11
|
+
if value.is_a?(::Range)
|
12
|
+
operator = exclude_end? ? :< : :<=
|
13
|
+
end_value = value.exclude_end? ? last.succ : last
|
14
|
+
include_without_range?(value.first) && (value.last <=> end_value).send(operator, 0)
|
15
|
+
else
|
16
|
+
include_without_range?(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method_chain :include?, :range
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'active_support/core_ext/kernel/reporting'
|
2
|
+
|
3
|
+
# Fixes the rexml vulnerability disclosed at:
|
4
|
+
# http://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/
|
5
|
+
# This fix is identical to rexml-expansion-fix version 1.0.1.
|
6
|
+
#
|
7
|
+
# We still need to distribute this fix because albeit the REXML
|
8
|
+
# in recent 1.8.7s is patched, it wasn't in early patchlevels.
|
9
|
+
require 'rexml/rexml'
|
10
|
+
|
11
|
+
# Earlier versions of rexml defined REXML::Version, newer ones REXML::VERSION
|
12
|
+
unless (defined?(REXML::VERSION) ? REXML::VERSION : REXML::Version) > "3.1.7.2"
|
13
|
+
silence_warnings { require 'rexml/document' }
|
14
|
+
|
15
|
+
# REXML in 1.8.7 has the patch but early patchlevels didn't update Version from 3.1.7.2.
|
16
|
+
unless REXML::Document.respond_to?(:entity_expansion_limit=)
|
17
|
+
silence_warnings { require 'rexml/entity' }
|
18
|
+
|
19
|
+
module REXML #:nodoc:
|
20
|
+
class Entity < Child #:nodoc:
|
21
|
+
undef_method :unnormalized
|
22
|
+
def unnormalized
|
23
|
+
document.record_entity_expansion! if document
|
24
|
+
v = value()
|
25
|
+
return nil if v.nil?
|
26
|
+
@unnormalized = Text::unnormalize(v, parent)
|
27
|
+
@unnormalized
|
28
|
+
end
|
29
|
+
end
|
30
|
+
class Document < Element #:nodoc:
|
31
|
+
@@entity_expansion_limit = 10_000
|
32
|
+
def self.entity_expansion_limit= val
|
33
|
+
@@entity_expansion_limit = val
|
34
|
+
end
|
35
|
+
|
36
|
+
def record_entity_expansion!
|
37
|
+
@number_of_expansions ||= 0
|
38
|
+
@number_of_expansions += 1
|
39
|
+
if @number_of_expansions > @@entity_expansion_limit
|
40
|
+
raise "Number of entity expansions exceeded, processing aborted."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'active_support/core_ext/string/conversions'
|
2
|
+
require 'active_support/core_ext/string/filters'
|
3
|
+
require 'active_support/core_ext/string/multibyte'
|
4
|
+
require 'active_support/core_ext/string/starts_ends_with'
|
5
|
+
require 'active_support/core_ext/string/inflections'
|
6
|
+
require 'active_support/core_ext/string/access'
|
7
|
+
require 'active_support/core_ext/string/xchar'
|
8
|
+
require 'active_support/core_ext/string/behavior'
|
9
|
+
require 'active_support/core_ext/string/interpolation'
|
10
|
+
require 'active_support/core_ext/string/output_safety'
|
11
|
+
require 'active_support/core_ext/string/exclude'
|
12
|
+
require 'active_support/core_ext/string/encoding'
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "active_support/multibyte"
|
2
|
+
|
3
|
+
class String
|
4
|
+
unless '1.9'.respond_to?(:force_encoding)
|
5
|
+
# Returns the character at the +position+ treating the string as an array (where 0 is the first character).
|
6
|
+
#
|
7
|
+
# Examples:
|
8
|
+
# "hello".at(0) # => "h"
|
9
|
+
# "hello".at(4) # => "o"
|
10
|
+
# "hello".at(10) # => ERROR if < 1.9, nil in 1.9
|
11
|
+
def at(position)
|
12
|
+
mb_chars[position, 1].to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character).
|
16
|
+
#
|
17
|
+
# Examples:
|
18
|
+
# "hello".from(0) # => "hello"
|
19
|
+
# "hello".from(2) # => "llo"
|
20
|
+
# "hello".from(10) # => "" if < 1.9, nil in 1.9
|
21
|
+
def from(position)
|
22
|
+
mb_chars[position..-1].to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character).
|
26
|
+
#
|
27
|
+
# Examples:
|
28
|
+
# "hello".to(0) # => "h"
|
29
|
+
# "hello".to(2) # => "hel"
|
30
|
+
# "hello".to(10) # => "hello"
|
31
|
+
def to(position)
|
32
|
+
mb_chars[0..position].to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the first character of the string or the first +limit+ characters.
|
36
|
+
#
|
37
|
+
# Examples:
|
38
|
+
# "hello".first # => "h"
|
39
|
+
# "hello".first(2) # => "he"
|
40
|
+
# "hello".first(10) # => "hello"
|
41
|
+
def first(limit = 1)
|
42
|
+
if limit == 0
|
43
|
+
''
|
44
|
+
elsif limit >= size
|
45
|
+
self
|
46
|
+
else
|
47
|
+
mb_chars[0...limit].to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the last character of the string or the last +limit+ characters.
|
52
|
+
#
|
53
|
+
# Examples:
|
54
|
+
# "hello".last # => "o"
|
55
|
+
# "hello".last(2) # => "lo"
|
56
|
+
# "hello".last(10) # => "hello"
|
57
|
+
def last(limit = 1)
|
58
|
+
if limit == 0
|
59
|
+
''
|
60
|
+
elsif limit >= size
|
61
|
+
self
|
62
|
+
else
|
63
|
+
mb_chars[(-limit)..-1].to_s
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
def at(position)
|
68
|
+
self[position]
|
69
|
+
end
|
70
|
+
|
71
|
+
def from(position)
|
72
|
+
self[position..-1]
|
73
|
+
end
|
74
|
+
|
75
|
+
def to(position)
|
76
|
+
self[0..position]
|
77
|
+
end
|
78
|
+
|
79
|
+
def first(limit = 1)
|
80
|
+
if limit == 0
|
81
|
+
''
|
82
|
+
elsif limit >= size
|
83
|
+
self
|
84
|
+
else
|
85
|
+
to(limit - 1)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def last(limit = 1)
|
90
|
+
if limit == 0
|
91
|
+
''
|
92
|
+
elsif limit >= size
|
93
|
+
self
|
94
|
+
else
|
95
|
+
from(-limit)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|