match_point 0.0.9 → 0.0.10
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/lib/match_point/version.rb +1 -1
- data/lib/match_point/xml_instance.rb +38 -19
- data/spec/match_point_spec.rb +9 -9
- metadata +1 -1
data/lib/match_point/version.rb
CHANGED
@@ -3,13 +3,28 @@ module MatchPoint
|
|
3
3
|
|
4
4
|
SPEC_NODE="MatchPointSpec"
|
5
5
|
|
6
|
-
def
|
6
|
+
def self.from_xml template, xml
|
7
|
+
instance = self.new template
|
8
|
+
instance.xml= xml
|
9
|
+
instance
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.from_hash template, data
|
13
|
+
instance = self.new template
|
14
|
+
instance.assign_values data
|
15
|
+
instance
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize template
|
7
19
|
@template= Nokogiri::XML(template)
|
8
|
-
@xml = Nokogiri::XML(
|
20
|
+
@xml = Nokogiri::XML(template)
|
9
21
|
@nodes_paths = {}
|
10
22
|
|
11
23
|
synchronize_object_to_xml
|
12
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
def xml= an_xml
|
27
|
+
@xml = Nokogiri::XML(an_xml)
|
13
28
|
end
|
14
29
|
|
15
30
|
def to_xml
|
@@ -36,48 +51,52 @@ module MatchPoint
|
|
36
51
|
@xml.at_xpath a_path
|
37
52
|
end
|
38
53
|
|
39
|
-
protected
|
40
|
-
|
41
54
|
def assign_values data
|
42
55
|
data.each do |key, value|
|
43
|
-
|
56
|
+
assign_value value, node_path(key)
|
44
57
|
end
|
45
58
|
end
|
46
59
|
|
60
|
+
protected
|
61
|
+
|
47
62
|
def node_path node_name
|
48
63
|
@nodes_paths[node_name]
|
49
64
|
end
|
50
65
|
|
51
|
-
def
|
66
|
+
def assign_value value, path
|
52
67
|
@xml.xpath(remove_spec_node_from(path)).first.content = value
|
53
68
|
end
|
54
69
|
|
55
70
|
def synchronize_object_to_xml
|
56
71
|
nodes_in_template = @template.xpath("//#{SPEC_NODE}")
|
57
|
-
nodes_in_template.each do |
|
72
|
+
nodes_in_template.each do |node_in_template|
|
58
73
|
define_accessors_for node_in_template
|
59
|
-
@nodes_paths = @nodes_paths.merge ({
|
74
|
+
@nodes_paths = @nodes_paths.merge ({node_in_template.text.to_sym => node_in_template.path})
|
60
75
|
end
|
61
76
|
end
|
62
|
-
|
77
|
+
|
63
78
|
def define_accessors_for node_in_template
|
64
|
-
|
65
|
-
|
66
|
-
|
79
|
+
attr_path = remove_spec_node_from(node_in_template.path)
|
80
|
+
attr_value = @xml.xpath(attr_path).text
|
81
|
+
|
82
|
+
add_attr_reader_for node_in_template, attr_path
|
83
|
+
add_attr_writer_for node_in_template
|
67
84
|
end
|
68
85
|
|
69
86
|
def remove_spec_node_from a_path
|
70
87
|
a_path.gsub("/#{SPEC_NODE}", "")
|
71
88
|
end
|
72
89
|
|
73
|
-
def
|
74
|
-
|
90
|
+
def add_attr_reader_for node_in_template, attr_path
|
91
|
+
define_singleton_method node_in_template.text.to_sym, lambda {
|
92
|
+
@xml.at_xpath(attr_path).text
|
93
|
+
}
|
75
94
|
end
|
76
95
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
96
|
+
def add_attr_writer_for node_in_template
|
97
|
+
define_singleton_method (node_in_template.text).concat('=').to_sym, Proc.new { |new_value|
|
98
|
+
assign_value new_value, node_in_template.path
|
99
|
+
add_attr_reader_for node_in_template, remove_spec_node_from(node_path(node_in_template.text.to_sym))
|
81
100
|
}
|
82
101
|
end
|
83
102
|
end
|
data/spec/match_point_spec.rb
CHANGED
@@ -6,13 +6,13 @@ describe MatchPoint do
|
|
6
6
|
|
7
7
|
let(:template) do
|
8
8
|
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
<TIX version=\"TIX 4.11.0\">
|
10
|
+
<AccessControl method=\"AccessControlAuthenticate\">
|
11
|
+
<AuthRequest>
|
12
|
+
<AuthID><MatchPointSpec>auth_id</MatchPointSpec></AuthID>
|
13
|
+
</AuthRequest>
|
14
|
+
</AccessControl>
|
15
|
+
</TIX>"
|
16
16
|
end
|
17
17
|
|
18
18
|
let(:response_xml) do
|
@@ -26,8 +26,8 @@ describe MatchPoint do
|
|
26
26
|
</TIX>"
|
27
27
|
end
|
28
28
|
|
29
|
-
let(:response) { MatchPoint::XmlInstance.
|
30
|
-
let(:request) { MatchPoint::XmlInstance.
|
29
|
+
let(:response) { MatchPoint::XmlInstance.from_xml(template, response_xml) }
|
30
|
+
let(:request) { MatchPoint::XmlInstance.from_hash(template, {:auth_id=>"NeWVaLue"})}
|
31
31
|
|
32
32
|
it "should get the auth_id from the xml if the template for that field is defined" do
|
33
33
|
response.auth_id.should == "1ua5J1gJz3TryPEMQZkeWFarOagSJvYY"
|