Class: Megam::CloudTool

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/cloudtool.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ CloudTool

Returns a new instance of CloudTool.



19
20
21
22
23
24
25
26
# File 'lib/megam/core/cloudtool.rb', line 19

def initialize(email=nil, api_key=nil)
  @id = nil
  @name = nil
  @cli = nil
  @cloudtemplates = nil
  @some_msg = {}
  super(email, api_key)
end

Class Method Details

.from_hash(o) ⇒ Object



121
122
123
124
125
# File 'lib/megam/core/cloudtool.rb', line 121

def self.from_hash(o)
  cloudtool = self.new()
  cloudtool.from_hash(o)
  cloudtool
end

.json_create(o) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/megam/core/cloudtool.rb', line 106

def self.json_create(o)
  cloudtool = new
  cloudtool.id(o["id"]) if o.has_key?("id")
  cloudtool.name(o["name"]) if o.has_key?("name")
  cloudtool.cli(o["cli"]) if o.has_key?("cli")
  cloudtool.cloudtemplates(o["cloudtemplates"]) if o.has_key?("cloudtemplates")
  
  #success or error
  cloudtool.some_msg[:code] = o["code"] if o.has_key?("code")
  cloudtool.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  cloudtool.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  cloudtool.some_msg[:links] = o["links"] if o.has_key?("links")
  cloudtool
end

.list(tmp_email = nil, tmp_api_key = nil) ⇒ Object

Load all cloudtools - returns a CloudToolsCollection



134
135
136
137
# File 'lib/megam/core/cloudtool.rb', line 134

def self.list(tmp_email=nil, tmp_api_key=nil)
  ct = self.new(tmp_email, tmp_api_key)
  ct.megam_rest.get_cloudtools
end

.show(p_name, tmp_email = nil, tmp_api_key = nil) ⇒ Object

Show a particular cloudtool by name, Megam::CloudTool



141
142
143
144
145
# File 'lib/megam/core/cloudtool.rb', line 141

def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
  ct = self.new(tmp_email, tmp_api_key)
  ct.megam_rest.get_cloudtool(p_name)
  self
end

Instance Method Details

#cli(arg = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/megam/core/cloudtool.rb', line 41

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

#cloud_toolObject



28
29
30
# File 'lib/megam/core/cloudtool.rb', line 28

def cloud_tool
  self
end

#cloudtemplates(arg = nil) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/megam/core/cloudtool.rb', line 57

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

#error?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/megam/core/cloudtool.rb', line 73

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

#for_jsonObject



95
96
97
98
99
100
101
102
103
# File 'lib/megam/core/cloudtool.rb', line 95

def for_json
  result = {
    "id" => id,
    "name" => name,
    "cli" => cli,
    "cloudtemplates" => cloudtemplates
  }
  result
end

#from_hash(o) ⇒ Object



127
128
129
130
# File 'lib/megam/core/cloudtool.rb', line 127

def from_hash(o)
  @provider   = o[:provider] if o.has_key?(:provider)
  self
end

#id(arg = nil) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/megam/core/cloudtool.rb', line 33

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

#name(arg = nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/megam/core/cloudtool.rb', line 49

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

#some_msg(arg = nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/megam/core/cloudtool.rb', line 65

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



78
79
80
81
82
83
84
85
86
87
# File 'lib/megam/core/cloudtool.rb', line 78

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["name"] = name
  index_hash["cli"] = cli
  index_hash["cloudtemplates"] = cloudtemplates
  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.



91
92
93
# File 'lib/megam/core/cloudtool.rb', line 91

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

#to_sObject



147
148
149
# File 'lib/megam/core/cloudtool.rb', line 147

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