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,78 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
|
4
|
-
# = XmlMini Nokogiri implementation
|
5
|
-
module ActiveSupport
|
6
|
-
module XmlMini_Nokogiri #:nodoc:
|
7
|
-
extend self
|
8
|
-
|
9
|
-
# Parse an XML Document string or IO into a simple hash using libxml / nokogiri.
|
10
|
-
# data::
|
11
|
-
# XML Document string or IO to parse
|
12
|
-
def parse(data)
|
13
|
-
if !data.respond_to?(:read)
|
14
|
-
data = StringIO.new(data || '')
|
15
|
-
end
|
16
|
-
|
17
|
-
char = data.getc
|
18
|
-
if char.nil?
|
19
|
-
{}
|
20
|
-
else
|
21
|
-
data.ungetc(char)
|
22
|
-
doc = Nokogiri::XML(data)
|
23
|
-
raise doc.errors.first if doc.errors.length > 0
|
24
|
-
doc.to_hash
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module Conversions #:nodoc:
|
29
|
-
module Document #:nodoc:
|
30
|
-
def to_hash
|
31
|
-
root.to_hash
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module Node #:nodoc:
|
36
|
-
CONTENT_ROOT = '__content__'.freeze
|
37
|
-
|
38
|
-
# Convert XML document to hash
|
39
|
-
#
|
40
|
-
# hash::
|
41
|
-
# Hash to merge the converted element into.
|
42
|
-
def to_hash(hash={})
|
43
|
-
node_hash = {}
|
44
|
-
|
45
|
-
# Insert node hash into parent hash correctly.
|
46
|
-
case hash[name]
|
47
|
-
when Array then hash[name] << node_hash
|
48
|
-
when Hash then hash[name] = [hash[name], node_hash]
|
49
|
-
when nil then hash[name] = node_hash
|
50
|
-
end
|
51
|
-
|
52
|
-
# Handle child elements
|
53
|
-
children.each do |c|
|
54
|
-
if c.element?
|
55
|
-
c.to_hash(node_hash)
|
56
|
-
elsif c.text? || c.cdata?
|
57
|
-
node_hash[CONTENT_ROOT] ||= ''
|
58
|
-
node_hash[CONTENT_ROOT] << c.content
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Remove content node if it is blank and there are child tags
|
63
|
-
if node_hash.length > 1 && node_hash[CONTENT_ROOT].blank?
|
64
|
-
node_hash.delete(CONTENT_ROOT)
|
65
|
-
end
|
66
|
-
|
67
|
-
# Handle attributes
|
68
|
-
attribute_nodes.each { |a| node_hash[a.node_name] = a.value }
|
69
|
-
|
70
|
-
hash
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
Nokogiri::XML::Document.send(:include, Conversions::Document)
|
76
|
-
Nokogiri::XML::Node.send(:include, Conversions::Node)
|
77
|
-
end
|
78
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
|
4
|
-
# = XmlMini Nokogiri implementation using a SAX-based parser
|
5
|
-
module ActiveSupport
|
6
|
-
module XmlMini_NokogiriSAX
|
7
|
-
extend self
|
8
|
-
|
9
|
-
# Class that will build the hash while the XML document
|
10
|
-
# is being parsed using SAX events.
|
11
|
-
class HashBuilder < Nokogiri::XML::SAX::Document
|
12
|
-
|
13
|
-
CONTENT_KEY = '__content__'.freeze
|
14
|
-
HASH_SIZE_KEY = '__hash_size__'.freeze
|
15
|
-
|
16
|
-
attr_reader :hash
|
17
|
-
|
18
|
-
def current_hash
|
19
|
-
@hash_stack.last
|
20
|
-
end
|
21
|
-
|
22
|
-
def start_document
|
23
|
-
@hash = {}
|
24
|
-
@hash_stack = [@hash]
|
25
|
-
end
|
26
|
-
|
27
|
-
def end_document
|
28
|
-
raise "Parse stack not empty!" if @hash_stack.size > 1
|
29
|
-
end
|
30
|
-
|
31
|
-
def error(error_message)
|
32
|
-
raise error_message
|
33
|
-
end
|
34
|
-
|
35
|
-
def start_element(name, attrs = [])
|
36
|
-
new_hash = { CONTENT_KEY => '' }
|
37
|
-
new_hash[attrs.shift] = attrs.shift while attrs.length > 0
|
38
|
-
new_hash[HASH_SIZE_KEY] = new_hash.size + 1
|
39
|
-
|
40
|
-
case current_hash[name]
|
41
|
-
when Array then current_hash[name] << new_hash
|
42
|
-
when Hash then current_hash[name] = [current_hash[name], new_hash]
|
43
|
-
when nil then current_hash[name] = new_hash
|
44
|
-
end
|
45
|
-
|
46
|
-
@hash_stack.push(new_hash)
|
47
|
-
end
|
48
|
-
|
49
|
-
def end_element(name)
|
50
|
-
if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ''
|
51
|
-
current_hash.delete(CONTENT_KEY)
|
52
|
-
end
|
53
|
-
@hash_stack.pop
|
54
|
-
end
|
55
|
-
|
56
|
-
def characters(string)
|
57
|
-
current_hash[CONTENT_KEY] << string
|
58
|
-
end
|
59
|
-
|
60
|
-
alias_method :cdata_block, :characters
|
61
|
-
end
|
62
|
-
|
63
|
-
attr_accessor :document_class
|
64
|
-
self.document_class = HashBuilder
|
65
|
-
|
66
|
-
def parse(data)
|
67
|
-
if !data.respond_to?(:read)
|
68
|
-
data = StringIO.new(data || '')
|
69
|
-
end
|
70
|
-
|
71
|
-
char = data.getc
|
72
|
-
if char.nil?
|
73
|
-
{}
|
74
|
-
else
|
75
|
-
data.ungetc(char)
|
76
|
-
document = self.document_class.new
|
77
|
-
parser = Nokogiri::XML::SAX::Parser.new(document)
|
78
|
-
parser.parse(data)
|
79
|
-
document.hash
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/kernel/reporting'
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
|
4
|
-
# = XmlMini ReXML implementation
|
5
|
-
module ActiveSupport
|
6
|
-
module XmlMini_REXML #:nodoc:
|
7
|
-
extend self
|
8
|
-
|
9
|
-
CONTENT_KEY = '__content__'.freeze
|
10
|
-
|
11
|
-
# Parse an XML Document string or IO into a simple hash
|
12
|
-
#
|
13
|
-
# Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
|
14
|
-
# and uses the defaults from ActiveSupport
|
15
|
-
#
|
16
|
-
# data::
|
17
|
-
# XML Document string or IO to parse
|
18
|
-
def parse(data)
|
19
|
-
if !data.respond_to?(:read)
|
20
|
-
data = StringIO.new(data || '')
|
21
|
-
end
|
22
|
-
|
23
|
-
char = data.getc
|
24
|
-
if char.nil?
|
25
|
-
{}
|
26
|
-
else
|
27
|
-
data.ungetc(char)
|
28
|
-
silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
|
29
|
-
doc = REXML::Document.new(data)
|
30
|
-
|
31
|
-
if doc.root
|
32
|
-
merge_element!({}, doc.root)
|
33
|
-
else
|
34
|
-
raise REXML::ParseException,
|
35
|
-
"The document #{doc.to_s.inspect} does not have a valid root"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
# Convert an XML element and merge into the hash
|
42
|
-
#
|
43
|
-
# hash::
|
44
|
-
# Hash to merge the converted element into.
|
45
|
-
# element::
|
46
|
-
# XML element to merge into hash
|
47
|
-
def merge_element!(hash, element)
|
48
|
-
merge!(hash, element.name, collapse(element))
|
49
|
-
end
|
50
|
-
|
51
|
-
# Actually converts an XML document element into a data structure.
|
52
|
-
#
|
53
|
-
# element::
|
54
|
-
# The document element to be collapsed.
|
55
|
-
def collapse(element)
|
56
|
-
hash = get_attributes(element)
|
57
|
-
|
58
|
-
if element.has_elements?
|
59
|
-
element.each_element {|child| merge_element!(hash, child) }
|
60
|
-
merge_texts!(hash, element) unless empty_content?(element)
|
61
|
-
hash
|
62
|
-
else
|
63
|
-
merge_texts!(hash, element)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Merge all the texts of an element into the hash
|
68
|
-
#
|
69
|
-
# hash::
|
70
|
-
# Hash to add the converted element to.
|
71
|
-
# element::
|
72
|
-
# XML element whose texts are to me merged into the hash
|
73
|
-
def merge_texts!(hash, element)
|
74
|
-
unless element.has_text?
|
75
|
-
hash
|
76
|
-
else
|
77
|
-
# must use value to prevent double-escaping
|
78
|
-
texts = ''
|
79
|
-
element.texts.each { |t| texts << t.value }
|
80
|
-
merge!(hash, CONTENT_KEY, texts)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Adds a new key/value pair to an existing Hash. If the key to be added
|
85
|
-
# already exists and the existing value associated with key is not
|
86
|
-
# an Array, it will be wrapped in an Array. Then the new value is
|
87
|
-
# appended to that Array.
|
88
|
-
#
|
89
|
-
# hash::
|
90
|
-
# Hash to add key/value pair to.
|
91
|
-
# key::
|
92
|
-
# Key to be added.
|
93
|
-
# value::
|
94
|
-
# Value to be associated with key.
|
95
|
-
def merge!(hash, key, value)
|
96
|
-
if hash.has_key?(key)
|
97
|
-
if hash[key].instance_of?(Array)
|
98
|
-
hash[key] << value
|
99
|
-
else
|
100
|
-
hash[key] = [hash[key], value]
|
101
|
-
end
|
102
|
-
elsif value.instance_of?(Array)
|
103
|
-
hash[key] = [value]
|
104
|
-
else
|
105
|
-
hash[key] = value
|
106
|
-
end
|
107
|
-
hash
|
108
|
-
end
|
109
|
-
|
110
|
-
# Converts the attributes array of an XML element into a hash.
|
111
|
-
# Returns an empty Hash if node has no attributes.
|
112
|
-
#
|
113
|
-
# element::
|
114
|
-
# XML element to extract attributes from.
|
115
|
-
def get_attributes(element)
|
116
|
-
attributes = {}
|
117
|
-
element.attributes.each { |n,v| attributes[n] = v }
|
118
|
-
attributes
|
119
|
-
end
|
120
|
-
|
121
|
-
# Determines if a document element has text content
|
122
|
-
#
|
123
|
-
# element::
|
124
|
-
# XML element to be checked.
|
125
|
-
def empty_content?(element)
|
126
|
-
element.texts.join.blank?
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module CSD
|
3
|
-
class GlobalOpenStruct
|
4
|
-
|
5
|
-
def self.method_missing(meth, *args, &block)
|
6
|
-
if meth.to_s.ends_with?('=')
|
7
|
-
class_variable_set("@@#{meth.to_s.chop}".to_sym, *args)
|
8
|
-
else
|
9
|
-
begin
|
10
|
-
class_variable_get("@@#{meth}".to_sym)
|
11
|
-
rescue NameError => e
|
12
|
-
#UI.debug "The option `#{meth}´ was accessed but not available." # FIXME: This line causes a recursion error :)
|
13
|
-
nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
data/lib/csd/path.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.join(File.dirname(__FILE__), 'global_open_struct')
|
3
|
-
|
4
|
-
module CSD
|
5
|
-
class Path < GlobalOpenStruct
|
6
|
-
|
7
|
-
def self.root
|
8
|
-
@@root ||= Dir.pwd
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.root=(path)
|
12
|
-
@@root = path
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.gem
|
16
|
-
@@gem ||= File.expand_path(File.join(File.dirname(__FILE__), '..' ,'..'))
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.vendor
|
20
|
-
@@vendor ||= File.join(gem, 'vendor')
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.applications
|
24
|
-
@@applications ||= File.expand_path(File.join(gem, 'lib', 'csd', 'application'))
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.applications=(path)
|
28
|
-
@@applications = File.expand_path(path)
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
data/lib/csd/ui.rb
DELETED
data/lib/csd/ui/cli.rb
DELETED
data/lib/csd/ui/ui.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module CSD
|
3
|
-
class UI
|
4
|
-
|
5
|
-
include Gem::UserInteraction
|
6
|
-
|
7
|
-
# These are all possible user interactions provided by the UI
|
8
|
-
#
|
9
|
-
INTERACTIONS = %w{ separator debug info warn error ask ask_yes_no die }
|
10
|
-
|
11
|
-
def separator
|
12
|
-
say
|
13
|
-
end
|
14
|
-
|
15
|
-
def debug(message)
|
16
|
-
say "DEBUG: #{message}".magenta if Options.debug and !Options.silent
|
17
|
-
end
|
18
|
-
|
19
|
-
def info(message)
|
20
|
-
say message if !Options.silent
|
21
|
-
end
|
22
|
-
|
23
|
-
def warn(message)
|
24
|
-
say 'NOTE: '.red + message.red if !Options.silent
|
25
|
-
end
|
26
|
-
|
27
|
-
def error(message)
|
28
|
-
say('ERROR: '.red.blink + message.red) if !Options.silent
|
29
|
-
end
|
30
|
-
|
31
|
-
def die(message)
|
32
|
-
say('ERROR: '.red.blink + message.red) if !Options.silent
|
33
|
-
abort
|
34
|
-
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
|
38
|
-
# This is just a convenience wrapper so that +UI.myinteraction+ will map to +CSD.ui.myinteraction+
|
39
|
-
#
|
40
|
-
def self.method_missing(meth, *args, &block)
|
41
|
-
INTERACTIONS.include?(meth.to_s) ? CSD.ui.send(meth.to_sym, *args, &block) : super
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
data/lib/term/ansicolor.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'term/ansicolor/version'
|
2
|
-
|
3
|
-
module Term
|
4
|
-
# The ANSIColor module can be used for namespacing and mixed into your own
|
5
|
-
# classes.
|
6
|
-
module ANSIColor
|
7
|
-
# :stopdoc:
|
8
|
-
ATTRIBUTES = [
|
9
|
-
[ :clear , 0 ],
|
10
|
-
[ :reset , 0 ], # synonym for :clear
|
11
|
-
[ :bold , 1 ],
|
12
|
-
[ :dark , 2 ],
|
13
|
-
[ :italic , 3 ], # not widely implemented
|
14
|
-
[ :underline , 4 ],
|
15
|
-
[ :underscore , 4 ], # synonym for :underline
|
16
|
-
[ :blink , 5 ],
|
17
|
-
[ :rapid_blink , 6 ], # not widely implemented
|
18
|
-
[ :negative , 7 ], # no reverse because of String#reverse
|
19
|
-
[ :concealed , 8 ],
|
20
|
-
[ :strikethrough, 9 ], # not widely implemented
|
21
|
-
[ :black , 30 ],
|
22
|
-
[ :red , 31 ],
|
23
|
-
[ :green , 32 ],
|
24
|
-
[ :yellow , 33 ],
|
25
|
-
[ :blue , 34 ],
|
26
|
-
[ :magenta , 35 ],
|
27
|
-
[ :cyan , 36 ],
|
28
|
-
[ :white , 37 ],
|
29
|
-
[ :on_black , 40 ],
|
30
|
-
[ :on_red , 41 ],
|
31
|
-
[ :on_green , 42 ],
|
32
|
-
[ :on_yellow , 43 ],
|
33
|
-
[ :on_blue , 44 ],
|
34
|
-
[ :on_magenta , 45 ],
|
35
|
-
[ :on_cyan , 46 ],
|
36
|
-
[ :on_white , 47 ],
|
37
|
-
]
|
38
|
-
|
39
|
-
ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
|
40
|
-
# :startdoc:
|
41
|
-
|
42
|
-
# Returns true, if the coloring function of this module
|
43
|
-
# is switched on, false otherwise.
|
44
|
-
def self.coloring?
|
45
|
-
@coloring
|
46
|
-
end
|
47
|
-
|
48
|
-
# Turns the coloring on or off globally, so you can easily do
|
49
|
-
# this for example:
|
50
|
-
# Term::ANSIColor::coloring = STDOUT.isatty
|
51
|
-
def self.coloring=(val)
|
52
|
-
@coloring = val
|
53
|
-
end
|
54
|
-
self.coloring = true
|
55
|
-
|
56
|
-
ATTRIBUTES.each do |c, v|
|
57
|
-
eval %Q{
|
58
|
-
def #{c}(string = nil)
|
59
|
-
result = ''
|
60
|
-
result << "\e[#{v}m" if Term::ANSIColor.coloring?
|
61
|
-
if block_given?
|
62
|
-
result << yield
|
63
|
-
elsif string
|
64
|
-
result << string
|
65
|
-
elsif respond_to?(:to_str)
|
66
|
-
result << to_str
|
67
|
-
else
|
68
|
-
return result #only switch on
|
69
|
-
end
|
70
|
-
result << "\e[0m" if Term::ANSIColor.coloring?
|
71
|
-
result
|
72
|
-
end
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
# Regular expression that is used to scan for ANSI-sequences while
|
77
|
-
# uncoloring strings.
|
78
|
-
COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/
|
79
|
-
|
80
|
-
# Returns an uncolored version of the string, that is all
|
81
|
-
# ANSI-sequences are stripped from the string.
|
82
|
-
def uncolored(string = nil) # :yields:
|
83
|
-
if block_given?
|
84
|
-
yield.gsub(COLORED_REGEXP, '')
|
85
|
-
elsif string
|
86
|
-
string.gsub(COLORED_REGEXP, '')
|
87
|
-
elsif respond_to?(:to_str)
|
88
|
-
to_str.gsub(COLORED_REGEXP, '')
|
89
|
-
else
|
90
|
-
''
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
module_function
|
95
|
-
|
96
|
-
# Returns an array of all Term::ANSIColor attributes as symbols.
|
97
|
-
def attributes
|
98
|
-
ATTRIBUTE_NAMES
|
99
|
-
end
|
100
|
-
extend self
|
101
|
-
end
|
102
|
-
end
|