Class: Megam::Components

Inherits:
RestAdapter show all
Defined in:
lib/megam/core/components.rb

Instance Attribute Summary

Attributes inherited from RestAdapter

#api_key, #email, #headers, #host, #master_key, #org_id, #password_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ Components

Returns a new instance of Components.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/megam/core/components.rb', line 3

def initialize(o)
    @id = nil
    @name = nil
    @tosca_type = nil
    @inputs = []
    @outputs = []
    @envs = []
    @artifacts = {}
    @artifact_type = nil
    @content = nil
    @artifact_requirements = []
    @related_components = []
    @operations = []
    @status = nil
    @state = nil
    @repo = {}
    @rtype = nil
    @source = nil
    @oneclick = nil
    @url = nil
    @created_at = nil

    super(o)
end

Class Method Details

.create(params) ⇒ Object



291
292
293
294
# File 'lib/megam/core/components.rb', line 291

def self.create(params)
    asm = from_hash(params)
    asm.create
end

.from_hash(o) ⇒ Object



268
269
270
271
272
# File 'lib/megam/core/components.rb', line 268

def self.from_hash(o)
    asm = new(o)
    asm.from_hash(o)
    asm
end

.json_create(o) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/megam/core/components.rb', line 241

def self.json_create(o)
    asm = new({})
    asm.id(o['id']) if o.key?('id')
    asm.name(o['name']) if o.key?('name')
    asm.tosca_type(o['tosca_type']) if o.key?('tosca_type')
    asm.inputs(o['inputs']) if o.key?('inputs')
    asm.outputs(o['outputs']) if o.key?('outputs')
    asm.envs(o['envs']) if o.key?('envs')
    ar = o['artifacts']
    asm.artifacts[:artifact_type] = ar['artifact_type'] if ar && ar.key?('artifact_type')
    asm.artifacts[:content] = ar['content'] if ar && ar.key?('content')
    asm.artifacts[:artifact_requirements] = ar['artifact_requirements'] if ar && ar.key?('artifact_requirements')

    asm.related_components(o['related_components']) if o.key?('related_components')
    asm.operations(o['operations']) if o.key?('operations')
    asm.status(o['status']) if o.key?('status')
    asm.state(o['state']) if o.key?('state')

    ro = o['repo']
    asm.repo[:rtype] = ro['rtype'] if ro && ro.key?('rtype')
    asm.repo[:source] = ro['source'] if ro && ro.key?('source')
    asm.repo[:oneclick] = ro['oneclick'] if ro && ro.key?('oneclick')
    asm.repo[:url] = ro['url'] if ro && ro.key?('url')
    asm.created_at(o['created_at']) if o.key?('created_at')
    asm
end

.show(params) ⇒ Object

Load a account by email_p



297
298
299
300
# File 'lib/megam/core/components.rb', line 297

def self.show(params)
    asm = new(params)
    asm.megam_rest.get_components(params['id'])
end

.update(params) ⇒ Object



302
303
304
305
# File 'lib/megam/core/components.rb', line 302

def self.update(params)
    asm = from_hash(params)
    asm.update
end

Instance Method Details

#artifact_requirements(arg = []) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/megam/core/components.rb', line 104

def artifact_requirements(arg = [])
    if arg != []
        @artifact_requirements = arg
    else
        @artifact_requirements
    end
end

#artifact_type(arg = nil) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/megam/core/components.rb', line 88

def artifact_type(arg = nil)
    if !arg.nil?
        @artifact_type = arg
    else
        @artifact_type
    end
end

#artifacts(arg = nil) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/megam/core/components.rb', line 80

def artifacts(arg = nil)
    if !arg.nil?
        @artifacts = arg
    else
        @artifacts
    end
end

#componentsObject



28
29
30
# File 'lib/megam/core/components.rb', line 28

def components
    self
end

#content(arg = nil) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/megam/core/components.rb', line 96

def content(arg = nil)
    if !arg.nil?
        @content = arg
    else
        @content
    end
end

#created_at(arg = nil) ⇒ Object



184
185
186
187
188
189
190
# File 'lib/megam/core/components.rb', line 184

def created_at(arg = nil)
    if !arg.nil?
        @created_at = arg
    else
        @created_at
    end
end

#envs(arg = []) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/megam/core/components.rb', line 72

def envs(arg = [])
    if arg != []
        @envs = arg
    else
        @envs
    end
end

#error?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/megam/core/components.rb', line 192

def error?
    crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
end

#for_jsonObject



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/megam/core/components.rb', line 222

