Class: Megam::Boltdefns
- Inherits:
-
Object
- Object
- Megam::Boltdefns
- Defined in:
- lib/megam/core/boltdefns.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
- #boltdefns(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 ⇒ Boltdefns
constructor
def self.hash_tree Hash.new do |hash, key| hash = hash_tree end end.
- #megam_rest ⇒ Object
- #node ⇒ Object
- #node_id(arg = nil) ⇒ Object
- #node_name(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
176 177 178 179 |
# File 'lib/megam/core/boltdefns.rb', line 176 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
161 162 163 164 165 |
# File 'lib/megam/core/boltdefns.rb', line 161 def self.from_hash(o) node = self.new() node.from_hash(o) node 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":"" } }]
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/megam/core/boltdefns.rb', line 138 def self.json_create(o) node = new node.id(o["id"]) if o.has_key?("id") node.node_id(o["node_id"]) if o.has_key?("node_id") node.node_name(o["node_name"]) if o.has_key?("node_name") node.created_at(o["created_at"]) if o.has_key?("created_at") #APP DEFINITIONS op = o["boltdefns"] node.boltdefns[:username] = op["username"] if op && op.has_key?("username") node.boltdefns[:apikey] = op["apikey"] if op && op.has_key?("apikey") node.boltdefns[:store_name]= op["store_name"] if op && op.has_key?("store_name") node.boltdefns[:url] = op["url"] if op && op.has_key?("url") node.boltdefns[:prime] = op["prime"] if op && op.has_key?("prime") node.boltdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill") node.boltdefns[:metered] = op["metered"] if op && op.has_key?("metered") node.boltdefns[:logging]= op["logging"] if op && op.has_key?("logging") node.boltdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec") node end |
.show(node_name) ⇒ Object
Load a account by email_p
187 188 189 190 |
# File 'lib/megam/core/boltdefns.rb', line 187 def self.show(node_name) megam_rest.get_boltdefn(node_name) self end |
Instance Method Details
#boltdefns(arg = nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/megam/core/boltdefns.rb', line 69 def boltdefns(arg=nil) if arg != nil @boltdefns = arg else @boltdefns end end |
#create ⇒ Object
Create the node via the REST API
182 183 184 |
# File 'lib/megam/core/boltdefns.rb', line 182 def create megam_rest.post_boltdefn(to_hash) end |
#created_at(arg = nil) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/megam/core/boltdefns.rb', line 78 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
86 87 88 |
# File 'lib/megam/core/boltdefns.rb', line 86 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/megam/core/boltdefns.rb', line 108 def for_json result = { "id" => id, "node_id" => node_id, "node_name" => node_name, "boltdefns" => boltdefns, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/megam/core/boltdefns.rb', line 167 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") @boltdefns = o["boltdefns"] if o.has_key?("boltdefns") @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/boltdefns.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/boltdefns.rb', line 40 def megam_rest = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]} Megam::API.new() end |
#node ⇒ Object
36 37 38 |
# File 'lib/megam/core/boltdefns.rb', line 36 def node self end |
#node_id(arg = nil) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/megam/core/boltdefns.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/boltdefns.rb', line 61 def node_name(arg=nil) if arg != nil @node_name = arg else @node_name end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/megam/core/boltdefns.rb', line 91 def to_hash 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["boltdefns"] = boltdefns 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.
104 105 106 |
# File 'lib/megam/core/boltdefns.rb', line 104 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
192 193 194 195 |
# File 'lib/megam/core/boltdefns.rb', line 192 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |