facter 1.7.6 → 2.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of facter might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/COMMITTERS.md +194 -0
- data/CONTRIBUTING.md +63 -235
- data/Gemfile +12 -8
- data/README.md +1 -2
- data/Rakefile +1 -1
- data/bin/facter +0 -4
- data/ext/build_defaults.yaml +2 -2
- data/ext/project_data.yaml +18 -0
- data/install.rb +1 -16
- data/lib/facter.rb +171 -171
- data/lib/facter/application.rb +65 -54
- data/lib/facter/core/aggregate.rb +220 -0
- data/lib/facter/core/directed_graph.rb +46 -0
- data/lib/facter/core/execution.rb +100 -0
- data/lib/facter/core/execution/base.rb +73 -0
- data/lib/facter/core/execution/posix.rb +50 -0
- data/lib/facter/core/execution/windows.rb +57 -0
- data/lib/facter/core/logging.rb +169 -0
- data/lib/facter/core/resolvable.rb +94 -0
- data/lib/facter/core/suitable.rb +117 -0
- data/lib/facter/domain.rb +15 -9
- data/lib/facter/filesystems.rb +1 -1
- data/lib/facter/hardwaremodel.rb +1 -1
- data/lib/facter/hostname.rb +3 -3
- data/lib/facter/interfaces.rb +6 -1
- data/lib/facter/ipaddress.rb +2 -2
- data/lib/facter/kernel.rb +1 -1
- data/lib/facter/kernelrelease.rb +1 -1
- data/lib/facter/ldom.rb +1 -1
- data/lib/facter/lsbdistcodename.rb +1 -1
- data/lib/facter/lsbdistdescription.rb +1 -1
- data/lib/facter/lsbdistid.rb +1 -1
- data/lib/facter/lsbdistrelease.rb +1 -1
- data/lib/facter/lsbrelease.rb +1 -1
- data/lib/facter/macaddress.rb +1 -14
- data/lib/facter/macosx.rb +2 -2
- data/lib/facter/memory.rb +8 -19
- data/lib/facter/operatingsystem.rb +1 -1
- data/lib/facter/operatingsystemrelease.rb +34 -1
- data/lib/facter/physicalprocessorcount.rb +6 -6
- data/lib/facter/processor.rb +11 -10
- data/lib/facter/selinux.rb +4 -15
- data/lib/facter/ssh.rb +5 -2
- data/lib/facter/util/architecture.rb +2 -2
- data/lib/facter/util/collection.rb +42 -38
- data/lib/facter/util/config.rb +19 -9
- data/lib/facter/util/confine.rb +34 -4
- data/lib/facter/util/ec2.rb +1 -1
- data/lib/facter/util/fact.rb +108 -36
- data/lib/facter/util/file_read.rb +7 -6
- data/lib/facter/util/formatter.rb +38 -0
- data/lib/facter/util/ip.rb +3 -3
- data/lib/facter/util/loader.rb +62 -42
- data/lib/facter/util/macosx.rb +7 -8
- data/lib/facter/util/manufacturer.rb +3 -3
- data/lib/facter/util/memory.rb +13 -13
- data/lib/facter/util/monkey_patches.rb +0 -31
- data/lib/facter/util/netmask.rb +3 -3
- data/lib/facter/util/normalization.rb +94 -0
- data/lib/facter/util/nothing_loader.rb +3 -6
- data/lib/facter/util/parser.rb +3 -5
- data/lib/facter/util/plist/generator.rb +1 -1
- data/lib/facter/util/processor.rb +15 -15
- data/lib/facter/util/resolution.rb +112 -289
- data/lib/facter/util/solaris_zones.rb +4 -4
- data/lib/facter/util/uptime.rb +8 -3
- data/lib/facter/util/values.rb +67 -1
- data/lib/facter/util/virtual.rb +10 -10
- data/lib/facter/util/xendomains.rb +1 -1
- data/lib/facter/version.rb +42 -39
- data/lib/facter/virtual.rb +6 -7
- data/lib/facter/zfs_version.rb +3 -3
- data/lib/facter/zpool_version.rb +3 -3
- data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
- data/spec/unit/application_spec.rb +46 -1
- data/spec/unit/core/aggregate_spec.rb +125 -0
- data/spec/unit/core/directed_graph_spec.rb +79 -0
- data/spec/unit/core/execution/base_spec.rb +119 -0
- data/spec/unit/core/execution/posix_spec.rb +86 -0
- data/spec/unit/core/execution/windows_spec.rb +106 -0
- data/spec/unit/core/execution_spec.rb +37 -0
- data/spec/unit/core/logging_spec.rb +104 -0
- data/spec/unit/core/resolvable_spec.rb +81 -0
- data/spec/unit/core/suitable_spec.rb +96 -0
- data/spec/unit/domain_spec.rb +5 -5
- data/spec/unit/facter_spec.rb +61 -222
- data/spec/unit/filesystems_spec.rb +2 -2
- data/spec/unit/hardwareisa_spec.rb +5 -5
- data/spec/unit/hardwaremodel_spec.rb +1 -1
- data/spec/unit/hostname_spec.rb +4 -4
- data/spec/unit/id_spec.rb +3 -3
- data/spec/unit/interfaces_spec.rb +10 -0
- data/spec/unit/ipaddress6_spec.rb +4 -4
- data/spec/unit/ipaddress_spec.rb +1 -1
- data/spec/unit/kernel_spec.rb +2 -2
- data/spec/unit/kernelmajversion_spec.rb +1 -1
- data/spec/unit/kernelrelease_spec.rb +4 -4
- data/spec/unit/kernelversion_spec.rb +2 -2
- data/spec/unit/ldom_spec.rb +2 -2
- data/spec/unit/lsbdistcodename_spec.rb +2 -2
- data/spec/unit/lsbdistdescription_spec.rb +2 -2
- data/spec/unit/lsbdistid_spec.rb +2 -2
- data/spec/unit/lsbdistrelease_spec.rb +2 -2
- data/spec/unit/lsbrelease_spec.rb +2 -2
- data/spec/unit/manufacturer_spec.rb +1 -1
- data/spec/unit/memory_spec.rb +24 -31
- data/spec/unit/netmask_spec.rb +9 -0
- data/spec/unit/operatingsystem_spec.rb +1 -1
- data/spec/unit/operatingsystemrelease_spec.rb +62 -4
- data/spec/unit/physicalprocessorcount_spec.rb +10 -10
- data/spec/unit/processor_spec.rb +11 -11
- data/spec/unit/selinux_spec.rb +2 -8
- data/spec/unit/ssh_spec.rb +3 -2
- data/spec/unit/uniqueid_spec.rb +3 -3
- data/spec/unit/util/collection_spec.rb +37 -35
- data/spec/unit/util/config_spec.rb +20 -0
- data/spec/unit/util/confine_spec.rb +21 -0
- data/spec/unit/util/directory_loader_spec.rb +1 -0
- data/spec/unit/util/ec2_spec.rb +6 -6
- data/spec/unit/util/fact_spec.rb +92 -90
- data/spec/unit/util/ip_spec.rb +2 -2
- data/spec/unit/util/loader_spec.rb +127 -186
- data/spec/unit/util/macaddress_spec.rb +2 -2
- data/spec/unit/util/macosx_spec.rb +8 -8
- data/spec/unit/util/manufacturer_spec.rb +3 -3
- data/spec/unit/util/normalization_spec.rb +113 -0
- data/spec/unit/util/parser_spec.rb +25 -3
- data/spec/unit/util/processor_spec.rb +2 -2
- data/spec/unit/util/resolution_spec.rb +60 -631
- data/spec/unit/util/solaris_zones_spec.rb +5 -5
- data/spec/unit/util/uptime_spec.rb +1 -1
- data/spec/unit/util/values_spec.rb +131 -0
- data/spec/unit/util/virtual_spec.rb +16 -16
- data/spec/unit/util/xendomains_spec.rb +2 -2
- data/spec/unit/virtual_spec.rb +39 -39
- data/spec/unit/zfs_version_spec.rb +11 -11
- data/spec/unit/zonename_spec.rb +2 -2
- data/spec/unit/zones_spec.rb +1 -1
- data/spec/unit/zpool_version_spec.rb +11 -11
- metadata +466 -447
- data/lib/facter/util/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/LICENSE +0 -19
- data/lib/facter/util/cfpropertylist/README +0 -44
- data/lib/facter/util/cfpropertylist/Rakefile +0 -44
- data/lib/facter/util/cfpropertylist/THANKS +0 -7
- data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
- data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
- data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
- data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
- data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
- data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
- data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
- data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -1,135 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'libxml'
|
4
|
-
|
5
|
-
module Facter::Util::CFPropertyList
|
6
|
-
# XML parser
|
7
|
-
class XML < XMLParserInterface
|
8
|
-
# read a XML file
|
9
|
-
# opts::
|
10
|
-
# * :file - The filename of the file to load
|
11
|
-
# * :data - The data to parse
|
12
|
-
def load(opts)
|
13
|
-
if(opts.has_key?(:file)) then
|
14
|
-
doc = LibXML::XML::Document.file(opts[:file],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
|
15
|
-
else
|
16
|
-
doc = LibXML::XML::Document.string(opts[:data],:options => LibXML::XML::Parser::Options::NOBLANKS|LibXML::XML::Parser::Options::NOENT)
|
17
|
-
end
|
18
|
-
|
19
|
-
root = doc.root.first
|
20
|
-
return import_xml(root)
|
21
|
-
end
|
22
|
-
|
23
|
-
# serialize Facter::Util::CFPropertyList object to XML
|
24
|
-
# opts = {}:: Specify options: :formatted - Use indention and line breaks
|
25
|
-
def to_str(opts={})
|
26
|
-
doc = LibXML::XML::Document.new
|
27
|
-
|
28
|
-
doc.root = LibXML::XML::Node.new('plist')
|
29
|
-
doc.encoding = LibXML::XML::Encoding::UTF_8
|
30
|
-
|
31
|
-
doc.root['version'] = '1.0'
|
32
|
-
doc.root << opts[:root].to_xml(self)
|
33
|
-
|
34
|
-
# ugly hack, but there's no other possibility I know
|
35
|
-
str = doc.to_s(:indent => opts[:formatted])
|
36
|
-
str1 = String.new
|
37
|
-
first = false
|
38
|
-
str.each_line do |line|
|
39
|
-
str1 << line
|
40
|
-
unless(first) then
|
41
|
-
str1 << "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" if line =~ /^\s*<\?xml/
|
42
|
-
end
|
43
|
-
|
44
|
-
first = true
|
45
|
-
end
|
46
|
-
|
47
|
-
str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
|
48
|
-
return str1
|
49
|
-
end
|
50
|
-
|
51
|
-
def new_node(name)
|
52
|
-
LibXML::XML::Node.new(name)
|
53
|
-
end
|
54
|
-
|
55
|
-
def new_text(val)
|
56
|
-
LibXML::XML::Node.new_text(val)
|
57
|
-
end
|
58
|
-
|
59
|
-
def append_node(parent, child)
|
60
|
-
parent << child
|
61
|
-
end
|
62
|
-
|
63
|
-
protected
|
64
|
-
|
65
|
-
# get the value of a DOM node
|
66
|
-
def get_value(n)
|
67
|
-
content = if n.children?
|
68
|
-
n.first.content
|
69
|
-
else
|
70
|
-
n.content
|
71
|
-
end
|
72
|
-
|
73
|
-
content.force_encoding('UTF-8') if content.respond_to?(:force_encoding)
|
74
|
-
content
|
75
|
-
end
|
76
|
-
|
77
|
-
# import the XML values
|
78
|
-
def import_xml(node)
|
79
|
-
ret = nil
|
80
|
-
|
81
|
-
case node.name
|
82
|
-
when 'dict'
|
83
|
-
hsh = Hash.new
|
84
|
-
key = nil
|
85
|
-
|
86
|
-
if node.children? then
|
87
|
-
node.children.each do |n|
|
88
|
-
next if n.text? # avoid a bug of libxml
|
89
|
-
next if n.comment?
|
90
|
-
|
91
|
-
if n.name == "key" then
|
92
|
-
key = get_value(n)
|
93
|
-
else
|
94
|
-
raise CFFormatError.new("Format error!") if key.nil?
|
95
|
-
hsh[key] = import_xml(n)
|
96
|
-
key = nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
ret = CFDictionary.new(hsh)
|
102
|
-
|
103
|
-
when 'array'
|
104
|
-
ary = Array.new
|
105
|
-
|
106
|
-
if node.children? then
|
107
|
-
node.children.each do |n|
|
108
|
-
ary.push import_xml(n)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
ret = CFArray.new(ary)
|
113
|
-
|
114
|
-
when 'true'
|
115
|
-
ret = CFBoolean.new(true)
|
116
|
-
when 'false'
|
117
|
-
ret = CFBoolean.new(false)
|
118
|
-
when 'real'
|
119
|
-
ret = CFReal.new(get_value(node).to_f)
|
120
|
-
when 'integer'
|
121
|
-
ret = CFInteger.new(get_value(node).to_i)
|
122
|
-
when 'string'
|
123
|
-
ret = CFString.new(get_value(node))
|
124
|
-
when 'data'
|
125
|
-
ret = CFData.new(get_value(node))
|
126
|
-
when 'date'
|
127
|
-
ret = CFDate.new(CFDate.parse_date(get_value(node)))
|
128
|
-
end
|
129
|
-
|
130
|
-
return ret
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# eof
|
@@ -1,140 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'nokogiri'
|
4
|
-
|
5
|
-
module Facter::Util::CFPropertyList
|
6
|
-
# XML parser
|
7
|
-
class XML < ParserInterface
|
8
|
-
# read a XML file
|
9
|
-
# opts::
|
10
|
-
# * :file - The filename of the file to load
|
11
|
-
# * :data - The data to parse
|
12
|
-
def load(opts)
|
13
|
-
if(opts.has_key?(:file)) then
|
14
|
-
File.open(opts[:file], "rb") { |fd| doc = Nokogiri::XML::Document.parse(fd, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT) }
|
15
|
-
else
|
16
|
-
doc = Nokogiri::XML::Document.parse(opts[:data], nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS|Nokogiri::XML::ParseOptions::NOENT)
|
17
|
-
end
|
18
|
-
|
19
|
-
root = doc.root.children.first
|
20
|
-
return import_xml(root)
|
21
|
-
end
|
22
|
-
|
23
|
-
# serialize Facter::Util::CFPropertyList object to XML
|
24
|
-
# opts = {}:: Specify options: :formatted - Use indention and line breaks
|
25
|
-
def to_str(opts={})
|
26
|
-
doc = Nokogiri::XML::Document.new
|
27
|
-
@doc = doc
|
28
|
-
|
29
|
-
doc.root = doc.create_element 'plist', :version => '1.0'
|
30
|
-
doc.encoding = 'UTF-8'
|
31
|
-
|
32
|
-
doc.root << opts[:root].to_xml(self)
|
33
|
-
|
34
|
-
# ugly hack, but there's no other possibility I know
|
35
|
-
s_opts = Nokogiri::XML::Node::SaveOptions::AS_XML
|
36
|
-
s_opts |= Nokogiri::XML::Node::SaveOptions::FORMAT if opts[:formatted]
|
37
|
-
|
38
|
-
str = doc.serialize(:save_with => s_opts)
|
39
|
-
str1 = String.new
|
40
|
-
first = false
|
41
|
-
str.each_line do |line|
|
42
|
-
str1 << line
|
43
|
-
unless(first) then
|
44
|
-
str1 << "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" if line =~ /^\s*<\?xml/
|
45
|
-
end
|
46
|
-
|
47
|
-
first = true
|
48
|
-
end
|
49
|
-
|
50
|
-
str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
|
51
|
-
return str1
|
52
|
-
end
|
53
|
-
|
54
|
-
def new_node(name)
|
55
|
-
@doc.create_element name
|
56
|
-
end
|
57
|
-
|
58
|
-
def new_text(val)
|
59
|
-
@doc.create_text_node val
|
60
|
-
end
|
61
|
-
|
62
|
-
def append_node(parent, child)
|
63
|
-
parent << child
|
64
|
-
end
|
65
|
-
|
66
|
-
protected
|
67
|
-
|
68
|
-
# get the value of a DOM node
|
69
|
-
def get_value(n)
|
70
|
-
content = if n.children.empty?
|
71
|
-
n.content
|
72
|
-
else
|
73
|
-
n.children.first.content
|
74
|
-
end
|
75
|
-
|
76
|
-
content.force_encoding('UTF-8') if content.respond_to?(:force_encoding)
|
77
|
-
content
|
78
|
-
end
|
79
|
-
|
80
|
-
# import the XML values
|
81
|
-
def import_xml(node)
|
82
|
-
ret = nil
|
83
|
-
|
84
|
-
case node.name
|
85
|
-
when 'dict'
|
86
|
-
hsh = Hash.new
|
87
|
-
key = nil
|
88
|
-
children = node.children
|
89
|
-
|
90
|
-
unless children.empty? then
|
91
|
-
children.each do |n|
|
92
|
-
next if n.text? # avoid a bug of libxml
|
93
|
-
next if n.comment?
|
94
|
-
|
95
|
-
if n.name == "key" then
|
96
|
-
key = get_value(n)
|
97
|
-
else
|
98
|
-
raise CFFormatError.new("Format error!") if key.nil?
|
99
|
-
hsh[key] = import_xml(n)
|
100
|
-
key = nil
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
ret = CFDictionary.new(hsh)
|
106
|
-
|
107
|
-
when 'array'
|
108
|
-
ary = Array.new
|
109
|
-
children = node.children
|
110
|
-
|
111
|
-
unless children.empty? then
|
112
|
-
children.each do |n|
|
113
|
-
ary.push import_xml(n)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
ret = CFArray.new(ary)
|
118
|
-
|
119
|
-
when 'true'
|
120
|
-
ret = CFBoolean.new(true)
|
121
|
-
when 'false'
|
122
|
-
ret = CFBoolean.new(false)
|
123
|
-
when 'real'
|
124
|
-
ret = CFReal.new(get_value(node).to_f)
|
125
|
-
when 'integer'
|
126
|
-
ret = CFInteger.new(get_value(node).to_i)
|
127
|
-
when 'string'
|
128
|
-
ret = CFString.new(get_value(node))
|
129
|
-
when 'data'
|
130
|
-
ret = CFData.new(get_value(node))
|
131
|
-
when 'date'
|
132
|
-
ret = CFDate.new(CFDate.parse_date(get_value(node)))
|
133
|
-
end
|
134
|
-
|
135
|
-
return ret
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# eof
|
@@ -1,136 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'rexml/document'
|
4
|
-
|
5
|
-
module Facter::Util::CFPropertyList
|
6
|
-
# XML parser
|
7
|
-
class XML < ParserInterface
|
8
|
-
# read a XML file
|
9
|
-
# opts::
|
10
|
-
# * :file - The filename of the file to load
|
11
|
-
# * :data - The data to parse
|
12
|
-
def load(opts)
|
13
|
-
if(opts.has_key?(:file)) then
|
14
|
-
File.open(opts[:file], "rb") { |fd| doc = REXML::Document.new(fd) }
|
15
|
-
else
|
16
|
-
doc = REXML::Document.new(opts[:data])
|
17
|
-
end
|
18
|
-
|
19
|
-
root = doc.root.elements[1]
|
20
|
-
return import_xml(root)
|
21
|
-
end
|
22
|
-
|
23
|
-
# serialize Facter::Util::CFPropertyList object to XML
|
24
|
-
# opts = {}:: Specify options: :formatted - Use indention and line breaks
|
25
|
-
def to_str(opts={})
|
26
|
-
doc = REXML::Document.new
|
27
|
-
@doc = doc
|
28
|
-
|
29
|
-
doc.context[:attribute_quote] = :quote
|
30
|
-
|
31
|
-
doc.add_element 'plist', {'version' => '1.0'}
|
32
|
-
doc.root << opts[:root].to_xml(self)
|
33
|
-
|
34
|
-
formatter = if opts[:formatted] then
|
35
|
-
f = REXML::Formatters::Pretty.new(2)
|
36
|
-
f.compact = true
|
37
|
-
f
|
38
|
-
else
|
39
|
-
REXML::Formatters::Default.new
|
40
|
-
end
|
41
|
-
|
42
|
-
str = formatter.write(doc.root, "")
|
43
|
-
str1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + str + "\n"
|
44
|
-
str1.force_encoding('UTF-8') if str1.respond_to?(:force_encoding)
|
45
|
-
|
46
|
-
return str1
|
47
|
-
end
|
48
|
-
|
49
|
-
def new_node(name)
|
50
|
-
#LibXML::XML::Node.new(name)
|
51
|
-
REXML::Element.new(name)
|
52
|
-
end
|
53
|
-
|
54
|
-
def new_text(val)
|
55
|
-
val
|
56
|
-
end
|
57
|
-
|
58
|
-
def append_node(parent, child)
|
59
|
-
if child.is_a?(String) then
|
60
|
-
parent.add_text child
|
61
|
-
else
|
62
|
-
parent.elements << child
|
63
|
-
end
|
64
|
-
parent
|
65
|
-
end
|
66
|
-
|
67
|
-
protected
|
68
|
-
|
69
|
-
# get the value of a DOM node
|
70
|
-
def get_value(n)
|
71
|
-
content = n.text
|
72
|
-
|
73
|
-
content.force_encoding('UTF-8') if content.respond_to?(:force_encoding)
|
74
|
-
content
|
75
|
-
end
|
76
|
-
|
77
|
-
# import the XML values
|
78
|
-
def import_xml(node)
|
79
|
-
ret = nil
|
80
|
-
|
81
|
-
case node.name
|
82
|
-
when 'dict'
|
83
|
-
hsh = Hash.new
|
84
|
-
key = nil
|
85
|
-
|
86
|
-
if node.has_elements? then
|
87
|
-
node.elements.each do |n|
|
88
|
-
#print n.name + "\n"
|
89
|
-
next if n.name == '#text' # avoid a bug of libxml
|
90
|
-
next if n.name == '#comment'
|
91
|
-
|
92
|
-
if n.name == "key" then
|
93
|
-
key = get_value(n)
|
94
|
-
else
|
95
|
-
raise CFFormatError.new("Format error!") if key.nil?
|
96
|
-
hsh[key] = import_xml(n)
|
97
|
-
key = nil
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
ret = CFDictionary.new(hsh)
|
103
|
-
|
104
|
-
when 'array'
|
105
|
-
ary = Array.new
|
106
|
-
|
107
|
-
if node.has_elements? then
|
108
|
-
node.elements.each do |n|
|
109
|
-
ary.push import_xml(n)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
ret = CFArray.new(ary)
|
114
|
-
|
115
|
-
when 'true'
|
116
|
-
ret = CFBoolean.new(true)
|
117
|
-
when 'false'
|
118
|
-
ret = CFBoolean.new(false)
|
119
|
-
when 'real'
|
120
|
-
ret = CFReal.new(get_value(node).to_f)
|
121
|
-
when 'integer'
|
122
|
-
ret = CFInteger.new(get_value(node).to_i)
|
123
|
-
when 'string'
|
124
|
-
ret = CFString.new(get_value(node))
|
125
|
-
when 'data'
|
126
|
-
ret = CFData.new(get_value(node))
|
127
|
-
when 'date'
|
128
|
-
ret = CFDate.new(CFDate.parse_date(get_value(node)))
|
129
|
-
end
|
130
|
-
|
131
|
-
return ret
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# eof
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
describe 'Monkey Patches' do
|
5
|
-
let(:subject) { "a b c d e f\ng h i j" }
|
6
|
-
|
7
|
-
context 'String' do
|
8
|
-
it "should respond to lines" do
|
9
|
-
subject.lines.to_a.should == ["a b c d e f\n", "g h i j"]
|
10
|
-
end
|
11
|
-
it "should accept a block" do
|
12
|
-
our_lines = []
|
13
|
-
subject.lines do |line| our_lines << line end
|
14
|
-
our_lines.should == ["a b c d e f\n", "g h i j"]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'IO' do
|
19
|
-
it "should respond to lines" do
|
20
|
-
our_lines = nil
|
21
|
-
Tempfile.open("lines") do | file |
|
22
|
-
file.write(subject)
|
23
|
-
file.flush
|
24
|
-
file.rewind
|
25
|
-
our_lines = file.lines.to_a
|
26
|
-
end
|
27
|
-
our_lines.should == ["a b c d e f\n", "g h i j"]
|
28
|
-
end
|
29
|
-
it "should accept a block" do
|
30
|
-
our_lines = []
|
31
|
-
file = Tempfile.new("lines")
|
32
|
-
file.write(subject)
|
33
|
-
file.flush
|
34
|
-
file.rewind
|
35
|
-
file.lines.each do |line| our_lines << line end
|
36
|
-
file.unlink
|
37
|
-
our_lines.should == ["a b c d e f\n", "g h i j"]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|