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,78 @@
|
|
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
|
@@ -0,0 +1,83 @@
|
|
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
|
@@ -0,0 +1,129 @@
|
|
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
|
data/lib/csd.rb
CHANGED
@@ -1,2 +1,82 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
# Loading all files in CSD
|
2
|
+
require 'csd/error'
|
3
|
+
require 'csd/options'
|
4
|
+
|
5
|
+
# The CSD namespace is given to the entire gem.
|
6
|
+
#
|
7
|
+
module CSD
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# This String holds the name of the executable the user used to bootstrap this gem
|
11
|
+
attr_reader :executable
|
12
|
+
|
13
|
+
# This method "runs" the whole CSD gem, so to speak.
|
14
|
+
#
|
15
|
+
def bootstrap(options={})
|
16
|
+
@executable = options[:executable]
|
17
|
+
Options.parse!
|
18
|
+
respond_to_incomplete_arguments
|
19
|
+
Applications.current.instance.send("#{Options.action}!".to_sym)
|
20
|
+
end
|
21
|
+
|
22
|
+
# This method chooses and holds the user interface instance
|
23
|
+
#
|
24
|
+
def ui
|
25
|
+
@@ui ||= CLI.new
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# This method check the arguments the user has provided and terminates the AI with
|
31
|
+
# some helpful message if the arguments are invalid.
|
32
|
+
#
|
33
|
+
def respond_to_incomplete_arguments
|
34
|
+
choose_application unless Applications.current
|
35
|
+
choose_action unless Options.valid_action?
|
36
|
+
end
|
37
|
+
|
38
|
+
# This methods lists all available applications
|
39
|
+
#
|
40
|
+
def choose_application
|
41
|
+
UI.separator
|
42
|
+
UI.info ' Welcome to the Automated Installer.'.green.bold
|
43
|
+
UI.separator
|
44
|
+
UI.info ' The AI can assist you with the following applications: '
|
45
|
+
OptionParser.new do |opts|
|
46
|
+
opts.banner = ''
|
47
|
+
Applications.all { |app| opts.list_item(app.name, app.description) }
|
48
|
+
UI.info opts.help
|
49
|
+
end
|
50
|
+
UI.separator
|
51
|
+
UI.info ' For more information type: '.green.bold + "#{executable} [APPLICATION NAME]".cyan.bold
|
52
|
+
UI.info ' For example: '.green.bold + "#{executable} minisip".cyan.bold
|
53
|
+
UI.separator
|
54
|
+
UI.warn "You did not specify a valid application name."
|
55
|
+
raise Error::Argument::NoApplication
|
56
|
+
end
|
57
|
+
|
58
|
+
# This methods lists all available actions for a specific application
|
59
|
+
#
|
60
|
+
def choose_action
|
61
|
+
UI.separator
|
62
|
+
UI.info " Automated Installer assistance for #{Applications.current.human}".green.bold
|
63
|
+
UI.separator
|
64
|
+
UI.info " The AI can assist you with the following tasks regarding #{Applications.current.human}: "
|
65
|
+
OptionParser.new do |opts|
|
66
|
+
opts.banner = ''
|
67
|
+
actions = Applications.current.actions[:public]
|
68
|
+
actions << Applications.current.actions[:developer] if Options.developer
|
69
|
+
actions.flatten.each { |action| opts.list_item(action.keys.first, action.values.first) }
|
70
|
+
UI.info opts.help
|
71
|
+
end
|
72
|
+
UI.separator
|
73
|
+
UI.info ' To execute the task: '.green.bold + "#{executable} [TASK] #{Applications.current.name}".cyan.bold
|
74
|
+
UI.info ' For more details: '.green.bold + "#{executable} help [TASK] #{Applications.current.name}".cyan.bold
|
75
|
+
UI.info ' Example: '.green.bold + "#{executable} help install #{Applications.current.name}".cyan.bold
|
76
|
+
UI.separator
|
77
|
+
UI.warn "You did not specify a valid task name."
|
78
|
+
raise Error::Argument::NoAction
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module CSD
|
2
|
+
# This namespace holds all individual application Modules
|
3
|
+
#
|
4
|
+
module Application
|
5
|
+
|
6
|
+
# This is the root class of all Applications
|
7
|
+
#
|
8
|
+
module Default
|
9
|
+
|
10
|
+
def name
|
11
|
+
ActiveSupport::Inflector.underscore self.to_s.demodulize
|
12
|
+
end
|
13
|
+
|
14
|
+
def description
|
15
|
+
about.description
|
16
|
+
end
|
17
|
+
|
18
|
+
def human
|
19
|
+
about.human
|
20
|
+
end
|
21
|
+
|
22
|
+
def actions
|
23
|
+
about.actions
|
24
|
+
end
|
25
|
+
|
26
|
+
def scopes(action)
|
27
|
+
about.scopes[:action]
|
28
|
+
end
|
29
|
+
|
30
|
+
def options(action='')
|
31
|
+
options_dir = File.join(Path.applications, name, 'options')
|
32
|
+
common_file = File.join(options_dir, "common.rb")
|
33
|
+
specific_file = File.join(options_dir, "#{action}.rb")
|
34
|
+
common_options = File.file?(common_file) ? File.read(common_file) : ''
|
35
|
+
specific_options = File.file?(specific_file) ? File.read(specific_file) : ''
|
36
|
+
specific_options + common_options
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def about
|
42
|
+
about_file = File.join(Path.applications, name, 'about.yml')
|
43
|
+
OpenStruct.new YAML.load_file(about_file)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|