Class: Megam::Boltreqs
- Inherits:
-
Object
- Object
- Megam::Boltreqs
- Defined in:
- lib/megam/core/boltreqs.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_id(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 ⇒ Boltreqs
constructor
def self.hash_tree Hash.new do |hash, key| hash = hash_tree end end.
- #lc_additional(arg = nil) ⇒ Object
- #lc_apply(arg = nil) ⇒ Object
- #lc_when(arg = nil) ⇒ Object
- #megam_rest ⇒ Object
- #node ⇒ Object
- #node_name(arg = nil) ⇒ Object
- #req_type(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
#initialize ⇒ Boltreqs
def self.hash_tree Hash.new do |hash, key| hash = hash_tree end end
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/megam/core/boltreqs.rb', line 28 def initialize @id = nil @req_type = nil @boltdefns_id = nil @node_name = nil @lc_apply = nil @lc_additional = nil @lc_when = nil @created_at = nil end |
Class Method Details
.create(o) ⇒ Object
202 203 204 205 |
# File 'lib/megam/core/boltreqs.rb', line 202 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
184 185 186 187 188 |
# File 'lib/megam/core/boltreqs.rb', line 184 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":"" } }]
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/megam/core/boltreqs.rb', line 170 def self.json_create(o) node = new node.id(o["id"]) if o.has_key?("id") node.req_type(o["req_type"]) if o.has_key?("req_type") node.boltdefns_id(o["boltdefns_id"]) if o.has_key?("boltdefns_id") node.node_name(o["node_name"]) if o.has_key?("node_name") node.lc_apply(o["lc_apply"]) if o.has_key?("lc_apply") node.lc_additional(o["lc_additional"]) if o.has_key?("lc_additional") node.lc_when(o["lc_when"]) if o.has_key?("lc_when") node.created_at(o["created_at"]) if o.has_key?("created_at") node end |
.show(node_name) ⇒ Object
Load a account by email_p
213 214 215 216 |
# File 'lib/megam/core/boltreqs.rb', line 213 def self.show(node_name) megam_rest.get_node(node_name) self end |
Instance Method Details
#boltdefns_id(arg = nil) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/megam/core/boltreqs.rb', line 63 def boltdefns_id(arg=nil) if arg != nil @boltdefns_id = arg else @boltdefns_id end end |
#create ⇒ Object
Create the node via the REST API
208 209 210 |
# File 'lib/megam/core/boltreqs.rb', line 208 def create megam_rest.post_node(to_hash) end |
#created_at(arg = nil) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/megam/core/boltreqs.rb', line 103 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
111 112 113 |
# File 'lib/megam/core/boltreqs.rb', line 111 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/megam/core/boltreqs.rb', line 136 def for_json result = { "id" => id, "req_type" => req_type, "boltdefns_id" => boltdefns_id, "node_name" => node_name, "lc_apply" => lc_apply, "lc_additional" => lc_additional, "lc_when" => lc_when, "created_at" => created_at } result end |
#from_hash(o) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/megam/core/boltreqs.rb', line 190 def from_hash(o) @id = o["id"] if o.has_key?("id") @req_type = o["req_type"] if o.has_key?("req_type") @boltdefns_id = o["boltdefns_id"] if o.has_key?("boltdefns_id") @node_name = o["node_name"] if o.has_key?("node_name") @lc_apply = o["lc_apply"] if o.has_key?("lc_apply") @lc_additional = o["lc_additional"] if o.has_key?("lc_additional") @lc_when = o["lc_when"] if o.has_key?("lc_when") @created_at = o["created_at"] if o.has_key?("created_at") self end |
#id(arg = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/megam/core/boltreqs.rb', line 47 def id(arg=nil) if arg != nil @id = arg else @id end end |
#lc_additional(arg = nil) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/megam/core/boltreqs.rb', line 87 def lc_additional(arg=nil) if arg != nil @lc_additional = arg else @lc_additional end end |
#lc_apply(arg = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/megam/core/boltreqs.rb', line 79 def lc_apply(arg=nil) if arg != nil @lc_apply = arg else @lc_apply end end |
#lc_when(arg = nil) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/megam/core/boltreqs.rb', line 95 def lc_when(arg=nil) if arg != nil @lc_when = arg else @lc_when end end |
#megam_rest ⇒ Object
42 43 44 45 |
# File 'lib/megam/core/boltreqs.rb', line 42 def megam_rest = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]} Megam::API.new() end |
#node ⇒ Object
38 39 40 |
# File 'lib/megam/core/boltreqs.rb', line 38 def node self end |
#node_name(arg = nil) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/megam/core/boltreqs.rb', line 71 def node_name(arg=nil) if arg != nil @node_name = arg else @node_name end end |
#req_type(arg = nil) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/megam/core/boltreqs.rb', line 55 def req_type(arg=nil) if arg != nil @req_type = arg else @req_type 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 |
# File 'lib/megam/core/boltreqs.rb', line 116 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["id"] = id index_hash["req_type"] = req_type index_hash["boltdefns_id"] = boltdefns_id index_hash["node_name"] = node_name index_hash["lc_apply"] = lc_apply index_hash["lc_additional"] = lc_additional index_hash["lc_when"] = lc_when 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.
132 133 134 |
# File 'lib/megam/core/boltreqs.rb', line 132 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
218 219 220 221 |
# File 'lib/megam/core/boltreqs.rb', line 218 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |