Class: Megam::Appdefns
- Inherits:
-
Object
- Object
- Megam::Appdefns
- Defined in:
- lib/megam/core/appdefns.rb
Class Method Summary collapse
- .create(o) ⇒ Object
- .from_hash(o) ⇒ Object
-
.json_create(o) ⇒ Object
Create a Megam::Node from NodeResult-JSON.
-
.show(node_name) ⇒ Object
Load a account by email_p.
Instance Method Summary collapse
- #appdefns(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the node via the REST API.
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize ⇒ Appdefns
constructor
def self.hash_tree Hash.new do |hash, key| hash = hash_tree end end.
- #megam_rest ⇒ Object
- #node_id(arg = nil) ⇒ Object
- #node_name(arg = nil) ⇒ Object
- #some_msg(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
Constructor Details
Class Method Details
.create(o) ⇒ Object
186 187 188 189 |
# File 'lib/megam/core/appdefns.rb', line 186 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
171 172 173 174 175 |
# File 'lib/megam/core/appdefns.rb', line 171 def self.from_hash(o) appdefns = self.new() appdefns.from_hash(o) appdefns end |
.json_create(o) ⇒ Object
Create a Megam::Node from NodeResult-JSON
[{ "id":"NOD362212018897289216", "accounts_id":"ACT362211962353876992", "json_claz":"Megam::Node", "request":{ "req_id":"NOD362212018897289216", "command":"commands" }, "predefs":{ "name":"", "scm":"", "war":"", "db":"", "queue":"" } }]
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/megam/core/appdefns.rb', line 149 def self.json_create(o) appdefns = new appdefns.id(o["id"]) if o.has_key?("id") appdefns.node_id(o["node_id"]) if o.has_key?("node_id") appdefns.node_name(o["node_name"]) if o.has_key?("node_name") appdefns.created_at(o["created_at"]) if o.has_key?("created_at") #APP DEFINITIONS op = o["appdefns"] appdefns.appdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill") appdefns.appdefns[:metered] = op["metered"] if op && op.has_key?("metered") appdefns.appdefns[:logging]= op["logging"] if op && op.has_key?("logging") appdefns.appdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec") appdefns.some_msg[:code] = o["code"] if o.has_key?("code") appdefns.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type") appdefns.some_msg[:msg]= o["msg"] if o.has_key?("msg") appdefns.some_msg[:links] = o["links"] if o.has_key?("links") appdefns end |
.show(node_name) ⇒ Object
Load a account by email_p
197 198 199 200 |
# File 'lib/megam/core/appdefns.rb', line 197 def self.show(node_name) appdefns = self.new() appdefns.megam_rest.get_appdefn(node_name) end |
Instance Method Details
#appdefns(arg = nil) ⇒ Object
36 37 38 |
# File 'lib/megam/core/appdefns.rb', line 36 def appdefns self end |
#create ⇒ Object
Create the node via the REST API
192 193 194 |
# File 'lib/megam/core/appdefns.rb', line 192 def create megam_rest.post_appdefn(to_hash) end |
#created_at(arg = nil) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/megam/core/appdefns.rb', line 78 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
94 95 96 |
# File 'lib/megam/core/appdefns.rb', line 94 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/megam/core/appdefns.rb', line 119 def for_json result = { "id" => id, "node_id" => node_id, "node_name" => node_name, "appdefns" => appdefns, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/megam/core/appdefns.rb', line 177 def from_hash(o) @id = o["id"] if o.has_key?("id") @node_id = o["node_id"] if o.has_key?("node_id") @node_name = o["node_name"] if o.has_key?("node_name") @appdefns = o["appdefns"] if o.has_key?("appdefns") @created_at = o["created_at"] if o.has_key?("created_at") self end |
#id(arg = nil) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/megam/core/appdefns.rb', line 45 def id(arg=nil) if arg != nil @id = arg else @id end end |
#megam_rest ⇒ Object
40 41 42 43 |
# File 'lib/megam/core/appdefns.rb', line 40 def megam_rest = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]} Megam::API.new() end |
#node_id(arg = nil) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/megam/core/appdefns.rb', line 53 def node_id(arg=nil) if arg != nil @node_id = arg else @node_id end end |
#node_name(arg = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/megam/core/appdefns.rb', line 61 def node_name(arg=nil) if arg != nil @node_name = arg else @node_name end end |
#some_msg(arg = nil) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/megam/core/appdefns.rb', line 86 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/megam/core/appdefns.rb', line 99 def to_hash puts "===================> CLASS NAME =====================================" puts self.class.name index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["node_id"] = node_id index_hash["node_name"] = node_name index_hash["appdefns"] = appdefns index_hash["created_at"] = created_at index_hash["some_msg"] = some_msg index_hash end |
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
115 116 117 |
# File 'lib/megam/core/appdefns.rb', line 115 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
202 203 204 205 |
# File 'lib/megam/core/appdefns.rb', line 202 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |