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.
- 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,29 +0,0 @@
|
|
1
|
-
module ActiveSupport
|
2
|
-
module Concern
|
3
|
-
def self.extended(base)
|
4
|
-
base.instance_variable_set("@_dependencies", [])
|
5
|
-
end
|
6
|
-
|
7
|
-
def append_features(base)
|
8
|
-
if base.instance_variable_defined?("@_dependencies")
|
9
|
-
base.instance_variable_get("@_dependencies") << self
|
10
|
-
return false
|
11
|
-
else
|
12
|
-
return false if base < self
|
13
|
-
@_dependencies.each { |dep| base.send(:include, dep) }
|
14
|
-
super
|
15
|
-
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
|
16
|
-
base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods")
|
17
|
-
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def included(base = nil, &block)
|
22
|
-
if base.nil?
|
23
|
-
@_included_block = block
|
24
|
-
else
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'active_support/ordered_options'
|
3
|
-
require 'active_support/core_ext/kernel/singleton_class'
|
4
|
-
require 'active_support/core_ext/module/delegation'
|
5
|
-
|
6
|
-
module ActiveSupport
|
7
|
-
module Configurable
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def config
|
12
|
-
@config ||= ActiveSupport::InheritableOptions.new(superclass.respond_to?(:config) ? superclass.config : {})
|
13
|
-
end
|
14
|
-
|
15
|
-
def configure
|
16
|
-
yield config
|
17
|
-
end
|
18
|
-
|
19
|
-
def config_accessor(*names)
|
20
|
-
names.each do |name|
|
21
|
-
code, line = <<-RUBY, __LINE__ + 1
|
22
|
-
def #{name}; config.#{name}; end
|
23
|
-
def #{name}=(value); config.#{name} = value; end
|
24
|
-
RUBY
|
25
|
-
|
26
|
-
singleton_class.class_eval code, __FILE__, line
|
27
|
-
class_eval code, __FILE__, line
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def config
|
33
|
-
@config ||= ActiveSupport::InheritableOptions.new(self.class.config)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/array/wrap'
|
2
|
-
require 'active_support/core_ext/array/access'
|
3
|
-
require 'active_support/core_ext/array/uniq_by'
|
4
|
-
require 'active_support/core_ext/array/conversions'
|
5
|
-
require 'active_support/core_ext/array/extract_options'
|
6
|
-
require 'active_support/core_ext/array/grouping'
|
7
|
-
require 'active_support/core_ext/array/random_access'
|
@@ -1,46 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
# Returns the tail of the array from +position+.
|
3
|
-
#
|
4
|
-
# %w( a b c d ).from(0) # => %w( a b c d )
|
5
|
-
# %w( a b c d ).from(2) # => %w( c d )
|
6
|
-
# %w( a b c d ).from(10) # => nil
|
7
|
-
# %w().from(0) # => %w()
|
8
|
-
def from(position)
|
9
|
-
self[position..-1]
|
10
|
-
end
|
11
|
-
|
12
|
-
# Returns the beginning of the array up to +position+.
|
13
|
-
#
|
14
|
-
# %w( a b c d ).to(0) # => %w( a )
|
15
|
-
# %w( a b c d ).to(2) # => %w( a b c )
|
16
|
-
# %w( a b c d ).to(10) # => %w( a b c d )
|
17
|
-
# %w().to(0) # => %w()
|
18
|
-
def to(position)
|
19
|
-
self[0..position]
|
20
|
-
end
|
21
|
-
|
22
|
-
# Equal to <tt>self[1]</tt>.
|
23
|
-
def second
|
24
|
-
self[1]
|
25
|
-
end
|
26
|
-
|
27
|
-
# Equal to <tt>self[2]</tt>.
|
28
|
-
def third
|
29
|
-
self[2]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Equal to <tt>self[3]</tt>.
|
33
|
-
def fourth
|
34
|
-
self[3]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Equal to <tt>self[4]</tt>.
|
38
|
-
def fifth
|
39
|
-
self[4]
|
40
|
-
end
|
41
|
-
|
42
|
-
# Equal to <tt>self[41]</tt>. Also known as accessing "the reddit".
|
43
|
-
def forty_two
|
44
|
-
self[41]
|
45
|
-
end
|
46
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
require 'active_support/xml_mini'
|
2
|
-
require 'active_support/core_ext/hash/keys'
|
3
|
-
require 'active_support/core_ext/hash/reverse_merge'
|
4
|
-
require 'active_support/core_ext/string/inflections'
|
5
|
-
|
6
|
-
class Array
|
7
|
-
# Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
|
8
|
-
# * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", ")
|
9
|
-
# * <tt>:two_words_connector</tt> - The sign or word used to join the elements in arrays with two elements (default: " and ")
|
10
|
-
# * <tt>:last_word_connector</tt> - The sign or word used to join the last element in arrays with three or more elements (default: ", and ")
|
11
|
-
def to_sentence(options = {})
|
12
|
-
if defined?(I18n)
|
13
|
-
default_words_connector = I18n.translate(:'support.array.words_connector', :locale => options[:locale])
|
14
|
-
default_two_words_connector = I18n.translate(:'support.array.two_words_connector', :locale => options[:locale])
|
15
|
-
default_last_word_connector = I18n.translate(:'support.array.last_word_connector', :locale => options[:locale])
|
16
|
-
else
|
17
|
-
default_words_connector = ", "
|
18
|
-
default_two_words_connector = " and "
|
19
|
-
default_last_word_connector = ", and "
|
20
|
-
end
|
21
|
-
|
22
|
-
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
|
23
|
-
options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector
|
24
|
-
|
25
|
-
case length
|
26
|
-
when 0
|
27
|
-
""
|
28
|
-
when 1
|
29
|
-
self[0].to_s
|
30
|
-
when 2
|
31
|
-
"#{self[0]}#{options[:two_words_connector]}#{self[1]}"
|
32
|
-
else
|
33
|
-
"#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Converts a collection of elements into a formatted string by calling
|
38
|
-
# <tt>to_s</tt> on all elements and joining them:
|
39
|
-
#
|
40
|
-
# Blog.find(:all).to_formatted_s # => "First PostSecond PostThird Post"
|
41
|
-
#
|
42
|
-
# Adding in the <tt>:db</tt> argument as the format yields a prettier
|
43
|
-
# output:
|
44
|
-
#
|
45
|
-
# Blog.find(:all).to_formatted_s(:db) # => "First Post,Second Post,Third Post"
|
46
|
-
def to_formatted_s(format = :default)
|
47
|
-
case format
|
48
|
-
when :db
|
49
|
-
if respond_to?(:empty?) && self.empty?
|
50
|
-
"null"
|
51
|
-
else
|
52
|
-
collect { |element| element.id }.join(",")
|
53
|
-
end
|
54
|
-
else
|
55
|
-
to_default_s
|
56
|
-
end
|
57
|
-
end
|
58
|
-
alias_method :to_default_s, :to_s
|
59
|
-
alias_method :to_s, :to_formatted_s
|
60
|
-
|
61
|
-
# Returns a string that represents this array in XML by sending +to_xml+
|
62
|
-
# to each element. Active Record collections delegate their representation
|
63
|
-
# in XML to this method.
|
64
|
-
#
|
65
|
-
# All elements are expected to respond to +to_xml+, if any of them does
|
66
|
-
# not an exception is raised.
|
67
|
-
#
|
68
|
-
# The root node reflects the class name of the first element in plural
|
69
|
-
# if all elements belong to the same type and that's not Hash:
|
70
|
-
#
|
71
|
-
# customer.projects.to_xml
|
72
|
-
#
|
73
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
74
|
-
# <projects type="array">
|
75
|
-
# <project>
|
76
|
-
# <amount type="decimal">20000.0</amount>
|
77
|
-
# <customer-id type="integer">1567</customer-id>
|
78
|
-
# <deal-date type="date">2008-04-09</deal-date>
|
79
|
-
# ...
|
80
|
-
# </project>
|
81
|
-
# <project>
|
82
|
-
# <amount type="decimal">57230.0</amount>
|
83
|
-
# <customer-id type="integer">1567</customer-id>
|
84
|
-
# <deal-date type="date">2008-04-15</deal-date>
|
85
|
-
# ...
|
86
|
-
# </project>
|
87
|
-
# </projects>
|
88
|
-
#
|
89
|
-
# Otherwise the root element is "records":
|
90
|
-
#
|
91
|
-
# [{:foo => 1, :bar => 2}, {:baz => 3}].to_xml
|
92
|
-
#
|
93
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
94
|
-
# <records type="array">
|
95
|
-
# <record>
|
96
|
-
# <bar type="integer">2</bar>
|
97
|
-
# <foo type="integer">1</foo>
|
98
|
-
# </record>
|
99
|
-
# <record>
|
100
|
-
# <baz type="integer">3</baz>
|
101
|
-
# </record>
|
102
|
-
# </records>
|
103
|
-
#
|
104
|
-
# If the collection is empty the root element is "nil-classes" by default:
|
105
|
-
#
|
106
|
-
# [].to_xml
|
107
|
-
#
|
108
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
109
|
-
# <nil-classes type="array"/>
|
110
|
-
#
|
111
|
-
# To ensure a meaningful root element use the <tt>:root</tt> option:
|
112
|
-
#
|
113
|
-
# customer_with_no_projects.projects.to_xml(:root => "projects")
|
114
|
-
#
|
115
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
116
|
-
# <projects type="array"/>
|
117
|
-
#
|
118
|
-
# By default root children have as node name the one of the root
|
119
|
-
# singularized. You can change it with the <tt>:children</tt> option.
|
120
|
-
#
|
121
|
-
# The +options+ hash is passed downwards:
|
122
|
-
#
|
123
|
-
# Message.all.to_xml(:skip_types => true)
|
124
|
-
#
|
125
|
-
# <?xml version="1.0" encoding="UTF-8"?>
|
126
|
-
# <messages>
|
127
|
-
# <message>
|
128
|
-
# <created-at>2008-03-07T09:58:18+01:00</created-at>
|
129
|
-
# <id>1</id>
|
130
|
-
# <name>1</name>
|
131
|
-
# <updated-at>2008-03-07T09:58:18+01:00</updated-at>
|
132
|
-
# <user-id>1</user-id>
|
133
|
-
# </message>
|
134
|
-
# </messages>
|
135
|
-
#
|
136
|
-
def to_xml(options = {})
|
137
|
-
require 'active_support/builder' unless defined?(Builder)
|
138
|
-
|
139
|
-
options = options.dup
|
140
|
-
options[:indent] ||= 2
|
141
|
-
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
142
|
-
options[:root] ||= if first.class.to_s != "Hash" && all? { |e| e.is_a?(first.class) }
|
143
|
-
underscored = ActiveSupport::Inflector.underscore(first.class.name)
|
144
|
-
ActiveSupport::Inflector.pluralize(underscored).tr('/', '_')
|
145
|
-
else
|
146
|
-
"objects"
|
147
|
-
end
|
148
|
-
|
149
|
-
builder = options[:builder]
|
150
|
-
builder.instruct! unless options.delete(:skip_instruct)
|
151
|
-
|
152
|
-
root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
|
153
|
-
children = options.delete(:children) || root.singularize
|
154
|
-
|
155
|
-
attributes = options[:skip_types] ? {} : {:type => "array"}
|
156
|
-
return builder.tag!(root, attributes) if empty?
|
157
|
-
|
158
|
-
builder.__send__(:method_missing, root, attributes) do
|
159
|
-
each { |value| ActiveSupport::XmlMini.to_tag(children, value, options) }
|
160
|
-
yield builder if block_given?
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
# By default, only instances of Hash itself are extractable.
|
3
|
-
# Subclasses of Hash may implement this method and return
|
4
|
-
# true to declare themselves as extractable. If a Hash
|
5
|
-
# is extractable, Array#extract_options! pops it from
|
6
|
-
# the Array when it is the last element of the Array.
|
7
|
-
def extractable_options?
|
8
|
-
instance_of?(Hash)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class Array
|
13
|
-
# Extracts options from a set of arguments. Removes and returns the last
|
14
|
-
# element in the array if it's a hash, otherwise returns a blank hash.
|
15
|
-
#
|
16
|
-
# def options(*args)
|
17
|
-
# args.extract_options!
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# options(1, 2) # => {}
|
21
|
-
# options(1, 2, :a => :b) # => {:a=>:b}
|
22
|
-
def extract_options!
|
23
|
-
if last.is_a?(Hash) && last.extractable_options?
|
24
|
-
pop
|
25
|
-
else
|
26
|
-
{}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'enumerator'
|
2
|
-
|
3
|
-
class Array
|
4
|
-
# Splits or iterates over the array in groups of size +number+,
|
5
|
-
# padding any remaining slots with +fill_with+ unless it is +false+.
|
6
|
-
#
|
7
|
-
# %w(1 2 3 4 5 6 7).in_groups_of(3) {|group| p group}
|
8
|
-
# ["1", "2", "3"]
|
9
|
-
# ["4", "5", "6"]
|
10
|
-
# ["7", nil, nil]
|
11
|
-
#
|
12
|
-
# %w(1 2 3).in_groups_of(2, ' ') {|group| p group}
|
13
|
-
# ["1", "2"]
|
14
|
-
# ["3", " "]
|
15
|
-
#
|
16
|
-
# %w(1 2 3).in_groups_of(2, false) {|group| p group}
|
17
|
-
# ["1", "2"]
|
18
|
-
# ["3"]
|
19
|
-
def in_groups_of(number, fill_with = nil)
|
20
|
-
if fill_with == false
|
21
|
-
collection = self
|
22
|
-
else
|
23
|
-
# size % number gives how many extra we have;
|
24
|
-
# subtracting from number gives how many to add;
|
25
|
-
# modulo number ensures we don't add group of just fill.
|
26
|
-
padding = (number - size % number) % number
|
27
|
-
collection = dup.concat([fill_with] * padding)
|
28
|
-
end
|
29
|
-
|
30
|
-
if block_given?
|
31
|
-
collection.each_slice(number) { |slice| yield(slice) }
|
32
|
-
else
|
33
|
-
groups = []
|
34
|
-
collection.each_slice(number) { |group| groups << group }
|
35
|
-
groups
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Splits or iterates over the array in +number+ of groups, padding any
|
40
|
-
# remaining slots with +fill_with+ unless it is +false+.
|
41
|
-
#
|
42
|
-
# %w(1 2 3 4 5 6 7 8 9 10).in_groups(3) {|group| p group}
|
43
|
-
# ["1", "2", "3", "4"]
|
44
|
-
# ["5", "6", "7", nil]
|
45
|
-
# ["8", "9", "10", nil]
|
46
|
-
#
|
47
|
-
# %w(1 2 3 4 5 6 7).in_groups(3, ' ') {|group| p group}
|
48
|
-
# ["1", "2", "3"]
|
49
|
-
# ["4", "5", " "]
|
50
|
-
# ["6", "7", " "]
|
51
|
-
#
|
52
|
-
# %w(1 2 3 4 5 6 7).in_groups(3, false) {|group| p group}
|
53
|
-
# ["1", "2", "3"]
|
54
|
-
# ["4", "5"]
|
55
|
-
# ["6", "7"]
|
56
|
-
def in_groups(number, fill_with = nil)
|
57
|
-
# size / number gives minor group size;
|
58
|
-
# size % number gives how many objects need extra accomodation;
|
59
|
-
# each group hold either division or division + 1 items.
|
60
|
-
division = size / number
|
61
|
-
modulo = size % number
|
62
|
-
|
63
|
-
# create a new array avoiding dup
|
64
|
-
groups = []
|
65
|
-
start = 0
|
66
|
-
|
67
|
-
number.times do |index|
|
68
|
-
length = division + (modulo > 0 && modulo > index ? 1 : 0)
|
69
|
-
padding = fill_with != false &&
|
70
|
-
modulo > 0 && length == division ? 1 : 0
|
71
|
-
groups << slice(start, length).concat([fill_with] * padding)
|
72
|
-
start += length
|
73
|
-
end
|
74
|
-
|
75
|
-
if block_given?
|
76
|
-
groups.each { |g| yield(g) }
|
77
|
-
else
|
78
|
-
groups
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# Divides the array into one or more subarrays based on a delimiting +value+
|
83
|
-
# or the result of an optional block.
|
84
|
-
#
|
85
|
-
# [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]]
|
86
|
-
# (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
|
87
|
-
def split(value = nil)
|
88
|
-
using_block = block_given?
|
89
|
-
|
90
|
-
inject([[]]) do |results, element|
|
91
|
-
if (using_block && yield(element)) || (value == element)
|
92
|
-
results << []
|
93
|
-
else
|
94
|
-
results.last << element
|
95
|
-
end
|
96
|
-
|
97
|
-
results
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
# Backport of Array#sample based on Marc-Andre Lafortune's http://github.com/marcandre/backports/
|
3
|
-
def sample(n=nil)
|
4
|
-
return self[Kernel.rand(size)] if n.nil?
|
5
|
-
n = n.to_int
|
6
|
-
rescue Exception => e
|
7
|
-
raise TypeError, "Coercion error: #{n.inspect}.to_int => Integer failed:\n(#{e.message})"
|
8
|
-
else
|
9
|
-
raise TypeError, "Coercion error: obj.to_int did NOT return an Integer (was #{n.class})" unless n.kind_of? Integer
|
10
|
-
raise ArgumentError, "negative array size" if n < 0
|
11
|
-
n = size if n > size
|
12
|
-
result = Array.new(self)
|
13
|
-
n.times do |i|
|
14
|
-
r = i + Kernel.rand(size - i)
|
15
|
-
result[i], result[r] = result[r], result[i]
|
16
|
-
end
|
17
|
-
result[n..size] = []
|
18
|
-
result
|
19
|
-
end unless method_defined? :sample
|
20
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
# Return an unique array based on the criteria given as a proc.
|
3
|
-
#
|
4
|
-
# [1, 2, 3, 4].uniq_by { |i| i.odd? }
|
5
|
-
# #=> [1, 2]
|
6
|
-
#
|
7
|
-
def uniq_by
|
8
|
-
hash, array = {}, []
|
9
|
-
each { |i| hash[yield(i)] ||= (array << i) }
|
10
|
-
array
|
11
|
-
end
|
12
|
-
|
13
|
-
# Same as uniq_by, but modifies self.
|
14
|
-
def uniq_by!
|
15
|
-
replace(uniq_by{ |i| yield(i) })
|
16
|
-
end
|
17
|
-
end
|