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,14 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
if instance_methods[0].is_a?(Symbol)
|
3
|
-
def instance_method_names(*args)
|
4
|
-
instance_methods(*args).map(&:to_s)
|
5
|
-
end
|
6
|
-
|
7
|
-
def method_names(*args)
|
8
|
-
methods(*args).map(&:to_s)
|
9
|
-
end
|
10
|
-
else
|
11
|
-
alias_method :instance_method_names, :instance_methods
|
12
|
-
alias_method :method_names, :methods
|
13
|
-
end
|
14
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module/aliasing'
|
2
|
-
require 'active_support/core_ext/array/extract_options'
|
3
|
-
|
4
|
-
class Module
|
5
|
-
# Synchronize access around a method, delegating synchronization to a
|
6
|
-
# particular mutex. A mutex (either a Mutex, or any object that responds to
|
7
|
-
# #synchronize and yields to a block) must be provided as a final :with option.
|
8
|
-
# The :with option should be a symbol or string, and can represent a method,
|
9
|
-
# constant, or instance or class variable.
|
10
|
-
# Example:
|
11
|
-
# class SharedCache
|
12
|
-
# @@lock = Mutex.new
|
13
|
-
# def expire
|
14
|
-
# ...
|
15
|
-
# end
|
16
|
-
# synchronize :expire, :with => :@@lock
|
17
|
-
# end
|
18
|
-
def synchronize(*methods)
|
19
|
-
options = methods.extract_options!
|
20
|
-
unless options.is_a?(Hash) && with = options[:with]
|
21
|
-
raise ArgumentError, "Synchronization needs a mutex. Supply an options hash with a :with key as the last argument (e.g. synchronize :hello, :with => :@mutex)."
|
22
|
-
end
|
23
|
-
|
24
|
-
methods.each do |method|
|
25
|
-
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
|
26
|
-
|
27
|
-
if method_defined?("#{aliased_method}_without_synchronization#{punctuation}")
|
28
|
-
raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
|
29
|
-
end
|
30
|
-
|
31
|
-
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
32
|
-
def #{aliased_method}_with_synchronization#{punctuation}(*args, &block) # def expire_with_synchronization(*args, &block)
|
33
|
-
#{with}.synchronize do # @@lock.synchronize do
|
34
|
-
#{aliased_method}_without_synchronization#{punctuation}(*args, &block) # expire_without_synchronization(*args, &block)
|
35
|
-
end # end
|
36
|
-
end # end
|
37
|
-
EOS
|
38
|
-
|
39
|
-
alias_method_chain method, :synchronization
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class NameError
|
2
|
-
# Extract the name of the missing constant from the exception message.
|
3
|
-
def missing_name
|
4
|
-
if /undefined local variable or method/ !~ message
|
5
|
-
$1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
# Was this exception raised because the given name was missing?
|
10
|
-
def missing_name?(name)
|
11
|
-
if name.is_a? Symbol
|
12
|
-
last_name = (missing_name || '').split('::').last
|
13
|
-
last_name == name.to_s
|
14
|
-
else
|
15
|
-
missing_name == name.to_s
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
class Numeric
|
2
|
-
KILOBYTE = 1024
|
3
|
-
MEGABYTE = KILOBYTE * 1024
|
4
|
-
GIGABYTE = MEGABYTE * 1024
|
5
|
-
TERABYTE = GIGABYTE * 1024
|
6
|
-
PETABYTE = TERABYTE * 1024
|
7
|
-
EXABYTE = PETABYTE * 1024
|
8
|
-
|
9
|
-
# Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes
|
10
|
-
def bytes
|
11
|
-
self
|
12
|
-
end
|
13
|
-
alias :byte :bytes
|
14
|
-
|
15
|
-
def kilobytes
|
16
|
-
self * KILOBYTE
|
17
|
-
end
|
18
|
-
alias :kilobyte :kilobytes
|
19
|
-
|
20
|
-
def megabytes
|
21
|
-
self * MEGABYTE
|
22
|
-
end
|
23
|
-
alias :megabyte :megabytes
|
24
|
-
|
25
|
-
def gigabytes
|
26
|
-
self * GIGABYTE
|
27
|
-
end
|
28
|
-
alias :gigabyte :gigabytes
|
29
|
-
|
30
|
-
def terabytes
|
31
|
-
self * TERABYTE
|
32
|
-
end
|
33
|
-
alias :terabyte :terabytes
|
34
|
-
|
35
|
-
def petabytes
|
36
|
-
self * PETABYTE
|
37
|
-
end
|
38
|
-
alias :petabyte :petabytes
|
39
|
-
|
40
|
-
def exabytes
|
41
|
-
self * EXABYTE
|
42
|
-
end
|
43
|
-
alias :exabyte :exabytes
|
44
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'active_support/duration'
|
2
|
-
|
3
|
-
class Numeric
|
4
|
-
# Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
|
5
|
-
#
|
6
|
-
# These methods use Time#advance for precise date calculations when using from_now, ago, etc.
|
7
|
-
# as well as adding or subtracting their results from a Time object. For example:
|
8
|
-
#
|
9
|
-
# # equivalent to Time.now.advance(:months => 1)
|
10
|
-
# 1.month.from_now
|
11
|
-
#
|
12
|
-
# # equivalent to Time.now.advance(:years => 2)
|
13
|
-
# 2.years.from_now
|
14
|
-
#
|
15
|
-
# # equivalent to Time.now.advance(:months => 4, :years => 5)
|
16
|
-
# (4.months + 5.years).from_now
|
17
|
-
#
|
18
|
-
# While these methods provide precise calculation when used as in the examples above, care
|
19
|
-
# should be taken to note that this is not true if the result of `months', `years', etc is
|
20
|
-
# converted before use:
|
21
|
-
#
|
22
|
-
# # equivalent to 30.days.to_i.from_now
|
23
|
-
# 1.month.to_i.from_now
|
24
|
-
#
|
25
|
-
# # equivalent to 365.25.days.to_f.from_now
|
26
|
-
# 1.year.to_f.from_now
|
27
|
-
#
|
28
|
-
# In such cases, Ruby's core
|
29
|
-
# Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and
|
30
|
-
# Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision
|
31
|
-
# date and time arithmetic
|
32
|
-
def seconds
|
33
|
-
ActiveSupport::Duration.new(self, [[:seconds, self]])
|
34
|
-
end
|
35
|
-
alias :second :seconds
|
36
|
-
|
37
|
-
def minutes
|
38
|
-
ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]])
|
39
|
-
end
|
40
|
-
alias :minute :minutes
|
41
|
-
|
42
|
-
def hours
|
43
|
-
ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]])
|
44
|
-
end
|
45
|
-
alias :hour :hours
|
46
|
-
|
47
|
-
def days
|
48
|
-
ActiveSupport::Duration.new(self * 24.hours, [[:days, self]])
|
49
|
-
end
|
50
|
-
alias :day :days
|
51
|
-
|
52
|
-
def weeks
|
53
|
-
ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]])
|
54
|
-
end
|
55
|
-
alias :week :weeks
|
56
|
-
|
57
|
-
def fortnights
|
58
|
-
ActiveSupport::Duration.new(self * 2.weeks, [[:days, self * 14]])
|
59
|
-
end
|
60
|
-
alias :fortnight :fortnights
|
61
|
-
|
62
|
-
# Reads best without arguments: 10.minutes.ago
|
63
|
-
def ago(time = ::Time.now)
|
64
|
-
time - self
|
65
|
-
end
|
66
|
-
|
67
|
-
# Reads best with argument: 10.minutes.until(time)
|
68
|
-
alias :until :ago
|
69
|
-
|
70
|
-
# Reads best with argument: 10.minutes.since(time)
|
71
|
-
def since(time = ::Time.now)
|
72
|
-
time + self
|
73
|
-
end
|
74
|
-
|
75
|
-
# Reads best without arguments: 10.minutes.from_now
|
76
|
-
alias :from_now :since
|
77
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/object/acts_like'
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
require 'active_support/core_ext/object/duplicable'
|
4
|
-
require 'active_support/core_ext/object/try'
|
5
|
-
|
6
|
-
require 'active_support/core_ext/object/conversions'
|
7
|
-
require 'active_support/core_ext/object/instance_variables'
|
8
|
-
require 'active_support/core_ext/object/misc'
|
9
|
-
require 'active_support/core_ext/object/extending'
|
10
|
-
|
11
|
-
require 'active_support/core_ext/object/returning'
|
12
|
-
require 'active_support/core_ext/object/to_param'
|
13
|
-
require 'active_support/core_ext/object/to_query'
|
14
|
-
require 'active_support/core_ext/object/with_options'
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
# A duck-type assistant method. For example, Active Support extends Date
|
3
|
-
# to define an acts_like_date? method, and extends Time to define
|
4
|
-
# acts_like_time?. As a result, we can do "x.acts_like?(:time)" and
|
5
|
-
# "x.acts_like?(:date)" to do duck-type-safe comparisons, since classes that
|
6
|
-
# we want to act like Time simply need to define an acts_like_time? method.
|
7
|
-
def acts_like?(duck)
|
8
|
-
respond_to? :"acts_like_#{duck}?"
|
9
|
-
end
|
10
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
# An object is blank if it's false, empty, or a whitespace string.
|
3
|
-
# For example, "", " ", +nil+, [], and {} are blank.
|
4
|
-
#
|
5
|
-
# This simplifies:
|
6
|
-
#
|
7
|
-
# if !address.nil? && !address.empty?
|
8
|
-
#
|
9
|
-
# ...to:
|
10
|
-
#
|
11
|
-
# if !address.blank?
|
12
|
-
def blank?
|
13
|
-
respond_to?(:empty?) ? empty? : !self
|
14
|
-
end
|
15
|
-
|
16
|
-
# An object is present if it's not blank.
|
17
|
-
def present?
|
18
|
-
!blank?
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns object if it's #present? otherwise returns nil.
|
22
|
-
# object.presence is equivalent to object.present? ? object : nil.
|
23
|
-
#
|
24
|
-
# This is handy for any representation of objects where blank is the same
|
25
|
-
# as not present at all. For example, this simplifies a common check for
|
26
|
-
# HTTP POST/query parameters:
|
27
|
-
#
|
28
|
-
# state = params[:state] if params[:state].present?
|
29
|
-
# country = params[:country] if params[:country].present?
|
30
|
-
# region = state || country || 'US'
|
31
|
-
#
|
32
|
-
# ...becomes:
|
33
|
-
#
|
34
|
-
# region = params[:state].presence || params[:country].presence || 'US'
|
35
|
-
def presence
|
36
|
-
self if present?
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class NilClass #:nodoc:
|
41
|
-
def blank?
|
42
|
-
true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class FalseClass #:nodoc:
|
47
|
-
def blank?
|
48
|
-
true
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class TrueClass #:nodoc:
|
53
|
-
def blank?
|
54
|
-
false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class Array #:nodoc:
|
59
|
-
alias_method :blank?, :empty?
|
60
|
-
end
|
61
|
-
|
62
|
-
class Hash #:nodoc:
|
63
|
-
alias_method :blank?, :empty?
|
64
|
-
end
|
65
|
-
|
66
|
-
class String #:nodoc:
|
67
|
-
def blank?
|
68
|
-
self !~ /\S/
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class Numeric #:nodoc:
|
73
|
-
def blank?
|
74
|
-
false
|
75
|
-
end
|
76
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# Most objects are cloneable, but not all. For example you can't dup +nil+:
|
2
|
-
#
|
3
|
-
# nil.dup # => TypeError: can't dup NilClass
|
4
|
-
#
|
5
|
-
# Classes may signal their instances are not duplicable removing +dup+/+clone+
|
6
|
-
# or raising exceptions from them. So, to dup an arbitrary object you normally
|
7
|
-
# use an optimistic approach and are ready to catch an exception, say:
|
8
|
-
#
|
9
|
-
# arbitrary_object.dup rescue object
|
10
|
-
#
|
11
|
-
# Rails dups objects in a few critical spots where they are not that arbitrary.
|
12
|
-
# That rescue is very expensive (like 40 times slower than a predicate), and it
|
13
|
-
# is often triggered.
|
14
|
-
#
|
15
|
-
# That's why we hardcode the following cases and check duplicable? instead of
|
16
|
-
# using that rescue idiom.
|
17
|
-
class Object
|
18
|
-
# Can you safely .dup this object?
|
19
|
-
# False for nil, false, true, symbols, numbers, class and module objects; true otherwise.
|
20
|
-
def duplicable?
|
21
|
-
true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class NilClass #:nodoc:
|
26
|
-
def duplicable?
|
27
|
-
false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class FalseClass #:nodoc:
|
32
|
-
def duplicable?
|
33
|
-
false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class TrueClass #:nodoc:
|
38
|
-
def duplicable?
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class Symbol #:nodoc:
|
44
|
-
def duplicable?
|
45
|
-
false
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Numeric #:nodoc:
|
50
|
-
def duplicable?
|
51
|
-
false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Class #:nodoc:
|
56
|
-
def duplicable?
|
57
|
-
false
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class Module #:nodoc:
|
62
|
-
def duplicable?
|
63
|
-
false
|
64
|
-
end
|
65
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/class/subclasses'
|
2
|
-
|
3
|
-
class Object
|
4
|
-
# Exclude this class unless it's a subclass of our supers and is defined.
|
5
|
-
# We check defined? in case we find a removed class that has yet to be
|
6
|
-
# garbage collected. This also fails for anonymous classes -- please
|
7
|
-
# submit a patch if you have a workaround.
|
8
|
-
def subclasses_of(*superclasses) #:nodoc:
|
9
|
-
Class.subclasses_of(*superclasses)
|
10
|
-
end
|
11
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
# Returns a hash that maps instance variable names without "@" to their
|
3
|
-
# corresponding values. Keys are strings both in Ruby 1.8 and 1.9.
|
4
|
-
#
|
5
|
-
# class C
|
6
|
-
# def initialize(x, y)
|
7
|
-
# @x, @y = x, y
|
8
|
-
# end
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# C.new(0, 1).instance_values # => {"x" => 0, "y" => 1}
|
12
|
-
def instance_values #:nodoc:
|
13
|
-
instance_variables.inject({}) do |values, name|
|
14
|
-
values[name.to_s[1..-1]] = instance_variable_get(name)
|
15
|
-
values
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns an array of instance variable names including "@". They are strings
|
20
|
-
# both in Ruby 1.8 and 1.9.
|
21
|
-
#
|
22
|
-
# class C
|
23
|
-
# def initialize(x, y)
|
24
|
-
# @x, @y = x, y
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# C.new(0, 1).instance_variable_names # => ["@y", "@x"]
|
29
|
-
if RUBY_VERSION >= '1.9'
|
30
|
-
def instance_variable_names
|
31
|
-
instance_variables.map { |var| var.to_s }
|
32
|
-
end
|
33
|
-
else
|
34
|
-
alias_method :instance_variable_names, :instance_variables
|
35
|
-
end
|
36
|
-
|
37
|
-
# Copies the instance variables of +object+ into +self+.
|
38
|
-
#
|
39
|
-
# Instance variable names in the +exclude+ array are ignored. If +object+
|
40
|
-
# responds to <tt>protected_instance_variables</tt> the ones returned are
|
41
|
-
# also ignored. For example, Rails controllers implement that method.
|
42
|
-
#
|
43
|
-
# In both cases strings and symbols are understood, and they have to include
|
44
|
-
# the at sign.
|
45
|
-
#
|
46
|
-
# class C
|
47
|
-
# def initialize(x, y, z)
|
48
|
-
# @x, @y, @z = x, y, z
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# def protected_instance_variables
|
52
|
-
# %w(@z)
|
53
|
-
# end
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# a = C.new(0, 1, 2)
|
57
|
-
# b = C.new(3, 4, 5)
|
58
|
-
#
|
59
|
-
# a.copy_instance_variables_from(b, [:@y])
|
60
|
-
# # a is now: @x = 3, @y = 1, @z = 2
|
61
|
-
def copy_instance_variables_from(object, exclude = []) #:nodoc:
|
62
|
-
exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables
|
63
|
-
|
64
|
-
vars = object.instance_variables.map(&:to_s) - exclude.map(&:to_s)
|
65
|
-
vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
|
66
|
-
end
|
67
|
-
end
|