Class: Megam::Predef

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePredef

Returns a new instance of Predef.



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

def initialize
  @id = nil
  @name = nil
  @provider = nil
  @provider_role =nil
  @build_monkey=nil
  @runtime_exec = nil
  @created_at = nil
  @some_msg = {}
end

Class Method Details

.createObject



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

def self.create
  predef = build
  predef.create
end

.from_hash(o) ⇒ Object



158
159
160
161
162
# File 'lib/megam/core/predef.rb', line 158

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

.json_create(o) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/megam/core/predef.rb', line 141

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

.listObject

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



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

def self.list
  prede = self.new()
  prede.megam_rest.get_predefs
end

.show(p_name) ⇒ Object

Show a particular predef by name, Megam::Predef



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

def self.show(p_name)
  prede = self.new()
  prede.megam_rest.get_predef(p_name)
end

Instance Method Details

#build_monkey(arg = nil) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/megam/core/predef.rb', line 79

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



182
183
184
185
# File 'lib/megam/core/predef.rb', line 182

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

#created_at(arg = nil) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/megam/core/predef.rb', line 87

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

#error?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/megam/core/predef.rb', line 103

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

#for_jsonObject



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/megam/core/predef.rb', line 127

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



164
165
166
167
168
169
170
171
172
173
# File 'lib/megam/core/predef.rb', line 164

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



39
40
41
42
43
44
45
# File 'lib/megam/core/predef.rb', line 39

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

#megam_restObject



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

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

#name(arg = nil) ⇒ Object



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

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



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

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

#provider_role(arg = nil) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/megam/core/predef.rb', line 71

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

#runtime_exec(arg = nil) ⇒ Object



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

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

#some_msg(arg = nil) ⇒ Object



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

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



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

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.



123
124
125
# File 'lib/megam/core/predef.rb', line 123

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

#to_sObject



202
203
204
205
# File 'lib/megam/core/predef.rb', line 202

def to_s
  Megam::Stuff.styled_hash(to_hash)
#"---> Megam::Account:[error=#{error?}]\n"+
end