def for_json
    result = {
        'id' => id,
        'name' => name,
        'tosca_type' => tosca_type,
        'inputs' => inputs,
        'outputs' => outputs,
        'envs' => envs,
        'artifacts' => artifacts,
        'related_components' => related_components,
        'operations' => operations,
        'status' => status,
        'state' => state,
        'repo' => repo,
        'created_at' => created_at
    }
    result
end

#from_hash(o) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/megam/core/components.rb', line 274

def from_hash(o)
    @id                              = o['id'] if o.key?('id')
    @name                            = o['name'] if o.key?('name')
    @tosca_type                      = o['tosca_type'] if o.key?('tosca_type')
    @inputs                          = o['inputs'] if o.key?('inputs')
    @outputs                         = o['outputs'] if o.key?('outputs')
    @envs                            = o['envs'] if o.key?('envs')
    @artifacts                       = o['artifacts'] if o.key?('artifacts')
    @related_components              = o['related_components'] if o.key?('related_components')
    @operations                      = o['operations'] if o.key?('operations')
    @status                          = o['status'] if o.key?('status')
    @state                          = o['state'] if o.key?('state')
    @repo                            = o['repo'] if o.key?('repo')
    @created_at                      = o['created_at'] if o.key?('created_at')
    self
end

#id(arg = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/megam/core/components.rb', line 32

def id(arg = nil)
    if !arg.nil?
        @id = arg
    else
        @id
    end
end

#inputs(arg = []) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/megam/core/components.rb', line 56

def inputs(arg = [])
    if arg != []
        @inputs = arg
    else
        @inputs
    end
end

#name(arg = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/megam/core/components.rb', line 40

def name(arg = nil)
    if !arg.nil?
        @name = arg
    else
        @name
    end
end

#oneclick(arg = nil) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/megam/core/components.rb', line 168

def oneclick(arg = nil)
    if !arg.nil?
        @oneclick = arg
    else
        @oneclick
    end
end

#operations(arg = []) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/megam/core/components.rb', line 120

def operations(arg = [])
    if arg != []
        @operations = arg
    else
        @operations
    end
end

#outputs(arg = []) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/megam/core/components.rb', line 64

def outputs(arg = [])
    if arg != []
        @outputs = arg
    else
        @outputs
    end
end


112
113
114
115
116
117
118
# File 'lib/megam/core/components.rb', line 112

def related_components(arg = [])
    if arg != []
        @related_components = arg
    else
        @related_components
    end
end

#repo(arg = nil) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/megam/core/components.rb', line 144

def repo(arg = nil)
    if !arg.nil?
        @repo = arg
    else
        @repo
    end
end

#rtype(arg = nil) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/megam/core/components.rb', line 152

def rtype(arg = nil)
    if !arg.nil?
        @rtype = arg
    else
        @rtype
    end
end

#source(arg = nil) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/megam/core/components.rb', line 160

def source(arg = nil)
    if !arg.nil?
        @source = arg
    else
        @source
    end
end

#state(arg = nil) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/megam/core/components.rb', line 136

def state(arg = nil)
    if !arg.nil?
        @state = arg
    else
        @state
    end
end

#status(arg = nil) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/megam/core/components.rb', line 128

def status(arg = nil)
    if !arg.nil?
        @status = arg
    else
        @status
    end
end

#to_hashObject

Transform the ruby obj -> to a Hash



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/megam/core/components.rb', line 197

def to_hash
    index_hash = {}
    index_hash['json_claz'] = self.class.name
    index_hash['id'] = id
    index_hash['name'] = name
    index_hash['tosca_type'] = tosca_type
    index_hash['inputs'] = inputs
    index_hash['outputs'] = outputs
    index_hash['envs'] = envs
    index_hash['artifacts'] = artifacts
    index_hash['related_components'] = related_components
    index_hash['operations'] = operations
    index_hash['status'] = status
    index_hash['state'] = state
    index_hash['repo'] = repo
    index_hash['created_at'] = created_at
    index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



218
219
220
# File 'lib/megam/core/components.rb', line 218

def to_json(*a)
    for_json.to_json(*a)
end

#to_sObject



312
313
314
# File 'lib/megam/core/components.rb', line 312

def to_s
    Megam::Stuff.styled_hash(to_hash)
end

#tosca_type(arg = nil) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/megam/core/components.rb', line 48

def tosca_type(arg = nil)
    if !arg.nil?
        @tosca_type = arg
    else
        @tosca_type
    end
end

#updateObject

Create the node via the REST API



308
309
310
# File 'lib/megam/core/components.rb', line 308

def update
    megam_rest.update_component(to_hash)
end

#url(arg = nil) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/megam/core/components.rb', line 176

def url(arg = nil)
    if !arg.nil?
        @url = arg
    else
        @url
    end
end