Class: Megam::CloudTool

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCloudTool

Returns a new instance of CloudTool.



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

def initialize
  @id = nil
  @name = nil
  @cli = nil
  @cloudtemplates = nil
  @some_msg = {}
end

Class Method Details

.from_hash(o) ⇒ Object



123
124
125
126
127
# File 'lib/megam/core/cloudtool.rb', line 123

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

.json_create(o) ⇒ Object



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

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

.listObject

Load all cloudtools - returns a CloudToolsCollection



136
137
138
139
# File 'lib/megam/core/cloudtool.rb', line 136

def self.list
  ct = self.new()
  ct.megam_rest.get_cloudtools
end

.show(p_name) ⇒ Object

Show a particular cloudtool by name, Megam::CloudTool



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

def self.show(p_name)
  megam_rest.get_cloudtool(p_name)
  self
end

Instance Method Details

#cli(arg = nil) ⇒ Object



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

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

#cloud_toolObject



26
27
28
# File 'lib/megam/core/cloudtool.rb', line 26

def cloud_tool
  self
end

#cloudtemplates(arg = nil) ⇒ Object



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

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

#error?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/megam/core/cloudtool.rb', line 75

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

#for_jsonObject



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

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

#from_hash(o) ⇒ Object



129
130
131
132
# File 'lib/megam/core/cloudtool.rb', line 129

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

#id(arg = nil) ⇒ Object



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

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

#megam_restObject



30
31
32
33
# File 'lib/megam/core/cloudtool.rb', line 30

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

#name(arg = nil) ⇒ Object



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

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

#some_msg(arg = nil) ⇒ Object



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

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



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

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.



93
94
95
# File 'lib/megam/core/cloudtool.rb', line 93

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

#to_sObject



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

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