vidalia 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a60b306129eebe17ace114e099a2002c8b270e2
4
+ data.tar.gz: 107470ee1e0d86ce65231c79c42be2e7000aeebd
5
+ SHA512:
6
+ metadata.gz: 9eab8185fad11164351b752c94cfc32b93e13d3344f35e26962d11e1bedc39e464a63361fe0b2d79d2bee7383b13b861a712856dc7f5fb5ebdd22a139eaf7f67
7
+ data.tar.gz: 72981f0c4531399059f2b766e98cc1c6f240c63d29d012880c662f7d4cc0fcb3a0ea30b3b8f4d810084d2a9dc43300fb02a18d52153fcde70ef1977d85caf7d5
@@ -0,0 +1,159 @@
1
+ module Vidalia
2
+
3
+ class Artifact
4
+
5
+ attr_reader :name, :parent, :init_block
6
+
7
+ # Create an Artifact
8
+ #
9
+ # Initializes a Vidalia::Artifact using the data set in Vidalia::Artifact.define. If such data
10
+ # does not exist, this routine will error out. This ensures that all Artifacts have been
11
+ # predefined.
12
+ #
13
+ # *Options*
14
+ #
15
+ # Takes a hash as input where the current options are:
16
+ # +name+:: (required) specifies the name of the Interface
17
+ # +parent+:: (required) specifies the Vidalia::Identifier of the parent object
18
+ # +definition+:: (optional) specifies the Vidalia::Artifact contained by the artifact's definition
19
+ #
20
+ # *Example*
21
+ #
22
+ # $$$ Example needed $$$
23
+ #
24
+ def initialize(opts = {},&block)
25
+ o = {
26
+ :name => nil,
27
+ :parent => nil,
28
+ :definition => nil
29
+ }.merge(opts)
30
+
31
+ Vidalia::checkvar(o[:name],String,self.class.ancestors,"name")
32
+ @name = o[:name]
33
+ @type = Vidalia::Artifact unless @type
34
+ @children = Hash.new
35
+
36
+ if o[:parent]
37
+ # Add myself as a child of my parent
38
+ Vidalia::checkvar(o[:parent],Vidalia::Artifact,self.class.ancestors,"parent")
39
+ @parent = o[:parent]
40
+ @parent.add_child(self)
41
+ else
42
+ # Just kidding. I'm an orphan. :(
43
+ @parent = nil
44
+ end
45
+
46
+ @source_artifact = o[:definition]
47
+
48
+ if @source_artifact
49
+ # If this is an instantiation of a definition
50
+
51
+ Vidalia::checkvar(@source_artifact,Vidalia::Artifact,self.class.ancestors,"definition")
52
+
53
+ # Copy the initialization block and run it if defined
54
+ @init_block = @source_artifact.init_block
55
+ if @init_block
56
+ block = @init_block
57
+ instance_eval(&block)
58
+ end
59
+ else
60
+ # If this is only a definition
61
+
62
+ # Store the initialization block
63
+ @init_block = block
64
+ end
65
+ end
66
+
67
+
68
+ # Copy an Artifact from another Artifact
69
+ #
70
+ # *Options*
71
+ #
72
+ # Takes one parameter:
73
+ # +source+:: specifies the name of the Interface to copy from
74
+ #
75
+ # *Example*
76
+ #
77
+ # $$$ Example Needed $$$
78
+ #
79
+ def self.copy_from(source)
80
+ Vidalia::checkvar(source,Vidalia::Artifact,self.class.ancestors,"source")
81
+ @name = source.type
82
+ @type = source.type
83
+ @init_block = source.init_block
84
+ super
85
+ end
86
+
87
+
88
+ # Add a child object to this Artifact
89
+ #
90
+ # *Options*
91
+ #
92
+ # This method takes one parameter:
93
+ # +object+:: specifies a Vidalia::Artifact object to be added as a child
94
+ #
95
+ # *Example*
96
+ #
97
+ # # Note that both the "Blog API" and "Blog Post" Artifacts must be predefined
98
+ # blog_api = Vidalia::Artifact.new("Blog API")
99
+ # blog_post = Vidalia::Artifact.new("Blog Post")
100
+ # blog_api.add_child(blog_post)
101
+ #
102
+ def add_child(object)
103
+ Vidalia::checkvar(object,Vidalia::Artifact,self.class.ancestors,"object")
104
+ @children[object.name] = object
105
+ object.set_parent(self)
106
+ end
107
+
108
+
109
+ # Get a child of this Artifact
110
+ #
111
+ # *Options*
112
+ #
113
+ # This method takes one parameter:
114
+ # +name+:: specifies the name of a child of this Artifact
115
+ #
116
+ # *Example*
117
+ #
118
+ # $$$ Example needed $$$
119
+ #
120
+ def get_child(name)
121
+ Vidalia::checkvar(name,String,self.class.ancestors,"name")
122
+ @children[name]
123
+ end
124
+
125
+
126
+ # Get a the number of children of this Artifact
127
+ #
128
+ # *Options*
129
+ #
130
+ # This method takes no parameters.
131
+ #
132
+ # *Example*
133
+ #
134
+ # $$$ Example needed $$$
135
+ #
136
+ def number_of_children
137
+ @children.size
138
+ end
139
+
140
+
141
+ # Set the parent of this Artifact
142
+ #
143
+ # *Options*
144
+ #
145
+ # This method takes one parameter:
146
+ # +parent+: specifies the parent object of this Artifact
147
+ #
148
+ # *Example*
149
+ #
150
+ # $$$ Example needed $$$
151
+ #
152
+ def set_parent(parent)
153
+ @parent = parent
154
+ end
155
+
156
+
157
+ end
158
+
159
+ end
@@ -0,0 +1,413 @@
1
+ module Vidalia
2
+
3
+ class Element < Artifact
4
+
5
+ attr_reader :name, :parent, :set_function, :get_function, :retrieve_function, :verify_function, :confirm_function, :update_function
6
+
7
+ # Define an Element
8
+ #
9
+ # This routine takes a Vidalia::ObjectDefinition and adds an Element
10
+ # definition to the associated Object.
11
+ #
12
+ # *Options*
13
+ #
14
+ # Takes a hash as input where the current options are:
15
+ # +name+:: specifies the name of the Element
16
+ # +parent+:: specifies the Object that the Element is associated with
17
+ #
18
+ # +block+:: specifies the block of code to be run when the Element is initialized
19
+ #
20
+ # *Example*
21
+ #
22
+ # $$$ Example needed $$$
23
+ #
24
+ def self.define(opts = {}, &block)
25
+ Vidalia::ElementDefinition.new(opts,&block)
26
+ end
27
+
28
+
29
+ # Create an Element (inherited from Vidalia::Artifact)
30
+ #
31
+ # Initializes a Vidalia::Element using the data set in
32
+ # Vidalia::Element.define. If such data does not exist, this routine will
33
+ # error out. This ensures that all Elements have been predefined.
34
+ #
35
+ # *Options*
36
+ #
37
+ # Takes a hash as input where the current options are:
38
+ # +name+:: specifies the name of the Interface
39
+ # +parent+:: specifies the Vidalia::Identifier of the parent object
40
+ #
41
+ # *Example*
42
+ #
43
+ # $$$ Example needed $$$
44
+ #
45
+ def initialize(opts = {})
46
+ o = {
47
+ :name => nil,
48
+ :parent => nil,
49
+ :definition => nil,
50
+ }.merge(opts)
51
+
52
+ @type = Vidalia::Element
53
+ super
54
+ if o[:definition]
55
+ my_def = o[:definition]
56
+ Vidalia::checkvar(my_def,Vidalia::Element,self.class.ancestors,"definition")
57
+ @get_function = my_def.get_function
58
+ @set_function = my_def.set_function
59
+ @retrieve_function = my_def.retrieve_function
60
+ @verify_function = my_def.verify_function
61
+ @confirm_function = my_def.confirm_function
62
+ @update_function = my_def.update_function
63
+ if @get_function
64
+ add_generic_retrieve() unless @retrieve_function
65
+ add_generic_verify() unless @verify_function
66
+ add_generic_confirm() unless @confirm_function
67
+ if @set_function
68
+ add_generic_update() unless @update_function
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+
75
+ # Set the generic retrieve directive for this Element
76
+ #
77
+ # *Options*
78
+ #
79
+ # Takes no parameters.
80
+ #
81
+ # *Example*
82
+ #
83
+ # $$$ Example Needed $$$
84
+ #
85
+ def add_generic_retrieve()
86
+ @retrieve_function = @get_function
87
+ end
88
+
89
+
90
+ # Set the generic verify directive for this Element
91
+ #
92
+ # *Options*
93
+ #
94
+ # Takes no parameters.
95
+ #
96
+ # *Example*
97
+ #
98
+ # $$$ Example Needed $$$
99
+ #
100
+ def add_generic_verify()
101
+ add_verify { |value|
102
+ found_value = retrieve(value)
103
+ if value == found_value
104
+ Vidalia.log("Verified #{@name} to be \"#{value}\"")
105
+ else
106
+ raise "Expected #{@name} to be \"#{value}\", but found \"#{found_value}\" instead"
107
+ end
108
+ true
109
+ }
110
+ end
111
+
112
+
113
+ # Set the generic confirm directive for this Element
114
+ #
115
+ # *Options*
116
+ #
117
+ # Takes no parameters.
118
+ #
119
+ # *Example*
120
+ #
121
+ # $$$ Example Needed $$$
122
+ #
123
+ def add_generic_confirm()
124
+ add_confirm { |value|
125
+ retval = false
126
+ found_value = retrieve(value)
127
+ if value == found_value
128
+ retval = true
129
+ end
130
+ retval
131
+ }
132
+ end
133
+
134
+
135
+ # Set the generic update directive for this Element
136
+ #
137
+ # *Options*
138
+ #
139
+ # Takes no parameters.
140
+ #
141
+ # *Example*
142
+ #
143
+ # $$$ Example Needed $$$
144
+ #
145
+ def add_generic_update()
146
+ add_update { |value|
147
+ new_value = value
148
+ found_value = retrieve()
149
+ if new_value == found_value
150
+ capital_text = @name
151
+ capital_text[0] = capital_text[0].capitalize
152
+ Vidalia.log("#{capital_text} is already set to \"#{new_value}\"")
153
+ else
154
+ Vidalia.log("Entering #{@name}: \"#{new_value}\" (was \"#{found_value}\")")
155
+ set(new_value)
156
+ end
157
+ }
158
+ end
159
+
160
+
161
+ # Copy an Interface from another Interface (inherited from Vidalia::Artifact)
162
+ #
163
+ # *Options*
164
+ #
165
+ # Takes one parameter:
166
+ # +source+:: specifies the name of the Interface to copy from
167
+ #
168
+ # *Example*
169
+ #
170
+ # $$$ Example Needed $$$
171
+ #
172
+ def self.copy_from(source)
173
+ super
174
+ end
175
+
176
+
177
+ # Add a "get" function
178
+ #
179
+ # This function will be called to obtain the data element value from the
180
+ # Object. A call to "get" really makes the most sense AFTER obtaining
181
+ # data from the database/API.
182
+ #
183
+ # *Options*
184
+ #
185
+ # Takes a block to be executed when "get" for this Element is invoked.
186
+ # The input block should take a hash as a parameter.
187
+ #
188
+ # *Example*
189
+ #
190
+ # $$$ Example needed $$$
191
+ #
192
+ def add_get(&block)
193
+ @get_function = block
194
+ end
195
+
196
+
197
+ # Call the "get" function
198
+ #
199
+ # Call the pre-defined "get" function for this element.
200
+ #
201
+ # *Options*
202
+ #
203
+ # Takes a hash as input, with data as expected by the pre-defined "get"
204
+ # block.
205
+ #
206
+ # *Example*
207
+ #
208
+ # $$$ Example needed $$$
209
+ #
210
+ def get(inparams = {})
211
+ block = @get_function
212
+ instance_exec(inparams,&block)
213
+ end
214
+
215
+
216
+ # Add a "set" function
217
+ #
218
+ # This function will be called to set the element's value in the Object.
219
+ # Object. A call to "set" really makes the most sense BEFORE making an
220
+ # alteration to the Object data via database/API call.
221
+ #
222
+ # *Options*
223
+ #
224
+ # Takes a block to be executed when "set" for this Element is invoked.
225
+ # The input block should take a hash as a parameter.
226
+ #
227
+ # *Example*
228
+ #
229
+ # $$$ Example needed $$$
230
+ #
231
+ def add_set(&block)
232
+ @set_function = block
233
+ end
234
+
235
+
236
+ # Call the "set" function
237
+ #
238
+ # Call the pre-defined "set" function for this element.
239
+ #
240
+ # *Options*
241
+ #
242
+ # Takes a hash as input, with data as expected by the pre-defined "set"
243
+ # block.
244
+ #
245
+ # *Example*
246
+ #
247
+ # $$$ Example needed $$$
248
+ #
249
+ def set(inparams = {})
250
+ block = @set_function
251
+ instance_exec(inparams,&block)
252
+ end
253
+
254
+
255
+ # Add a "retrieve" function
256
+ #
257
+ # This function will be called to obtain the data element value from the
258
+ # Object. A call to "retrieve" really makes the most sense AFTER obtaining
259
+ # data from the database/API.
260
+ #
261
+ # *Options*
262
+ #
263
+ # Takes a block to be executed when "retrieve" for this Element is invoked.
264
+ # The input block should take a hash as a parameter.
265
+ #
266
+ # *Example*
267
+ #
268
+ # $$$ Example needed $$$
269
+ #
270
+ def add_retrieve(&block)
271
+ @retrieve_function = block
272
+ end
273
+
274
+
275
+ # Call the "retrieve" function
276
+ #
277
+ # Call the pre-defined "retrieve" function for this element.
278
+ #
279
+ # *Options*
280
+ #
281
+ # Takes a hash as input, with data as expected by the pre-defined "retrieve"
282
+ # block.
283
+ #
284
+ # *Example*
285
+ #
286
+ # $$$ Example needed $$$
287
+ #
288
+ def retrieve(inparams = {})
289
+ block = @retrieve_function
290
+ instance_exec(inparams,&block)
291
+ end
292
+
293
+
294
+ # Add a "verify" function
295
+ #
296
+ # This function will be called to obtain the data element value from the
297
+ # Object. A call to "verify" really makes the most sense AFTER obtaining
298
+ # data from the database/API.
299
+ #
300
+ # *Options*
301
+ #
302
+ # Takes a block to be executed when "verify" for this Element is invoked.
303
+ # The input block should take a hash as a parameter.
304
+ #
305
+ # *Example*
306
+ #
307
+ # $$$ Example needed $$$
308
+ #
309
+ def add_verify(&block)
310
+ @verify_function = block
311
+ end
312
+
313
+
314
+ # Call the "verify" function
315
+ #
316
+ # Call the pre-defined "verify" function for this element.
317
+ #
318
+ # *Options*
319
+ #
320
+ # Takes a hash as input, with data as expected by the pre-defined "verify"
321
+ # block.
322
+ #
323
+ # *Example*
324
+ #
325
+ # $$$ Example needed $$$
326
+ #
327
+ def verify(inparams = {})
328
+ block = @verify_function
329
+ instance_exec(inparams,&block)
330
+ end
331
+
332
+
333
+ # Add a "confirm" function
334
+ #
335
+ # This function will be called to obtain the data element value from the
336
+ # Object. A call to "confirm" really makes the most sense AFTER obtaining
337
+ # data from the database/API.
338
+ #
339
+ # *Options*
340
+ #
341
+ # Takes a block to be executed when "confirm" for this Element is invoked.
342
+ # The input block should take a hash as a parameter.
343
+ #
344
+ # *Example*
345
+ #
346
+ # $$$ Example needed $$$
347
+ #
348
+ def add_confirm(&block)
349
+ @confirm_function = block
350
+ end
351
+
352
+
353
+ # Call the "confirm" function
354
+ #
355
+ # Call the pre-defined "confirm" function for this element.
356
+ #
357
+ # *Options*
358
+ #
359
+ # Takes a hash as input, with data as expected by the pre-defined "confirm"
360
+ # block.
361
+ #
362
+ # *Example*
363
+ #
364
+ # $$$ Example needed $$$
365
+ #
366
+ def confirm(inparams = {})
367
+ block = @confirm_function
368
+ instance_exec(inparams,&block)
369
+ end
370
+
371
+
372
+ # Add a "update" function
373
+ #
374
+ # This function will be called to obtain the data element value from the
375
+ # Object. A call to "update" really makes the most sense AFTER obtaining
376
+ # data from the database/API.
377
+ #
378
+ # *Options*
379
+ #
380
+ # Takes a block to be executed when "update" for this Element is invoked.
381
+ # The input block should take a hash as a parameter.
382
+ #
383
+ # *Example*
384
+ #
385
+ # $$$ Example needed $$$
386
+ #
387
+ def add_update(&block)
388
+ @update_function = block
389
+ end
390
+
391
+
392
+ # Call the "update" function
393
+ #
394
+ # Call the pre-defined "update" function for this element.
395
+ #
396
+ # *Options*
397
+ #
398
+ # Takes a hash as input, with data as expected by the pre-defined "update"
399
+ # block.
400
+ #
401
+ # *Example*
402
+ #
403
+ # $$$ Example needed $$$
404
+ #
405
+ def update(inparams = {})
406
+ block = @update_function
407
+ instance_exec(inparams,&block)
408
+ end
409
+
410
+
411
+ end
412
+
413
+ end
@@ -0,0 +1,179 @@
1
+ module Vidalia
2
+
3
+ class ElementDefinition
4
+
5
+ attr_reader :name, :parent, :children, :element
6
+
7
+ # Create an Element Definition
8
+ #
9
+ # Under the covers, the ElementDefinition will create an associated
10
+ # Element definition. Any instantiated Element under the parent Object
11
+ # will be copied from this master copy.
12
+ #
13
+ # *Options*
14
+ #
15
+ # Takes two parameters:
16
+ # Takes a hash as input where the current options are:
17
+ # +name+:: (required) specifies the name of the Element
18
+ # +parent+:: (required) specifies the name of the parent Object
19
+ # Takes a block to be executed at initialization time
20
+ #
21
+ # *Example*
22
+ #
23
+ # $$$ Example needed $$$
24
+ #
25
+ def initialize(opts = {}, &block)
26
+ o = {
27
+ :name => nil,
28
+ :parent => nil
29
+ }.merge(opts)
30
+
31
+ Vidalia::checkvar(o[:name],String,self.class.ancestors,"name")
32
+ Vidalia::checkvar(o[:parent],Vidalia::ObjectDefinition,self.class.ancestors,"parent")
33
+
34
+ o[:parent] = o[:parent].object
35
+ @element = Vidalia::Element.new(o,&block)
36
+ end
37
+
38
+
39
+ # Add a "get" function for a Defined Element
40
+ #
41
+ # This function will be called to obtain the data element value from the
42
+ # Object. A call to "get" really makes the most sense AFTER obtaining
43
+ # data from the database/API.
44
+ #
45
+ # *Options*
46
+ #
47
+ # Takes a block to be executed when "get" for this defined Element is
48
+ # invoked.
49
+ #
50
+ # *Example*
51
+ #
52
+ # $$$ Example needed $$$
53
+ #
54
+ def add_get(&block)
55
+ if block.arity > 1
56
+ raise "Vidalia::ElementDefinition.add_get block must take a single parameter"
57
+ end
58
+ @element.add_get &block
59
+ end
60
+
61
+
62
+ # Add a "set" function for a Defined Element
63
+ #
64
+ # This function will be called to set the element's value in the Object.
65
+ # Object. A call to "set" really makes the most sense BEFORE making an
66
+ # alteration to the Object data via database/API call.
67
+ #
68
+ # *Options*
69
+ #
70
+ # Takes a block to be executed when "set" for this defined Element is
71
+ # invoked.
72
+ #
73
+ # *Example*
74
+ #
75
+ # $$$ Example needed $$$
76
+ #
77
+ def add_set(&block)
78
+ if block.arity > 1
79
+ raise "Vidalia::ElementDefinition.add_set block must take a single parameter"
80
+ end
81
+ @element.add_set &block
82
+ end
83
+
84
+
85
+ # Add a "retrieve" function for a Defined Element
86
+ #
87
+ # This function will be called to obtain the data element value from the
88
+ # Object. A call to "retrieve" really makes the most sense AFTER obtaining
89
+ # data from the database/API.
90
+ #
91
+ # *Options*
92
+ #
93
+ # Takes a block to be executed when "retrieve" for this defined Element is
94
+ # invoked.
95
+ #
96
+ # *Example*
97
+ #
98
+ # $$$ Example needed $$$
99
+ #
100
+ def add_retrieve(&block)
101
+ if block.arity > 1
102
+ raise "Vidalia::ElementDefinition.add_retrieve block must take a single parameter"
103
+ end
104
+ @element.add_retrieve &block
105
+ end
106
+
107
+
108
+ # Add a "verify" function for a Defined Element
109
+ #
110
+ # This function will be called to obtain the data element value from the
111
+ # Object. A call to "verify" really makes the most sense AFTER obtaining
112
+ # data from the database/API.
113
+ #
114
+ # *Options*
115
+ #
116
+ # Takes a block to be executed when "verify" for this defined Element is
117
+ # invoked.
118
+ #
119
+ # *Example*
120
+ #
121
+ # $$$ Example needed $$$
122
+ #
123
+ def add_verify(&block)
124
+ if block.arity > 1
125
+ raise "Vidalia::ElementDefinition.add_verify block must take a single parameter"
126
+ end
127
+ @element.add_verify &block
128
+ end
129
+
130
+
131
+ # Add a "confirm" function for a Defined Element
132
+ #
133
+ # This function will be called to obtain the data element value from the
134
+ # Object. A call to "confirm" really makes the most sense AFTER obtaining
135
+ # data from the database/API.
136
+ #
137
+ # *Options*
138
+ #
139
+ # Takes a block to be executed when "confirm" for this defined Element is
140
+ # invoked.
141
+ #
142
+ # *Example*
143
+ #
144
+ # $$$ Example needed $$$
145
+ #
146
+ def add_confirm(&block)
147
+ if block.arity > 1
148
+ raise "Vidalia::ElementDefinition.add_confirm block must take a single parameter"
149
+ end
150
+ @element.add_confirm &block
151
+ end
152
+
153
+
154
+ # Add a "update" function for a Defined Element
155
+ #
156
+ # This function will be called to obtain the data element value from the
157
+ # Object. A call to "update" really makes the most sense when updating
158
+ # data AFTER obtaining data from the database/API.
159
+ #
160
+ # *Options*
161
+ #
162
+ # Takes a block to be executed when "update" for this defined Element is
163
+ # invoked.
164
+ #
165
+ # *Example*
166
+ #
167
+ # $$$ Example needed $$$
168
+ #
169
+ def add_update(&block)
170
+ if block.arity > 1
171
+ raise "Vidalia::ElementDefinition.add_update block must take a single parameter"
172
+ end
173
+ @element.add_update &block
174
+ end
175
+
176
+
177
+ end
178
+
179
+ end
@@ -0,0 +1,106 @@
1
+ module Vidalia
2
+
3
+ class Interface < Artifact
4
+
5
+ attr_reader :name, :interface
6
+
7
+ # Define an Interface
8
+ #
9
+ # This routine "stores" the defined Interface attributes in a
10
+ # Vidalia::InterfaceDefinition. Any subsequent call to instantiate
11
+ # an Interface object will copy that object from the InterfaceDefinition.
12
+ #
13
+ # *Options*
14
+ #
15
+ # Takes a hash as input where the current options are:
16
+ # +name+:: (required) specifies the name of the interface
17
+ # +block+:: (optional) specifies a block of code to be run when the interface object is initialized
18
+ #
19
+ # *Example*
20
+ #
21
+ # Vidalia::Interface.define(:name => "Blog API") {
22
+ # @db_password = ENV['BLOG_DB_PASSWORD']
23
+ # @db_userid = ENV['BLOG_DB_PASSWORD']
24
+ # @db_ip = ENV['BLOG_DB_IP']
25
+ # @db_port = ENV['BLOG_DB_PORT']
26
+ # }
27
+ #
28
+ def self.define(opts = {}, &block)
29
+ Vidalia::InterfaceDefinition.new(opts,&block)
30
+ end
31
+
32
+
33
+ # Create an Interface (inherited from Vidalia::Artifact)
34
+ #
35
+ # Initializes a Vidalia::Interface using the data set in Vidalia::Interface.define. If such data
36
+ # does not exist, this routine will error out. This ensures that all Interfaces have been
37
+ # predefined.
38
+ #
39
+ # *Options*
40
+ #
41
+ # Takes a hash as input where the current options are:
42
+ # +name+:: specifies the name of the Interface
43
+ #
44
+ # *Example*
45
+ #
46
+ # blog_api = Vidalia::Interface.new("Blog API")
47
+ #
48
+ def initialize(opts = {}, &block)
49
+ o = {
50
+ :name => nil,
51
+ :definition => nil
52
+ }.merge(opts)
53
+
54
+ @type = Vidalia::Interface
55
+ super
56
+ end
57
+
58
+
59
+ # Retrieve a child Object of this Interface by name
60
+ #
61
+ # *Options*
62
+ #
63
+ # This method takes one parameter:
64
+ # +name+:: specifies the name of the child Object
65
+ #
66
+ # *Example*
67
+ #
68
+ # $$$ Example needed $$$
69
+ #
70
+ def object(name)
71
+ Vidalia::checkvar(name,String,self.class.ancestors,"name")
72
+ child = get_child(name)
73
+ unless child
74
+ # Child does not yet exist. Create it.
75
+ child = Vidalia::Object.new(
76
+ :name => name,
77
+ :parent => self,
78
+ :definition => @source_artifact.get_child(name)
79
+ )
80
+ end
81
+ child
82
+ end
83
+
84
+
85
+ # Get an Interface object by name
86
+ #
87
+ # *Options*
88
+ #
89
+ # This method takes one parameter:
90
+ # +name+:: (required) specifies the name of the Interface
91
+ #
92
+ # *Example*
93
+ #
94
+ # $$$ Example needed $$$
95
+ #
96
+ def self.get(name)
97
+ return Vidalia::Interface.new(
98
+ :name => name,
99
+ :definition => Vidalia::InterfaceDefinition.find(name)
100
+ )
101
+ end
102
+
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,69 @@
1
+ module Vidalia
2
+
3
+ class InterfaceDefinition
4
+
5
+ @@interfaces = []
6
+ attr_reader :name, :parent, :interface
7
+
8
+ # Create an Interface Definition
9
+ #
10
+ # Under the covers, the InterfaceDefinition will create or find the
11
+ # associated Interface definition. Any instantiated Interface will
12
+ # be copied from this master copy.
13
+ #
14
+ # *Options*
15
+ #
16
+ # Takes two parameters:
17
+ # Takes a hash as input where the current options are:
18
+ # +name+:: (required) specifies the name of the Interface
19
+ # Takes a block to be executed at initialization time
20
+ #
21
+ # *Example*
22
+ #
23
+ # blog_api = Vidalia::InterfaceDefinition.new("Blog API") {
24
+ # @db_password = ENV['BLOG_DB_PASSWORD']
25
+ # @db_userid = ENV['BLOG_DB_PASSWORD']
26
+ # @db_ip = ENV['BLOG_DB_IP']
27
+ # @db_port = ENV['BLOG_DB_PORT']
28
+ # }
29
+ #
30
+ def initialize(opts = {}, &block)
31
+ o = {
32
+ :name => nil
33
+ }.merge(opts)
34
+
35
+ Vidalia::checkvar(o[:name],String,self.class.ancestors,"name")
36
+
37
+ # It's OK to "define" an Interface that has already been defined
38
+ unless Vidalia::InterfaceDefinition.find(o[:name])
39
+ @interface = Vidalia::Interface.new(opts,&block)
40
+ @@interfaces << @interface
41
+ end
42
+ end
43
+
44
+
45
+ # Find an Interface by name
46
+ #
47
+ # *Options*
48
+ #
49
+ # Takes one parameter:
50
+ # +name+:: (required) specifies the name of the Interface
51
+ #
52
+ # *Example*
53
+ #
54
+ # $$$ Example needed $$$
55
+ #
56
+ def self.find(name)
57
+ Vidalia::checkvar(name,String,self.class.ancestors,"name")
58
+ interface = nil
59
+ @@interfaces.each do |i|
60
+ if i.name == name
61
+ interface = i
62
+ end
63
+ end
64
+ interface
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,139 @@
1
+ module Vidalia
2
+
3
+ class Object < Artifact
4
+
5
+ attr_reader :name, :parent, :added_methods
6
+
7
+ @@methodlist = Hash.new
8
+
9
+ # Define an Object
10
+ #
11
+ # This routine takes a Vidalia::InterfaceDefinition and adds an Object
12
+ # definition to the associated Interface.
13
+ #
14
+ # *Options*
15
+ #
16
+ # Takes a hash as input where the current options are:
17
+ # +name+:: specifies the name of the Object
18
+ # +interface+:: specifies the Vidalia::InterfaceDefinition that the Object is associated with
19
+ #
20
+ # +block+:: specifies the block of code to be run when the Object is initialized
21
+ #
22
+ # *Example*
23
+ #
24
+ # $$$ Example needed $$$
25
+ #
26
+ def self.define(opts = {}, &block)
27
+ Vidalia::ObjectDefinition.new(opts,&block)
28
+ end
29
+
30
+
31
+ # Create an Object (inherited from Vidalia::Artifact)
32
+ #
33
+ # Initializes a Vidalia::Object using the data set in
34
+ # Vidalia::Object.define. If such data does not exist, this routine will
35
+ # error out. This ensures that all Objects have been predefined.
36
+ #
37
+ # *Options*
38
+ #
39
+ # Takes a hash as input where the current options are:
40
+ # +name+:: specifies the name of the Object
41
+ # +parent+:: specifies the parent object
42
+ #
43
+ # *Example*
44
+ #
45
+ # $$$ Example needed $$$
46
+ #
47
+ def initialize(opts = {})
48
+ o = {
49
+ :name => nil,
50
+ :parent => nil,
51
+ :definition => nil
52
+ }.merge(opts)
53
+
54
+ @type = Vidalia::Object
55
+ super
56
+ @added_methods = Hash.new
57
+ if o[:definition]
58
+ my_def = o[:definition]
59
+ Vidalia::checkvar(my_def,Vidalia::Object,self.class.ancestors,"definition")
60
+ my_def.added_methods.each do |method_name,block|
61
+ @added_methods[method_name] = block
62
+ end
63
+ end
64
+ end
65
+
66
+
67
+ # Retrieve a child Element of this Object by name
68
+ #
69
+ # *Options*
70
+ #
71
+ # This method takes one parameter:
72
+ # +name+:: specifies the name of the child Element
73
+ #
74
+ # *Example*
75
+ #
76
+ # $$$ Example needed $$$
77
+ #
78
+ def element(name)
79
+ Vidalia::checkvar(name,String,self.class.ancestors,"name")
80
+ child = get_child(name)
81
+ unless child
82
+ # Child does not yet exist. Create it.
83
+ child = Vidalia::Element.new(
84
+ :name => name,
85
+ :parent => self,
86
+ :definition => @source_artifact.get_child(name)
87
+ )
88
+ end
89
+ child
90
+ end
91
+
92
+
93
+ # Define a method to act on a given Object
94
+ #
95
+ # *Options*
96
+ #
97
+ # Takes a hash as input where the current options are:
98
+ # +name+:: specifies the name of the method
99
+ # +token+:: specifies the Vidalia::ArtifactToken of the Object
100
+ #
101
+ # *Example*
102
+ #
103
+ # $$$ Example needed $$$
104
+ #
105
+ def add_method(opts = {},&block)
106
+ o = {
107
+ :name => nil
108
+ }.merge(opts)
109
+ Vidalia::checkvar(o[:name],String,self.class.ancestors,"name")
110
+ @added_methods[o[:name]] = block
111
+ end
112
+
113
+
114
+ # Add a pre-defined instance method to this Class
115
+ #
116
+ # *Options*
117
+ #
118
+ # Takes a hash as input where the current options are:
119
+ # +name+:: specifies the name of the method
120
+ #
121
+ # *Example*
122
+ #
123
+ # $$$ Example needed $$$
124
+ #
125
+ def self.define_method_for_object_class(name)
126
+ Vidalia::checkvar(name,String,self.class.ancestors,"name")
127
+ define_method name.to_sym do |opts = {}|
128
+ if @added_methods[name]
129
+ block = @added_methods[name]
130
+ instance_exec(opts,&block)
131
+ else
132
+ raise "Tried to call an Object method that doesn't exist."
133
+ end
134
+ end
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,77 @@
1
+ module Vidalia
2
+
3
+ class ObjectDefinition
4
+
5
+ attr_reader :name, :parent, :children, :object
6
+
7
+ @@defined_method_names = {}
8
+
9
+ # Create an Object Definition
10
+ #
11
+ # Under the covers, the ObjectDefinition will create an associated
12
+ # Object definition. Any instantiated Object under the parent Interface
13
+ # will be copied from this master copy.
14
+ #
15
+ # *Options*
16
+ #
17
+ # Takes two parameters:
18
+ # Takes a hash as input where the current options are:
19
+ # +name+:: (required) specifies the name of the Object
20
+ # +parent+:: (required) specifies the name of the parent Interface
21
+ # Takes a block to be executed at initialization time
22
+ #
23
+ # *Example*
24
+ #
25
+ # $$$ Example needed $$$
26
+ #
27
+ def initialize(opts = {}, &block)
28
+ o = {
29
+ :name => nil,
30
+ :parent => nil
31
+ }.merge(opts)
32
+
33
+ Vidalia::checkvar(o[:name],String,self.class.ancestors,"name")
34
+ Vidalia::checkvar(o[:parent],Vidalia::InterfaceDefinition,self.class.ancestors,"parent")
35
+
36
+ o[:parent] = o[:parent].interface
37
+ @object = Vidalia::Object.new(o,&block)
38
+ end
39
+
40
+
41
+ # Define a method to act on a defined Object
42
+ #
43
+ # Define a method that any Vidalia::Object can run and save the method code in
44
+ # the Vidalia::Object represented with this definition
45
+ #
46
+ # *Options*
47
+ #
48
+ # Takes a hash as input where the current options are:
49
+ # +name+:: specifies the name of the method
50
+ # Takes a block that defines the code to run for that method
51
+ #
52
+ # *Example*
53
+ #
54
+ # $$$ Example needed $$$
55
+ #
56
+ def add_method(opts = {},&block)
57
+ o = {
58
+ :name => nil
59
+ }.merge(opts)
60
+
61
+ name = o[:name]
62
+ Vidalia::checkvar(name,String,self.class.ancestors,"name")
63
+
64
+ # Save the method code in the Vidalia::Object represented with this definition
65
+ @object.add_method(o,&block)
66
+
67
+ # Define a method that any Vidalia::Object can run
68
+ unless @@defined_method_names[name]
69
+ @@defined_method_names[name] = true
70
+ Vidalia::Object.define_method_for_object_class(name)
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
data/lib/vidalia.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'vidalia/interface_definition'
2
+ require 'vidalia/object_definition'
3
+ require 'vidalia/element_definition'
4
+ require 'vidalia/artifact'
5
+ require 'vidalia/interface'
6
+ require 'vidalia/object'
7
+ require 'vidalia/element'
8
+
9
+ # [cat] something
10
+ # something else
11
+ #
12
+ #
13
+ # * Top level comment about Vidalia
14
+
15
+ module Vidalia
16
+
17
+ # Configure the logging routine to be used by Vidalia for this thread.
18
+ #
19
+ # The routine you store here can be invoked by Vidalia.log
20
+ #
21
+ # *Options*
22
+ #
23
+ # +&block+:: specifies the code block to be called whenever Vidalia needs to invoke a logger. This block should take a string followed by an optional hash as its parameters.
24
+ #
25
+ # *Example*
26
+ #
27
+ # Vidalia.set_logroutine { |string,opts|
28
+ # MyLogger::write(string,opts)
29
+ # }
30
+ def Vidalia.set_logroutine(&block)
31
+ Thread.current[:vidalia_logroutine] = block
32
+ end
33
+
34
+
35
+ # Write to the Vidalia log
36
+ #
37
+ # The log can be predefined by Vidalia.set_logroutine
38
+ #
39
+ # *Options*
40
+ #
41
+ # +string+:: specifies the string to write to the Vidalia log
42
+ # +opts+:: specifies a hash containing parameters to the Vidalia logging function
43
+ #
44
+ # *Example*
45
+ #
46
+ # Vidalia.log("Everything is fine - no bugs here.",:style => fatal_error)
47
+ def Vidalia.log(string,opts = {})
48
+ return Thread.current[:vidalia_logroutine].call(string,opts)
49
+ end
50
+
51
+
52
+ # Check the type and existence of a variable
53
+ #
54
+ # *Options*
55
+ #
56
+ # +thing+:: specifies the veriable to check
57
+ # +thingtype+:: specifies the desired type of the variable data
58
+ # +procclass+:: specifies the class of the calling method
59
+ # +procname+:: specifies the name of the calling method
60
+ #
61
+ # *Example*
62
+ #
63
+ # Vidalia.log("Everything is fine - no bugs here.",:style => fatal_error)
64
+ def Vidalia.checkvar(thing,thingtype,procclass,thingname)
65
+ if thing
66
+ unless thing.is_a?(thingtype)
67
+ raise "#{procclass.first}: #{thingname} should be a #{thingtype}, but was a #{thing.class} instead"
68
+ end
69
+ else
70
+ raise "#{procclass.first}: #{thingname} must be specified"
71
+ end
72
+ end
73
+
74
+
75
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vidalia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Rotter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Vidalia uses layers to simplify the creation and maintenance of API and
28
+ database calls in your automated test suite.
29
+ email: jeremy.rotter@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/vidalia.rb
35
+ - lib/vidalia/artifact.rb
36
+ - lib/vidalia/element.rb
37
+ - lib/vidalia/element_definition.rb
38
+ - lib/vidalia/interface.rb
39
+ - lib/vidalia/interface_definition.rb
40
+ - lib/vidalia/object.rb
41
+ - lib/vidalia/object_definition.rb
42
+ homepage: https://github.com/jrotter/vidalia
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.4.6
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Vidalia
66
+ test_files: []