Class: Megam::Predef

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/predef.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) ⇒ Predef

Returns a new instance of Predef.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/megam/core/predef.rb', line 18

def initialize(email=nil, api_key=nil)
  @id = nil
  @name = nil
  @provider = nil
  @provider_role =nil
  @build_monkey=nil
  @runtime_exec = nil
  @created_at = nil
  @some_msg = {}
  super(email, api_key)
end

Class Method Details

.create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



170
171
172
173
# File 'lib/megam/core/predef.rb', line 170

def self.create(o,tmp_email=nil, tmp_api_key=nil)
  predef = from_hash(o,tmp_email, tmp_api_key)
  predef.create
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



153
154
155
156
157
# File 'lib/megam/core/predef.rb', line 153

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  node = self.new(tmp_email, tmp_api_key)
  node.from_hash(o)
  node
end

.json_create(o) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/megam/core/predef.rb', line 136

def self.json_create(o)
  node = new
  node.id(o["id"]) if o.has_key?("id")
  node.name(o["name"]) if o.has_key?("name")
  node.provider(o["provider"]) if o.has_key?("provider")
  node.provider_role(o["provider_role"]) if o.has_key?("provider_role")
  node.build_monkey(o["build_monkey"]) if o.has_key?("build_monkey")
  node.runtime_exec(o["runtime_exec"]) if o.has_key?("runtime_exec")
  node.created_at(o["created_at"]) if o.has_key?("created_at")
  #success or error
  node.some_msg[:code] = o["code"] if o.has_key?("code")
  node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  node.some_msg[:links] = o["links"] if o.has_key?("links")
  node
end

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

Load all predefs - returns a PredefsCollection don’t return self. check if the Megam::PredefCollection is returned.



184
185
186
187
# File 'lib/megam/core/predef.rb', line 184

def self.list(tmp_email=nil, tmp_api_key=nil)
  prede = self.new(tmp_email,tmp_api_key)
  prede.megam_rest.get_predefs
end

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

Show a particular predef by name, Megam::Predef



191
192
193
194
# File 'lib/megam/core/predef.rb', line 191

def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
  prede = self.new(tmp_email,tmp_api_key)
  prede.megam_rest.get_predef(p_name)
end

Instance Method Details

#build_monkey(arg = nil) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/megam/core/predef.rb', line 74

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

#create(predef_input) ⇒ Object

Create the predef via the REST API



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

def create(predef_input)
  megam_rest.post_predef(predef_input)
  self
end

#created_at(arg = nil) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/megam/core/predef.rb', line 82

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

#error?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/megam/core/predef.rb', line 98

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

#for_jsonObject



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/megam/core/predef.rb', line 122

def for_json
  result = {
    "id" => id,
    "name" => name,
    "provider" => provider,
    "provider_role" => provider_role,
    "build_monkey" => build_monkey,
    "runtime_exec" => runtime_exec,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/megam/core/predef.rb', line 159

def from_hash(o)
  @id = o[:id] if o.has_key?(:id)
  @name  = o[:name] if o.has_key?(:name)
  @provider       = o[:provider] if o.has_key?(:provider)
  @provider_role  = o[:provider_role] if o.has_key?(:provider_role)
  @build_monkey   = o[:build_monkey] if o.has_key?(:build_monkey)
  @runtime_exec   = o[:runtime_exec] if o.has_key?(:runtime_exec)
  @created_at   = o[:created_at] if o.has_key?(:created_at)
  self
end

#id(arg = nil) ⇒ Object



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

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

#name(arg = nil) ⇒ Object



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

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

#predefObject



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

def predef
  self
end

#provider(arg = nil) ⇒ Object



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

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

#provider_role(arg = nil) ⇒ Object



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

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

#runtime_exec(arg = nil) ⇒ Object



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

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

#some_msg(arg = nil) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/megam/core/predef.rb', line 90

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



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/megam/core/predef.rb', line 103

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["name"] = name
  index_hash["provider"] = provider
  index_hash["provider_role"] = provider_role
  index_hash["build_monkey"] = build_monkey
  index_hash["runtime_exec"] = runtime_exec
  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.



118
119
120
# File 'lib/megam/core/predef.rb', line 118

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

#to_sObject



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

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