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
-
.show(id) ⇒ Object
Load a account by email_p.
-
.shown(node_name, id) ⇒ 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
Each notify entry is a resource/action pair, modeled as an Struct with a #resource and #action member.
- #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
#initialize ⇒ Appdefns
Each notify entry is a resource/action pair, modeled as an Struct with a #resource and #action member
21 22 23 24 25 26 27 28 |
# File 'lib/megam/core/appdefns.rb', line 21 def initialize @id = nil @node_id = nil @node_name = nil @appdefns ={} @created_at = nil @some_msg = {} end |
Class Method Details
.create(o) ⇒ Object
159 160 161 162 |
# File 'lib/megam/core/appdefns.rb', line 159 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
144 145 146 147 148 |
# File 'lib/megam/core/appdefns.rb', line 144 def self.from_hash(o) appdefns = self.new() appdefns.from_hash(o) appdefns end |
.json_create(o) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/megam/core/appdefns.rb', line 122 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(id) ⇒ Object
Load a account by email_p
170 171 172 173 |
# File 'lib/megam/core/appdefns.rb', line 170 def self.show(id) appdefns = self.new() appdefns.megam_rest.get_appdefn(id) end |
.shown(node_name, id) ⇒ Object
Load a account by email_p
176 177 178 179 |
# File 'lib/megam/core/appdefns.rb', line 176 def self.shown(node_name, id) appdefns = self.new() appdefns.megam_rest.get_appdefn(node_name,id) end |
Instance Method Details
#appdefns(arg = nil) ⇒ Object
30 31 32 |
# File 'lib/megam/core/appdefns.rb', line 30 def appdefns self end |
#create ⇒ Object
Create the node via the REST API
165 166 167 |
# File 'lib/megam/core/appdefns.rb', line 165 def create megam_rest.post_appdefn(to_hash) end |
#created_at(arg = nil) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/megam/core/appdefns.rb', line 71 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
87 88 89 |
# File 'lib/megam/core/appdefns.rb', line 87 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/megam/core/appdefns.rb', line 110 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
150 151 152 153 154 155 156 157 |
# File 'lib/megam/core/appdefns.rb', line 150 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
39 40 41 42 43 44 45 |
# File 'lib/megam/core/appdefns.rb', line 39 def id(arg=nil) if arg != nil @id = arg else @id end end |
#megam_rest ⇒ Object
34 35 36 37 |
# File 'lib/megam/core/appdefns.rb', line 34 def megam_rest = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]} Megam::API.new() end |
#node_id(arg = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/megam/core/appdefns.rb', line 47 def node_id(arg=nil) if arg != nil @node_id = arg else @node_id end end |
#node_name(arg = nil) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/megam/core/appdefns.rb', line 55 def node_name(arg=nil) if arg != nil @node_name = arg else @node_name end end |
#some_msg(arg = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/megam/core/appdefns.rb', line 79 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
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/megam/core/appdefns.rb', line 92 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["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.
106 107 108 |
# File 'lib/megam/core/appdefns.rb', line 106 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
181 182 183 |
# File 'lib/megam/core/appdefns.rb', line 181 def to_s Megam::Stuff.styled_hash(to_hash) end |