Class: Megam::Boltdefns

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/core/boltdefns.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBoltdefns

def self.hash_tree Hash.new do |hash, key| hash = hash_tree end end



28
29
30
31
32
33
34
35
# File 'lib/megam/core/boltdefns.rb', line 28

def initialize
  @id = nil
  @node_id = nil
  @node_name = nil
  @boltdefns ={}
  @created_at = nil
  @some_msg = {}
end

Class Method Details

.create(o) ⇒ Object



190
191
192
193
# File 'lib/megam/core/boltdefns.rb', line 190

def self.create(o)
  acct = from_hash(o)
  acct.create
end

.from_hash(o) ⇒ Object



175
176
177
178
179
# File 'lib/megam/core/boltdefns.rb', line 175

def self.from_hash(o)
  boltdefns = self.new()
  boltdefns.from_hash(o)
  boltdefns
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”:“” } }]



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/megam/core/boltdefns.rb', line 147

def self.json_create(o)
  boltdefns = new
  boltdefns.id(o["id"]) if o.has_key?("id")
  boltdefns.node_id(o["node_id"]) if o.has_key?("node_id")
  boltdefns.node_name(o["node_name"]) if o.has_key?("node_name")
  boltdefns.created_at(o["created_at"]) if o.has_key?("created_at")

  #APP DEFINITIONS
  op = o["boltdefns"]
  boltdefns.boltdefns[:username] = op["username"] if op && op.has_key?("username")
  boltdefns.boltdefns[:apikey] = op["apikey"] if op && op.has_key?("apikey")
  boltdefns.boltdefns[:store_name]= op["store_name"] if op && op.has_key?("store_name")
  boltdefns.boltdefns[:url] = op["url"] if op && op.has_key?("url")
  boltdefns.boltdefns[:prime] = op["prime"] if op && op.has_key?("prime")

  boltdefns.boltdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
  boltdefns.boltdefns[:metered] = op["metered"] if op && op.has_key?("metered")
  boltdefns.boltdefns[:logging]= op["logging"] if op && op.has_key?("logging")
  boltdefns.boltdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")

  boltdefns.some_msg[:code] = o["code"] if o.has_key?("code")
  boltdefns.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  boltdefns.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  boltdefns.some_msg[:links] = o["links"] if o.has_key?("links")

  boltdefns
end

.show(node_name) ⇒ Object

Show all bolt defns by [node_name]/email



201
202
203
204
# File 'lib/megam/core/boltdefns.rb', line 201

def self.show(node_name)
  boltdefns = self.new()
  boltdefns.megam_rest.get_boltdefn(node_name)
end

.shown(node_name, id) ⇒ Object

Show a bolt defn by [node_name, defn id] for an email



207
208
209
210
# File 'lib/megam/core/boltdefns.rb', line 207

def self.shown(node_name,id)
  boltdefns = self.new()
  boltdefns.megam_rest.get_boltdefn(node_name,id)
end

Instance Method Details

#boltdefns(arg = nil) ⇒ Object



37
38
39
# File 'lib/megam/core/boltdefns.rb', line 37

def boltdefns
  self
end

#createObject

Create the node via the REST API



196
197
198
# File 'lib/megam/core/boltdefns.rb', line 196

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

Returns:

  • (Boolean)


94
95
96
# File 'lib/megam/core/boltdefns.rb', line 94

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/megam/core/boltdefns.rb', line 117

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



181
182
183
184
185
186
187
188
# File 'lib/megam/core/boltdefns.rb', line 181

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



46
47
48
49
50
51
52
# File 'lib/megam/core/boltdefns.rb', line 46

def id(arg=nil)
  if arg != nil
    @id = arg
  else
  @id
  end
end

#megam_restObject



41
42
43
44
# File 'lib/megam/core/boltdefns.rb', line 41

def megam_rest
  options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
  Megam::API.new(options)
end

#node_id(arg = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/megam/core/boltdefns.rb', line 54

def node_id(arg=nil)
  if arg != nil
    @node_id = arg
  else
  @node_id
  end
end

#node_name(arg = nil) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/megam/core/boltdefns.rb', line 62

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/boltdefns.rb', line 86

def some_msg(arg=nil)
  if arg != nil
    @some_msg = arg
  else
  @some_msg
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/megam/core/boltdefns.rb', line 99

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["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.



113
114
115
# File 'lib/megam/core/boltdefns.rb', line 113

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



212
213
214
# File 'lib/megam/core/boltdefns.rb', line 212

def to_s
  Megam::Stuff.styled_hash(to_hash)
end