proteus 0.9.0

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.
Files changed (43) hide show
  1. data/COPYING +674 -0
  2. data/README +88 -0
  3. data/Rakefile +33 -0
  4. data/bin/pro +189 -0
  5. data/lib/ClassParser.rb +84 -0
  6. data/lib/ComponentClass.rb +51 -0
  7. data/lib/ComponentInstance.rb +76 -0
  8. data/lib/DefinitionHelper.rb +157 -0
  9. data/lib/DefinitionParser.rb +107 -0
  10. data/lib/Facade.rb +116 -0
  11. data/lib/FileHelper.rb +80 -0
  12. data/lib/InputParser.rb +241 -0
  13. data/lib/InstanceParser.rb +65 -0
  14. data/lib/InstanceProxy.rb +100 -0
  15. data/lib/PropertyHash.rb +64 -0
  16. data/lib/TemplateRenderer.rb +128 -0
  17. data/lib/exceptions.rb +50 -0
  18. data/test/spec/ClassParser_spec.rb +314 -0
  19. data/test/spec/ComponentClass_spec.rb +44 -0
  20. data/test/spec/ComponentInstance_spec.rb +50 -0
  21. data/test/spec/DefinitionHelper_spec.rb +134 -0
  22. data/test/spec/DefinitionParser_spec.rb +236 -0
  23. data/test/spec/Facade_spec.rb +44 -0
  24. data/test/spec/FileHelper_spec.rb +113 -0
  25. data/test/spec/InputParser_spec.rb +424 -0
  26. data/test/spec/InstanceParser_spec.rb +125 -0
  27. data/test/spec/TemplateRenderer_spec.rb +54 -0
  28. data/test/spec/lib/NS1/TestComponent10.def +4 -0
  29. data/test/spec/lib/NS1/TestComponent11.def +4 -0
  30. data/test/spec/lib/NS1/TestComponent4.def +4 -0
  31. data/test/spec/lib/NS1/TestComponent5.def +4 -0
  32. data/test/spec/lib/NS1/TestComponent8.def +4 -0
  33. data/test/spec/lib/NS1/TestComponent9.def +4 -0
  34. data/test/spec/lib/NS2/TestComponent6.def +4 -0
  35. data/test/spec/lib/TestComponent1.def +4 -0
  36. data/test/spec/lib/TestComponent3.def +4 -0
  37. data/test/spec/test_lib_dir1/File1.def +0 -0
  38. data/test/spec/test_lib_dir1/File3.def +0 -0
  39. data/test/spec/test_lib_dir1/NS1/File4.def +0 -0
  40. data/test/spec/test_lib_dir1/NS1/NS2/File5.def +0 -0
  41. data/test/spec/test_lib_dir2/File1.def +0 -0
  42. data/test/spec/test_lib_dir2/File2.def +0 -0
  43. metadata +113 -0
