Class: Megam::Assembly

Inherits:
RestAdapter
  • Object
show all
Defined in:
lib/megam/core/assembly.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(o) ⇒ Assembly

Returns a new instance of Assembly.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/megam/core/assembly.rb', line 3

def initialize(o)
    @id = nil
    @asms_id = nil
    @name = nil
    @components = []
    @tosca_type = nil
    @policies = []
    @inputs = []
    @outputs = []
    @status = nil
    @state = nil
    @created_at = nil

    super(o)
end

Class Method Details

.from_hash(o) ⇒ Object



172
173
174
175
176
# File 'lib/megam/core/assembly.rb', line 172

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

.json_create(o) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/megam/core/assembly.rb', line 156

def self.json_create(o)
    asm = new({})
    asm.id(o['id']) if o.key?('id')
    asm.asms_id(o["asms_id"]) if o.has_key?("asms_id")
    asm.name(o['name']) if o.key?('name')
    asm.components(o['components']) if o.key?('components')
    asm.tosca_type(o['tosca_type']) if o.key?('tosca_type')
    asm.policies(o['policies']) if o.key?('policies') # this will be an array? can hash store array?
    asm.inputs(o['inputs']) if o.key?('inputs')
    asm.outputs(o['outputs']) if o.key?('outputs')
    asm.status(o['status']) if o.key?('status')
    asm.state(o['state']) if o.key?('state')
    asm.created_at(o['created_at']) if o.key?('created_at')
    asm
end

.show(params) ⇒ Object



193
194
195
196
# File 'lib/megam/core/assembly.rb', line 193

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

.update(params) ⇒ Object



198
199
200
201
# File 'lib/megam/core/assembly.rb', line 198

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

.upgrade(params) ⇒ Object



203
204
205
206
# File 'lib/megam/core/assembly.rb', line 203

def self.upgrade(params)
    asm = from_hash(params)
    asm.megam_rest.upgrade_assembly(params['id'])
end

Instance Method Details

#asms_id(arg = nil) ⇒ Object



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

def asms_id(arg=nil)
    if arg != nil
        @asms_id = arg
    else
        @asms_id
    end
end

#assembly ⇒ Object



19
20
21
# File 'lib/megam/core/assembly.rb', line 19

def assembly
    self
end

#components(arg = []) ⇒ Object



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

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

#created_at(arg = nil) ⇒ Object



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

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

#error? ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/megam/core/assembly.rb', line 111

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

#for_json ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/megam/core/assembly.rb', line 139

def for_json
    result = {
        'id' => id,
        'name' => name,
        'components' => components,
        'tosca_type' => tosca_type,
        'policies' => policies,
        'inputs' => inputs,
        'outputs' => outputs,
        'status' => status,
        'state' => state,
        'created_at' => created_at
    }

    result
end

#from_hash(o) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/megam/core/assembly.rb', line 178

def from_hash(o)
    @id                = o['id'] if o.key?('id')
    @asms_id           = o["asms_id"] if o.has_key?("asms_id")
    @name              = o['name'] if o.key?('name')
    @components        = o['components'] if o.key?('components')
    @tosca_type        = o['tosca_type'] if o.key?('tosca_type')
    @policies          = o['policies'] if o.key?('policies')
    @inputs            = o['inputs'] if o.key?('inputs')
    @outputs           = o['outputs'] if o.key?('outputs')
    @status            = o['status'] if o.key?('status')
    @state            = o['state'] if o.key?('state')
    @created_at        = o['created_at'] if o.key?('created_at')
    self
end

#id(arg = nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/megam/core/assembly.rb', line 23

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

#inputs(arg = []) ⇒ Object



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

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

#name(arg = nil) ⇒ Object



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

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

#outputs(arg = []) ⇒ Object



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

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

#policies(arg = []) ⇒ Object



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

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

#state(arg = nil) ⇒ Object



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

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

#status(arg = nil) ⇒ Object



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

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

#to_hash ⇒ Object

Transform the ruby obj -> to a Hash



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/megam/core/assembly.rb', line 116

def to_hash
    index_hash = {}
    index_hash['json_claz'] = self.class.name
    index_hash['id'] = id
    index_hash["asms_id"] = asms_id
    index_hash['name'] = name
    index_hash['components'] = components
    index_hash['tosca_type'] = tosca_type
    index_hash['policies'] = policies
    index_hash['inputs'] = inputs
    index_hash['outputs'] = outputs
    index_hash['status'] = status
    index_hash['state'] = state
    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.



135
136
137
# File 'lib/megam/core/assembly.rb', line 135

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

#to_s ⇒ Object



213
214
215
# File 'lib/megam/core/assembly.rb', line 213

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

#tosca_type(arg = nil) ⇒ Object



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

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

#update ⇒ Object

Create the node via the REST API



209
210
211
# File 'lib/megam/core/assembly.rb', line 209

def update
    megam_rest.update_assembly(to_hash)
end