virtengine_api 0.1.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 (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +21 -0
  6. data/README.md +27 -0
  7. data/Rakefile +10 -0
  8. data/lib/megam/api.rb +329 -0
  9. data/lib/megam/api/accounts.rb +96 -0
  10. data/lib/megam/api/addons.rb +27 -0
  11. data/lib/megam/api/assemblies.rb +49 -0
  12. data/lib/megam/api/assembly.rb +56 -0
  13. data/lib/megam/api/backups.rb +57 -0
  14. data/lib/megam/api/balances.rb +45 -0
  15. data/lib/megam/api/billedhistories.rb +35 -0
  16. data/lib/megam/api/billingtransactions.rb +25 -0
  17. data/lib/megam/api/components.rb +24 -0
  18. data/lib/megam/api/credits.rb +34 -0
  19. data/lib/megam/api/disks.rb +44 -0
  20. data/lib/megam/api/domains.rb +25 -0
  21. data/lib/megam/api/errors.rb +29 -0
  22. data/lib/megam/api/eventsall.rb +36 -0
  23. data/lib/megam/api/eventsbilling.rb +35 -0
  24. data/lib/megam/api/eventscontainer.rb +35 -0
  25. data/lib/megam/api/eventsmarketplace.rb +35 -0
  26. data/lib/megam/api/eventsstorage.rb +24 -0
  27. data/lib/megam/api/eventsvm.rb +35 -0
  28. data/lib/megam/api/flavors.rb +56 -0
  29. data/lib/megam/api/license.rb +26 -0
  30. data/lib/megam/api/marketplaces.rb +68 -0
  31. data/lib/megam/api/organizations.rb +50 -0
  32. data/lib/megam/api/promos.rb +18 -0
  33. data/lib/megam/api/quotas.rb +47 -0
  34. data/lib/megam/api/rawimages.rb +36 -0
  35. data/lib/megam/api/reports.rb +24 -0
  36. data/lib/megam/api/requests.rb +36 -0
  37. data/lib/megam/api/sensors.rb +35 -0
  38. data/lib/megam/api/snapshots.rb +46 -0
  39. data/lib/megam/api/sshkeys.rb +35 -0
  40. data/lib/megam/api/subscriptions.rb +26 -0
  41. data/lib/megam/api/version.rb +6 -0
  42. data/lib/megam/core/account.rb +245 -0
  43. data/lib/megam/core/account_collection.rb +122 -0
  44. data/lib/megam/core/addons.rb +169 -0
  45. data/lib/megam/core/addons_collection.rb +121 -0
  46. data/lib/megam/core/assemblies.rb +191 -0
  47. data/lib/megam/core/assemblies_collection.rb +122 -0
  48. data/lib/megam/core/assembly.rb +226 -0
  49. data/lib/megam/core/assembly_collection.rb +122 -0
  50. data/lib/megam/core/backups.rb +259 -0
  51. data/lib/megam/core/backups_collection.rb +122 -0
  52. data/lib/megam/core/balances.rb +187 -0
  53. data/lib/megam/core/balances_collection.rb +121 -0
  54. data/lib/megam/core/billedhistories.rb +190 -0
  55. data/lib/megam/core/billedhistories_collection.rb +121 -0
  56. data/lib/megam/core/billingtransactions.rb +214 -0
  57. data/lib/megam/core/billingtransactions_collection.rb +122 -0
  58. data/lib/megam/core/components.rb +326 -0
  59. data/lib/megam/core/components_collection.rb +123 -0
  60. data/lib/megam/core/credits.rb +146 -0
  61. data/lib/megam/core/credits_collection.rb +121 -0
  62. data/lib/megam/core/disks.rb +199 -0
  63. data/lib/megam/core/disks_collection.rb +122 -0
  64. data/lib/megam/core/domain_collection.rb +122 -0
  65. data/lib/megam/core/domains.rb +118 -0
  66. data/lib/megam/core/error.rb +70 -0
  67. data/lib/megam/core/eventsall.rb +186 -0
  68. data/lib/megam/core/eventsall_collection.rb +122 -0
  69. data/lib/megam/core/eventsbilling.rb +174 -0
  70. data/lib/megam/core/eventsbilling_collection.rb +122 -0
  71. data/lib/megam/core/eventscontainer.rb +187 -0
  72. data/lib/megam/core/eventscontainer_collection.rb +122 -0
  73. data/lib/megam/core/eventsmarketplace.rb +187 -0
  74. data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
  75. data/lib/megam/core/eventsstorage.rb +156 -0
  76. data/lib/megam/core/eventsstorage_collection.rb +122 -0
  77. data/lib/megam/core/eventsvm.rb +187 -0
  78. data/lib/megam/core/eventsvm_collection.rb +122 -0
  79. data/lib/megam/core/flavors.rb +294 -0
  80. data/lib/megam/core/flavors_collection.rb +121 -0
  81. data/lib/megam/core/json_compat.rb +289 -0
  82. data/lib/megam/core/konipai.rb +42 -0
  83. data/lib/megam/core/license.rb +101 -0
  84. data/lib/megam/core/license_collection.rb +122 -0
  85. data/lib/megam/core/log.rb +19 -0
  86. data/lib/megam/core/marketplace.rb +308 -0
  87. data/lib/megam/core/marketplace_collection.rb +123 -0
  88. data/lib/megam/core/monologger.rb +89 -0
  89. data/lib/megam/core/organizations.rb +142 -0
  90. data/lib/megam/core/organizations_collection.rb +121 -0
  91. data/lib/megam/core/promos.rb +145 -0
  92. data/lib/megam/core/quotas.rb +215 -0
  93. data/lib/megam/core/quotas_collection.rb +121 -0
  94. data/lib/megam/core/rawimages.rb +194 -0
  95. data/lib/megam/core/rawimages_collection.rb +121 -0
  96. data/lib/megam/core/reports.rb +176 -0
  97. data/lib/megam/core/reports_collection.rb +121 -0
  98. data/lib/megam/core/request.rb +197 -0
  99. data/lib/megam/core/request_collection.rb +121 -0
  100. data/lib/megam/core/rest_adapter.rb +44 -0
  101. data/lib/megam/core/sensors.rb +141 -0
  102. data/lib/megam/core/sensors_collection.rb +121 -0
  103. data/lib/megam/core/snapshots.rb +268 -0
  104. data/lib/megam/core/snapshots_collection.rb +122 -0
  105. data/lib/megam/core/sshkey.rb +173 -0
  106. data/lib/megam/core/sshkey_collection.rb +122 -0
  107. data/lib/megam/core/stuff.rb +22 -0
  108. data/lib/megam/core/subscriptions.rb +167 -0
  109. data/lib/megam/core/subscriptions_collection.rb +121 -0
  110. data/lib/megam/core/text.rb +87 -0
  111. data/lib/megam/core/text_formatter.rb +64 -0
  112. data/lib/megam/mixins/assemblies.rb +16 -0
  113. data/lib/megam/mixins/assembly.rb +59 -0
  114. data/lib/megam/mixins/common_deployable.rb +78 -0
  115. data/lib/megam/mixins/components.rb +182 -0
  116. data/lib/megam/mixins/megam_attributes.rb +30 -0
  117. data/lib/megam/mixins/outputs.rb +23 -0
  118. data/lib/megam/mixins/policies.rb +27 -0
  119. data/lib/megam_api.rb +1 -0
  120. data/megam_api.gemspec +26 -0
  121. data/test/mixins/test_assemblies.rb +113 -0
  122. data/test/mixins/test_assembly.rb +74 -0
  123. data/test/mixins/test_component.rb +19 -0
  124. data/test/test_accounts.rb +127 -0
  125. data/test/test_addons.rb +26 -0
  126. data/test/test_assemblies.rb +88 -0
  127. data/test/test_assembly.rb +37 -0
  128. data/test/test_backups.rb +29 -0
  129. data/test/test_balances.rb +38 -0
  130. data/test/test_billedhistories.rb +30 -0
  131. data/test/test_billingtranscations.rb +35 -0
  132. data/test/test_components.rb +42 -0
  133. data/test/test_credits.rb +28 -0
  134. data/test/test_disks.rb +25 -0
  135. data/test/test_domains.rb +29 -0
  136. data/test/test_eventsbilling.rb +30 -0
  137. data/test/test_eventscontainer.rb +26 -0
  138. data/test/test_eventsstorage.rb +12 -0
  139. data/test/test_eventsvm.rb +26 -0
  140. data/test/test_helper.rb +77 -0
  141. data/test/test_marketplaces.rb +38 -0
  142. data/test/test_organizations.rb +45 -0
  143. data/test/test_promos.rb +11 -0
  144. data/test/test_quotas.rb +33 -0
  145. data/test/test_reports.rb +32 -0
  146. data/test/test_requests.rb +95 -0
  147. data/test/test_sensors.rb +50 -0
  148. data/test/test_snapshots.rb +30 -0
  149. data/test/test_sshkeys.rb +50 -0
  150. data/test/test_subscriptions.rb +22 -0
  151. metadata +325 -0
@@ -0,0 +1,122 @@
1
+ module Megam
2
+ class BillingtransactionsCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @billingtransactions = Array.new
8
+ @billingtransactions_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_billingtransactions
13
+ @billingtransactions
14
+ end
15
+
16
+ def [](index)
17
+ @billingtransactions[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_billingtransactions(arg)
22
+ @@billingtransactions[index] = arg
23
+ @billingtransactions_by_name[arg.accounts_id] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_billingtransactions(a)
29
+ @billingtransactions << a
30
+ @billingtransactions_by_name[a.accounts_id] =@billingtransactions.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(billingtransactions)
39
+ is_megam_billingtransactions(billingtransactions)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any predefs inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ #
44
+ @billingtransactions.insert(@insert_after_idx + 1,billingtransactions)
45
+ # update name -> location mappings and register new
46
+ @billingtransactions_by_name.each_key do |key|
47
+ @billingtransactions_by_name[key] += 1 if@billingtransactions_by_name[key] > @insert_after_idx
48
+ end
49
+ @billingtransactions_by_name[billingtransactions.accounts_id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @billingtransactions << billingtransactions
53
+ @billingtransactions_by_name[billingtransactions.accounts_id] =@billingtransactions.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @billingtransactions.each do |billingtransactions|
59
+ yield billingtransactions
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @billingtransactions.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @billingtransactions.empty?
71
+ end
72
+
73
+ def lookup(billingtransactions)
74
+ lookup_by = nil
75
+ if billingtransactions.kind_of?(Megam::Billingtransactions)
76
+ lookup_by = billingtransactions.accounts_id
77
+ elsif billingtransactions.kind_of?(String)
78
+ lookup_by = billingtransactions
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Billingtransactions or String to lookup"
81
+ end
82
+ res =@billingtransactions_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @billingtransactions[res]
87
+ end
88
+
89
+ def to_s
90
+ @billingtransactions.join(", ")
91
+ end
92
+
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
96
+
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
100
+
101
+ def self.json_create(o)
102
+ collection = self.new()
103
+ o["results"].each do |billingtransactions_list|
104
+ billingtransactions_array = billingtransactions_list.kind_of?(Array) ? billingtransactions_list : [ billingtransactions_list ]
105
+ billingtransactions_array.each do |billingtransactions|
106
+ collection.insert(billingtransactions)
107
+ end
108
+ end
109
+ collection
110
+ end
111
+
112
+ private
113
+
114
+ def is_megam_billingtransactions(arg)
115
+ unless arg.kind_of?(Megam::Billingtransactions)
116
+ raise ArgumentError, "Members must be Megam::Billingtransactions's"
117
+ end
118
+ true
119
+ end
120
+
121
+ end
122
+ end
@@ -0,0 +1,326 @@
1
+ module Megam
2
+ class Components < Megam::RestAdapter
3
+ def initialize(o)
4
+ @id = nil
5
+ @name = nil
6
+ @tosca_type = nil
7
+ @inputs = []
8
+ @outputs = []
9
+ @envs = []
10
+ @artifacts = {}
11
+ @artifact_type = nil
12
+ @content = nil
13
+ @artifact_requirements = []
14
+ @related_components = []
15
+ @operations = []
16
+ @status = nil
17
+ @state = nil
18
+ @repo = {}
19
+ @rtype = nil
20
+ @source = nil
21
+ @oneclick = nil
22
+ @branch = nil
23
+ @url = nil
24
+ @created_at = nil
25
+
26
+ super(o)
27
+ end
28
+
29
+ def components
30
+ self
31
+ end
32
+
33
+ def id(arg = nil)
34
+ if !arg.nil?
35
+ @id = arg
36
+ else
37
+ @id
38
+ end
39
+ end
40
+
41
+ def name(arg = nil)
42
+ if !arg.nil?
43
+ @name = arg
44
+ else
45
+ @name
46
+ end
47
+ end
48
+
49
+ def tosca_type(arg = nil)
50
+ if !arg.nil?
51
+ @tosca_type = arg
52
+ else
53
+ @tosca_type
54
+ end
55
+ end
56
+
57
+ def inputs(arg = [])
58
+ if arg != []
59
+ @inputs = arg
60
+ else
61
+ @inputs
62
+ end
63
+ end
64
+
65
+ def outputs(arg = [])
66
+ if arg != []
67
+ @outputs = arg
68
+ else
69
+ @outputs
70
+ end
71
+ end
72
+
73
+ def envs(arg = [])
74
+ if arg != []
75
+ @envs = arg
76
+ else
77
+ @envs
78
+ end
79
+ end
80
+
81
+ def artifacts(arg = nil)
82
+ if !arg.nil?
83
+ @artifacts = arg
84
+ else
85
+ @artifacts
86
+ end
87
+ end
88
+
89
+ def artifact_type(arg = nil)
90
+ if !arg.nil?
91
+ @artifact_type = arg
92
+ else
93
+ @artifact_type
94
+ end
95
+ end
96
+
97
+ def content(arg = nil)
98
+ if !arg.nil?
99
+ @content = arg
100
+ else
101
+ @content
102
+ end
103
+ end
104
+
105
+ def artifact_requirements(arg = [])
106
+ if arg != []
107
+ @artifact_requirements = arg
108
+ else
109
+ @artifact_requirements
110
+ end
111
+ end
112
+
113
+ def related_components(arg = [])
114
+ if arg != []
115
+ @related_components = arg
116
+ else
117
+ @related_components
118
+ end
119
+ end
120
+
121
+ def operations(arg = [])
122
+ if arg != []
123
+ @operations = arg
124
+ else
125
+ @operations
126
+ end
127
+ end
128
+
129
+ def status(arg = nil)
130
+ if !arg.nil?
131
+ @status = arg
132
+ else
133
+ @status
134
+ end
135
+ end
136
+
137
+ def state(arg = nil)
138
+ if !arg.nil?
139
+ @state = arg
140
+ else
141
+ @state
142
+ end
143
+ end
144
+
145
+ def repo(arg = nil)
146
+ if !arg.nil?
147
+ @repo = arg
148
+ else
149
+ @repo
150
+ end
151
+ end
152
+
153
+ def rtype(arg = nil)
154
+ if !arg.nil?
155
+ @rtype = arg
156
+ else
157
+ @rtype
158
+ end
159
+ end
160
+
161
+ def source(arg = nil)
162
+ if !arg.nil?
163
+ @source = arg
164
+ else
165
+ @source
166
+ end
167
+ end
168
+
169
+ def oneclick(arg = nil)
170
+ if !arg.nil?
171
+ @oneclick = arg
172
+ else
173
+ @oneclick
174
+ end
175
+ end
176
+
177
+ def branch(arg = nil)
178
+ if !arg.nil?
179
+ @branch = arg
180
+ else
181
+ @branch
182
+ end
183
+ end
184
+
185
+ def url(arg = nil)
186
+ if !arg.nil?
187
+ @url = arg
188
+ else
189
+ @url
190
+ end
191
+ end
192
+
193
+ def created_at(arg = nil)
194
+ if !arg.nil?
195
+ @created_at = arg
196
+ else
197
+ @created_at
198
+ end
199
+ end
200
+
201
+ def error?
202
+ crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
203
+ end
204
+
205
+ # Transform the ruby obj -> to a Hash
206
+ def to_hash
207
+ index_hash = {}
208
+ index_hash['json_claz'] = self.class.name
209
+ index_hash['id'] = id
210
+ index_hash['name'] = name
211
+ index_hash['tosca_type'] = tosca_type
212
+ index_hash['inputs'] = inputs
213
+ index_hash['outputs'] = outputs
214
+ index_hash['envs'] = envs
215
+ index_hash['artifacts'] = artifacts
216
+ index_hash['related_components'] = related_components
217
+ index_hash['operations'] = operations
218
+ index_hash['status'] = status
219
+ index_hash['state'] = state
220
+ index_hash['repo'] = repo
221
+ index_hash['created_at'] = created_at
222
+ index_hash
223
+ end
224
+
225
+ # Serialize this object as a hash: called from JsonCompat.
226
+ # Verify if this called from JsonCompat during testing.
227
+ def to_json(*a)
228
+ for_json.to_json(*a)
229
+ end
230
+
231
+ def for_json
232
+ result = {
233
+ 'id' => id,
234
+ 'name' => name,
235
+ 'tosca_type' => tosca_type,
236
+ 'inputs' => inputs,
237
+ 'outputs' => outputs,
238
+ 'envs' => envs,
239
+ 'artifacts' => artifacts,
240
+ 'related_components' => related_components,
241
+ 'operations' => operations,
242
+ 'status' => status,
243
+ 'state' => state,
244
+ 'repo' => repo,
245
+ 'created_at' => created_at
246
+ }
247
+ result
248
+ end
249
+
250
+ def self.json_create(o)
251
+ asm = new({})
252
+ asm.id(o['id']) if o.key?('id')
253
+ asm.name(o['name']) if o.key?('name')
254
+ asm.tosca_type(o['tosca_type']) if o.key?('tosca_type')
255
+ asm.inputs(o['inputs']) if o.key?('inputs')
256
+ asm.outputs(o['outputs']) if o.key?('outputs')
257
+ asm.envs(o['envs']) if o.key?('envs')
258
+ ar = o['artifacts']
259
+ asm.artifacts[:artifact_type] = ar['artifact_type'] if ar && ar.key?('artifact_type')
260
+ asm.artifacts[:content] = ar['content'] if ar && ar.key?('content')
261
+ asm.artifacts[:artifact_requirements] = ar['artifact_requirements'] if ar && ar.key?('artifact_requirements')
262
+
263
+ asm.related_components(o['related_components']) if o.key?('related_components')
264
+ asm.operations(o['operations']) if o.key?('operations')
265
+ asm.status(o['status']) if o.key?('status')
266
+ asm.state(o['state']) if o.key?('state')
267
+
268
+ ro = o['repo']
269
+ asm.repo[:rtype] = ro['rtype'] if ro && ro.key?('rtype')
270
+ asm.repo[:source] = ro['source'] if ro && ro.key?('source')
271
+ asm.repo[:oneclick] = ro['oneclick'] if ro && ro.key?('oneclick')
272
+ asm.repo[:branch] = ro['branch'] if ro && ro.key?('branch')
273
+ asm.repo[:url] = ro['url'] if ro && ro.key?('url')
274
+ asm.created_at(o['created_at']) if o.key?('created_at')
275
+ asm
276
+ end
277
+
278
+ def self.from_hash(o)
279
+ asm = new(o)
280
+ asm.from_hash(o)
281
+ asm
282
+ end
283
+
284
+ def from_hash(o)
285
+ @id = o['id'] if o.key?('id')
286
+ @name = o['name'] if o.key?('name')
287
+ @tosca_type = o['tosca_type'] if o.key?('tosca_type')
288
+ @inputs = o['inputs'] if o.key?('inputs')
289
+ @outputs = o['outputs'] if o.key?('outputs')
290
+ @envs = o['envs'] if o.key?('envs')
291
+ @artifacts = o['artifacts'] if o.key?('artifacts')
292
+ @related_components = o['related_components'] if o.key?('related_components')
293
+ @operations = o['operations'] if o.key?('operations')
294
+ @status = o['status'] if o.key?('status')
295
+ @state = o['state'] if o.key?('state')
296
+ @repo = o['repo'] if o.key?('repo')
297
+ @created_at = o['created_at'] if o.key?('created_at')
298
+ self
299
+ end
300
+
301
+ def self.create(params)
302
+ asm = from_hash(params)
303
+ asm.create
304
+ end
305
+
306
+ # Load a account by email_p
307
+ def self.show(params)
308
+ asm = new(params)
309
+ asm.megam_rest.get_components(params['id'])
310
+ end
311
+
312
+ def self.update(params)
313
+ asm = from_hash(params)
314
+ asm.update
315
+ end
316
+
317
+ # Create the node via the REST API
318
+ def update
319
+ megam_rest.update_component(to_hash)
320
+ end
321
+
322
+ def to_s
323
+ Megam::Stuff.styled_hash(to_hash)
324
+ end
325
+ end
326
+ end
@@ -0,0 +1,123 @@
1
+ module Megam
2
+ class ComponentsCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @components = Array.new
8
+ @components_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_components
13
+ @components
14
+ end
15
+
16
+ def [](index)
17
+ @components[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_components(arg)
22
+ @components[index] = arg
23
+ @components_by_name[arg.name] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_components(a)
29
+ @components << a
30
+ @components_by_name[a.name] = @components.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(components)
39
+ is_megam_components(components)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any nodes inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # node
44
+ @components.insert(@insert_after_idx + 1, components)
45
+ # update name -> location mappings and register new node
46
+ @components_by_name.each_key do |key|
47
+ @components_by_name[key] += 1 if @components_by_name[key] > @insert_after_idx
48
+ end
49
+ @components_by_name[components.name] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @components << components
53
+ @components_by_name[components.name] = @components.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @components.each do |components|
59
+ yield components
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @components.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @components.empty?
71
+ end
72
+
73
+ def lookup(components)
74
+ lookup_by = nil
75
+ if components.kind_of?(Megam::Components)
76
+ lookup_by = components.name
77
+ elsif components.kind_of?(String)
78
+ lookup_by = components
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::components or String to lookup"
81
+ end
82
+ res = @components_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @components[res]
87
+ end
88
+
89
+ def to_s
90
+ @components.join(", ")
91
+ end
92
+
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
96
+
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
100
+
101
+
102
+ def self.json_create(o)
103
+ collection = self.new()
104
+ o["results"].each do |components_list|
105
+ components_array = components_list.kind_of?(Array) ? components_list : [ components_list ]
106
+ components_array.each do |components|
107
+ collection.insert(components)
108
+
109
+ end
110
+ end
111
+ collection
112
+ end
113
+
114
+ private
115
+
116
+ def is_megam_components(arg)
117
+ unless arg.kind_of?(Megam::Components)
118
+ raise ArgumentError, "Members must be Megam::components"
119
+ end
120
+ true
121
+ end
122
+ end
123
+ end