@@ -0,0 +1,44 @@
1
+ ################################################################################
2
+ # (C) Copyright 2009 William Madden
3
+ #
4
+ # This file is part of Proteus.
5
+ #
6
+ # Proteus is free software: you can redistribute it and/or modify it under the
7
+ # terms of the GNU General Public License as published by the Free Software
8
+ # Foundation, either version 3 of the License, or (at your option) any later
9
+ # version.
10
+ #
11
+ # Proteus is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # Proteus. If not, see <http://www.gnu.org/licenses/>.
17
+ ################################################################################
18
+
19
+ require File.expand_path( 'lib/ComponentClass.rb' )
20
+
21
+ include Proteus
22
+
23
+
24
+ describe ComponentClass do
25
+
26
+ #-----------------------------------------------------------------------------
27
+ #
28
+ # Input Constants
29
+ #
30
+ #-----------------------------------------------------------------------------
31
+
32
+ #-----------------------------------------------------------------------------
33
+ #
34
+ # Set up, tear down
35
+ #
36
+ #-----------------------------------------------------------------------------
37
+
38
+ #-----------------------------------------------------------------------------
39
+ #
40
+ # Tests
41
+ #
42
+ #-----------------------------------------------------------------------------
43
+
44
+ end
@@ -0,0 +1,50 @@
1
+ ################################################################################
2
+ # (C) Copyright 2009 William Madden
3
+ #
4
+ # This file is part of Proteus.
5
+ #
6
+ # Proteus is free software: you can redistribute it and/or modify it under the
7
+ # terms of the GNU General Public License as published by the Free Software
8
+ # Foundation, either version 3 of the License, or (at your option) any later
9
+ # version.
10
+ #
11
+ # Proteus is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # Proteus. If not, see <http://www.gnu.org/licenses/>.
17
+ ################################################################################
18
+
19
+ require File.expand_path( 'lib/ComponentInstance.rb' )
20
+
21
+ include Proteus
22
+
23
+
24
+ describe ComponentInstance do
25
+
26
+ #-----------------------------------------------------------------------------
27
+ #
28
+ # Input Constants
29
+ #
30
+ #-----------------------------------------------------------------------------
31
+
32
+ #-----------------------------------------------------------------------------
33
+ #
34
+ # Set up, tear down
35
+ #
36
+ #-----------------------------------------------------------------------------
37
+
38
+ #-----------------------------------------------------------------------------
39
+ #
40
+ # Tests
41
+ #
42
+ #-----------------------------------------------------------------------------
43
+
44
+ it "should override its class's default properties"
45
+
46
+
47
+ it "should drop its class's children in favour of its own, if present"
48
+
49
+
50
+ end
@@ -0,0 +1,134 @@
1
+ ################################################################################
2
+ # (C) Copyright 2009 William Madden
3
+ #
4
+ # This file is part of Proteus.
5
+ #
6
+ # Proteus is free software: you can redistribute it and/or modify it under the
7
+ # terms of the GNU General Public License as published by the Free Software
8
+ # Foundation, either version 3 of the License, or (at your option) any later
9
+ # version.
10
+ #
11
+ # Proteus is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # Proteus. If not, see <http://www.gnu.org/licenses/>.
17
+ ################################################################################
18
+
19
+ require File.expand_path( 'lib/DefinitionHelper.rb' )
20
+ require File.expand_path( 'lib/exceptions.rb' )
21
+
22
+ include Proteus
23
+
24
+
25
+ describe DefinitionHelper do
26
+
27
+ #-----------------------------------------------------------------------------
28
+ #
29
+ # Input Constants
30
+ #
31
+ #-----------------------------------------------------------------------------
32
+
33
+ #-----------------------------------------------------------------------------
34
+ #
35
+ # Set up, tear down
36
+ #
37
+ #-----------------------------------------------------------------------------
38
+
39
+ #------------------------------
40
+ # before(:all)
41
+ #------------------------------
42
+
43
+ before(:all) do
44
+
45
+ # Instance parser
46
+ @instance_parser = InstanceParser.new
47
+
48
+ # Class parser
49
+ @class_parser = ClassParser.new
50
+
51
+ # Definition parser
52
+ @definition_parser = DefinitionParser.new
53
+ @definition_parser.class_parser = @class_parser
54
+
55
+ # Definition helper
56
+ @definition_helper = DefinitionHelper.new
57
+ @definition_helper.definition_parser = @definition_parser
58
+ @definition_helper.path = "test/spec/lib"
59
+
60
+ @definition_parser.definition_helper = @definition_helper
61
+
62
+ # Input parser
63
+ @input_parser = InputParser.new
64
+ @input_parser.instance_parser = @instance_parser
65
+ @input_parser.definition_helper = @definition_helper
66
+
67
+ @definition_parser.input_parser = @input_parser
68
+
69
+ end
70
+
71
+ #-----------------------------------------------------------------------------
72
+ #
73
+ # Tests
74
+ #
75
+ #-----------------------------------------------------------------------------
76
+
77
+ it "should use the current namespace if no namespace is given" do
78
+ result = @definition_helper.get_class( ["TestComponent4"], ["NS1"] )
79
+ result.name.should == "TestComponent4"
80
+ end
81
+
82
+
83
+ it "should use the given namespace if present" do
84
+ result = @definition_helper.get_class( ["NS2", "TestComponent6"], ["NS1"] )
85
+ result.name.should == "TestComponent6"
86
+ end
87
+
88
+
89
+ it "should return classes that have already been loaded" do
90
+ result = @definition_helper.get_class( ["TestComponent4"], ["NS1"] )
91
+ result.name.should == "TestComponent4"
92
+
93
+ result2 = @definition_helper.get_class( ["TestComponent4"], ["NS1"] )
94
+ result2.should == result
95
+ end
96
+
97
+
98
+ it "should fail if it can't find the class definition" do
99
+ begin
100
+ result = @definition_helper.get_class( ["TestComponent7"], ["NS1"] )
101
+ rescue Exceptions::DefinitionUnavailable
102
+ success = true
103
+ end
104
+
105
+ success.should == true
106
+ end
107
+
108
+
109
+ it "should be able to handle recursive classes" do
110
+ result = @definition_helper.get_class( ["TestComponent8"], ["NS1"] )
111
+ result.is_a?( ComponentClass ).should == true
112
+ result.name.should == "TestComponent8"
113
+ result.parent.should == result
114
+
115
+ result = @definition_helper.get_class( ["TestComponent9"], ["NS1"] )
116
+ result.is_a?( ComponentClass ).should == true
117
+ result.name.should == "TestComponent9"
118
+ result.parent.is_a?( ComponentClass ).should == true
119
+ result.parent.name.should == "TestComponent10"
120
+ result.parent.parent.should == result
121
+
122
+ end
123
+
124
+ it "should fail if the definition's class name doesn't match its filename" do
125
+ begin
126
+ result = @definition_helper.get_class( ["TestComponent11"], ["NS1"] )
127
+ rescue Exceptions::DefinitionMalformed
128
+ success = true
129
+ end
130
+
131
+ success.should == true
132
+ end
133
+
134
+ end
@@ -0,0 +1,236 @@
1
+ ################################################################################
2
+ # (C) Copyright 2009 William Madden
3
+ #
4
+ # This file is part of Proteus.
5
+ #
6
+ # Proteus is free software: you can redistribute it and/or modify it under the
7
+ # terms of the GNU General Public License as published by the Free Software
8
+ # Foundation, either version 3 of the License, or (at your option) any later
9
+ # version.
10
+ #
11
+ # Proteus is distributed in the hope that it will be useful, but WITHOUT ANY
12
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # Proteus. If not, see <http://www.gnu.org/licenses/>.
17
+ ################################################################################
18
+
19
+ require File.expand_path( 'lib/InputParser.rb' )
20
+
21
+ include Proteus
22
+
23
+
24
+ describe DefinitionParser do
25
+
26
+ #-----------------------------------------------------------------------------
27
+ #
28
+ # Input Constants
29
+ #
30
+ #-----------------------------------------------------------------------------
31
+
32
+ class DummyInputParser
33
+
34
+ attr_accessor :called, :inputs
35
+
36
+ def initialize
37
+ @inputs = []
38
+ end
39
+
40
+ def parse_yaml( yaml, current_ns )
41
+ @called = true
42
+ @inputs.push( yaml )
43
+ end
44
+
45
+ end
46
+
47
+ class DummyClassParser
48
+
49
+ attr_accessor :called, :yaml, :component_class
50
+
51
+ def initialize()
52
+ @called = false
53
+ end
54
+
55
+ def parse_yaml( yaml, component_class )
56
+ @called = true
57
+
58
+ @yaml = yaml
59
+ @component_class = component_class
60
+
61
+ component_class.name = "SomeComponent"
62
+ component_class.parent = "SomeParent"
63
+ component_class.children = [
64
+ "child1",
65
+ "child2",
66
+ "child3"
67
+ ]
68
+ component_class.properties = {
69
+ "prop1" => "value1",
70
+ "prop2" => "value2",
71
+ "prop3" => "value3"
72
+ }
73
+
74
+ return component_class
75
+ end
76
+
77
+ end
78
+
79
+ class DummyDefinitionHelper
80
+
81
+ attr_accessor :called, :class_id
82
+
83
+ def get_class( class_id, current_ns )
84
+ @called = true
85
+ @class_id = class_id
86
+
87
+ return nil
88
+ end
89
+
90
+ end
91
+
92
+ @@PARENT_NAME = "SomeParent"
93
+ @@UNKNOWN_PARENT_NAME = "UnknownParent"
94
+
95
+ @@COMPONENT_NAME = "SomeComponent"
96
+ @@COMPONENT_CHILDREN = [
97
+ "child1",
98
+ "child2",
99
+ "child3"
100
+ ]
101
+ @@COMPONENT_PROPS = {
102
+ "prop1" => "value1",
103
+ "prop2" => "value2",
104
+ "prop3" => "value3"
105
+ }
106
+
107
+ @@COMPONENT_FULL_PROPS = {
108
+ "prop1" => "value1",
109
+ "prop2" => "value2",
110
+ "prop3" => "value3",
111
+ "children" => @@COMPONENT_CHILDREN
112
+ }
113
+
114
+ @@EXPECTED_INPUTS = [
115
+ "value1",
116
+ "value2",
117
+ "value3",
118
+ "child1",
119
+ "child2",
120
+ "child3"
121
+ ]
122
+
123
+ @@DEFINITION = {
124
+ @@COMPONENT_NAME + " < " + @@PARENT_NAME => @@COMPONENT_FULL_PROPS
125
+ }
126
+
127
+ @@UNKNOWN_PARENT_DEFINITION = {
128
+ @@COMPONENT_NAME + " < " + @@UNKNOWN_PARENT_NAME => @@COMPONENT_FULL_PROPS
129
+ }
130
+
131
+ #-----------------------------------------------------------------------------
132
+ #
133
+ # Set up, tear down
134
+ #
135
+ #-----------------------------------------------------------------------------
136
+
137
+ #------------------------------
138
+ # before(:each)
139
+ #------------------------------
140
+
141
+ before(:each) do
142
+ @dummy_dh = DummyDefinitionHelper.new
143
+ @dummy_cp = DummyClassParser.new
144
+ @dummy_ip = DummyInputParser.new
145
+
146
+ @definition_parser =
147
+ DefinitionParser.new( @dummy_dh, @dummy_cp, @dummy_ip )
148
+ end
149
+
150
+ #-----------------------------------------------------------------------------
151
+ #
152
+ # Tests
153
+ #
154
+ #-----------------------------------------------------------------------------
155
+
156
+ it "should use the class parser to parse the file" do
157
+
158
+ component_class = ComponentClass.new
159
+
160
+ @definition_parser.parse_yaml( @@DEFINITION, component_class )
161
+
162
+ @dummy_cp.called.should == true
163
+ @dummy_cp.component_class.should == component_class
164
+ @dummy_cp.yaml.should == @@DEFINITION
165
+
166
+ end
167
+
168
+
169
+ it "should use the input parser to parse the class's values" do
170
+
171
+ component_class = ComponentClass.new
172
+
173
+ @definition_parser.parse_yaml( @@DEFINITION, component_class )
174
+
175
+ @dummy_ip.called.should == true
176
+ @dummy_ip.inputs.should == @@EXPECTED_INPUTS
177
+
178
+ end
179
+
180
+
181
+ it "should use the definition helper to get the parent" do
182
+
183
+ component_class = ComponentClass.new
184
+
185
+ @definition_parser.parse_yaml( @@DEFINITION, component_class )
186
+
187
+ @dummy_dh.called.should == true
188
+ @dummy_dh.class_id.should == [ @@PARENT_NAME ]
189
+
190
+ end
191
+
192
+
193
+ it "should fail if the parent is unavailable" do
194
+
195
+ component_class = ComponentClass.new
196
+
197
+ # Set up real parsers
198
+
199
+ # Instance parser
200
+ @instance_parser = InstanceParser.new
201
+
202
+ # Class parser
203
+ @class_parser = ClassParser.new
204
+
205
+ # Definition parser
206
+ @definition_parser = DefinitionParser.new
207
+ @definition_parser.class_parser = @class_parser
208
+
209
+ # Definition helper
210
+ @definition_helper = DefinitionHelper.new
211
+ @definition_helper.definition_parser = @definition_parser
212
+ @definition_helper.path = "spec/lib"
213
+
214
+ @definition_parser.definition_helper = @definition_helper
215
+
216
+ # Input parser
217
+ @input_parser = InputParser.new
218
+ @input_parser.instance_parser = @instance_parser
219
+ @input_parser.definition_helper = @definition_helper
220
+
221
+ @definition_parser.input_parser = @input_parser
222
+
223
+ begin
224
+ @definition_parser.parse_yaml( @@UNKNOWN_PARENT_DEFINITION,
225
+ component_class )
226
+ rescue Exceptions::DefinitionUnavailable
227
+ success = true
228
+ end
229
+
230
+ success.should == true
231
+
232
+ end
233
+
234
+
235
+ end
236
+