Class: Megam::Components
- Defined in:
- lib/megam/core/components.rb
Instance Attribute Summary
Attributes inherited from ServerAPI
Class Method Summary collapse
- .create(params) ⇒ Object
- .from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
- .json_create(o) ⇒ Object
-
.show(params) ⇒ Object
Load a account by email_p.
- .update(params) ⇒ Object
Instance Method Summary collapse
- #artifact_requirements(arg = []) ⇒ Object
- #artifact_type(arg = nil) ⇒ Object
- #artifacts(arg = nil) ⇒ Object
- #components ⇒ Object
- #content(arg = nil) ⇒ Object
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(email = nil, api_key = nil) ⇒ Components
constructor
A new instance of Components.
- #inputs(arg = []) ⇒ Object
- #name(arg = nil) ⇒ Object
- #operations(arg = []) ⇒ Object
- #outputs(arg = []) ⇒ Object
- #related_components(arg = nil) ⇒ Object
- #status(arg = nil) ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
- #tosca_type(arg = nil) ⇒ Object
-
#update ⇒ Object
Create the node via the REST API.
Methods inherited from ServerAPI
Constructor Details
#initialize(email = nil, api_key = nil) ⇒ Components
Returns a new instance of Components.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/megam/core/components.rb', line 19 def initialize(email=nil, api_key=nil) @id = nil @name =nil @tosca_type = nil @inputs = [] @outputs = [] @artifacts = {} @artifact_type = nil @content = nil @artifact_requirements = [] @related_components = nil @operations = [] @status = nil @created_at = nil super(email, api_key) end |
Class Method Details
.create(params) ⇒ Object
228 229 230 231 |
# File 'lib/megam/core/components.rb', line 228 def self.create(params) asm = from_hash(params, params["email"], params["api_key"]) asm.create end |
.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object
208 209 210 211 212 |
# File 'lib/megam/core/components.rb', line 208 def self.from_hash(o,tmp_email=nil, tmp_api_key=nil) asm = self.new(tmp_email, tmp_api_key) asm.from_hash(o) asm end |
.json_create(o) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/megam/core/components.rb', line 188 def self.json_create(o) asm = new asm.id(o["id"]) if o.has_key?("id") asm.name(o["name"]) if o.has_key?("name") asm.tosca_type(o["tosca_type"]) if o.has_key?("tosca_type") asm.inputs(o["inputs"]) if o.has_key?("inputs") asm.outputs(o["outputs"]) if o.has_key?("outputs") ar = o["artifacts"] asm.artifacts[:artifact_type] = ar["artifact_type"] if ar && ar.has_key?("artifact_type") asm.artifacts[:content] = ar["content"] if ar && ar.has_key?("content") asm.artifacts[:artifact_requirements] = ar["artifact_requirements"] if ar && ar.has_key?("artifact_requirements") asm.(o["related_components"]) if o.has_key?("related_components") asm.operations(o["operations"]) if o.has_key?("operations") asm.status(o["status"]) if o.has_key?("status") asm.created_at(o["created_at"]) if o.has_key?("created_at") asm end |
.show(params) ⇒ Object
Load a account by email_p
234 235 236 237 |
# File 'lib/megam/core/components.rb', line 234 def self.show(params) asm = self.new(params["email"], params["api_key"]) asm.megam_rest.get_components(params["id"]) end |
.update(params) ⇒ Object
239 240 241 242 |
# File 'lib/megam/core/components.rb', line 239 def self.update(params) asm = from_hash(params, params["email"], params["api_key"]) asm.update end |
Instance Method Details
#artifact_requirements(arg = []) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/megam/core/components.rb', line 105 def artifact_requirements(arg=[]) if arg != [] @artifact_requirements = arg else @artifact_requirements end end |
#artifact_type(arg = nil) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/megam/core/components.rb', line 89 def artifact_type(arg=nil) if arg != nil @artifact_type = arg else @artifact_type end end |
#artifacts(arg = nil) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/megam/core/components.rb', line 81 def artifacts(arg=nil) if arg != nil @artifacts = arg else @artifacts end end |
#components ⇒ Object
37 38 39 |
# File 'lib/megam/core/components.rb', line 37 def components self end |
#content(arg = nil) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/megam/core/components.rb', line 97 def content(arg=nil) if arg != nil @content = arg else @content end end |
#created_at(arg = nil) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/megam/core/components.rb', line 137 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
145 146 147 |
# File 'lib/megam/core/components.rb', line 145 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/megam/core/components.rb', line 172 def for_json result = { "id" => id, "name" => name, "tosca_type" => tosca_type, "inputs" => inputs, "outputs" => outputs, "artifacts" => artifacts, "related_components" => , "operations" => operations, "status" => status, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/megam/core/components.rb', line 214 def from_hash(o) @id = o["id"] if o.has_key?("id") @name = o["name"] if o.has_key?("name") @tosca_type = o["tosca_type"] if o.has_key?("tosca_type") @inputs = o["inputs"] if o.has_key?("inputs") @outputs = o["outputs"] if o.has_key?("outputs") @artifacts = o["artifacts"] if o.has_key?("artifacts") @related_components = o["related_components"] if o.has_key?("related_components") @operations = o["operations"] if o.has_key?("operations") @status = o["status"] if o.has_key?("status") @created_at = o["created_at"] if o.has_key?("created_at") self end |
#id(arg = nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/megam/core/components.rb', line 41 def id(arg=nil) if arg != nil @id = arg else @id end end |
#inputs(arg = []) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/megam/core/components.rb', line 65 def inputs(arg=[]) if arg != [] @inputs = arg else @inputs end end |
#name(arg = nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/megam/core/components.rb', line 49 def name(arg=nil) if arg != nil @name = arg else @name end end |
#operations(arg = []) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/megam/core/components.rb', line 121 def operations(arg=[]) if arg != [] @operations = arg else @operations end end |
#outputs(arg = []) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/megam/core/components.rb', line 73 def outputs(arg=[]) if arg != [] @outputs = arg else @outputs end end |
#related_components(arg = nil) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/megam/core/components.rb', line 113 def (arg=nil) if arg != nil @related_components = arg else @related_components end end |
#status(arg = nil) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/megam/core/components.rb', line 129 def status(arg=nil) if arg != nil @status = arg else @status end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/megam/core/components.rb', line 150 def to_hash index_hash = Hash.new 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["artifacts"] = artifacts index_hash["related_components"] = index_hash["operations"] = operations index_hash["status"] = status 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.
168 169 170 |
# File 'lib/megam/core/components.rb', line 168 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
249 250 251 |
# File 'lib/megam/core/components.rb', line 249 def to_s Megam::Stuff.styled_hash(to_hash) end |
#tosca_type(arg = nil) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/megam/core/components.rb', line 57 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
245 246 247 |
# File 'lib/megam/core/components.rb', line 245 def update megam_rest.update_component(to_hash) end |