Class: Megam::Error

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeError

Returns a new instance of Error.



19
20
21
# File 'lib/megam/core/error.rb', line 19

def initialize
  @some_msg = {}
end

Class Method Details

.authObject

just an auth



88
89
90
91
# File 'lib/megam/core/error.rb', line 88

def self.auth
  megam_rest.post_auth
  self
end

.from_hash(o) ⇒ Object



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

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

.json_create(o) ⇒ Object

Create a Megam::Account from JSON (used by the backgroud job workers)



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

def self.json_create(o)
  acct = new
  acct.some_msg[:code] = o["code"] if o.has_key?("code")
  acct.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  acct.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  acct.some_msg[:links] = o["links"] if o.has_key?("links")
  acct
end

Instance Method Details

#authObject

used by resque workers and any other background job



24
25
26
# File 'lib/megam/core/error.rb', line 24

def auth
  self
end

#error?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/megam/core/error.rb', line 40

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

#for_jsonObject



58
59
60
61
# File 'lib/megam/core/error.rb', line 58

def for_json
  result = { }
  result
end

#from_hash(o) ⇒ Object



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

def from_hash(o)
  @some_msg[:code] = o["code"] if o.has_key?("code")
  @some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  @some_msg[:msg]= o["msg"] if o.has_key?("msg")
  @some_msg[:links] = o["links"] if o.has_key?("links")
  self
end

#megam_restObject



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

def megam_rest
  Megam::Scm.new(Megam::Config[:name], Megam::Config[:displayName], Megam::Config[:mail], Megam::Config[:password])
end

#some_msg(arg = nil) ⇒ Object



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

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



45
46
47
48
49
50
# File 'lib/megam/core/error.rb', line 45

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



54
55
56
# File 'lib/megam/core/error.rb', line 54

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

#to_sObject



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

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