Class: Megam::Error
- Inherits:
-
Object
- Object
- Megam::Error
- Defined in:
- lib/megam/core/error.rb
Class Method Summary collapse
- .from_hash(o) ⇒ Object
-
.json_create(o) ⇒ Object
Create a Megam::Account from JSON (used by the backgroud job workers).
Instance Method Summary collapse
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
-
#initialize ⇒ Error
constructor
A new instance of Error.
- #some_msg(arg = nil) ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Error
Returns a new instance of Error.
4 5 6 |
# File 'lib/megam/core/error.rb', line 4 def initialize @some_msg = {} end |
Class Method Details
.from_hash(o) ⇒ Object
50 51 52 53 54 |
# File 'lib/megam/core/error.rb', line 50 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)
41 42 43 44 45 46 47 48 |
# File 'lib/megam/core/error.rb', line 41 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
#error? ⇒ Boolean
17 18 19 |
# File 'lib/megam/core/error.rb', line 17 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
35 36 37 38 |
# File 'lib/megam/core/error.rb', line 35 def for_json result = { } result end |
#from_hash(o) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/megam/core/error.rb', line 56 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 |
#some_msg(arg = nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/megam/core/error.rb', line 9 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
22 23 24 25 26 27 |
# File 'lib/megam/core/error.rb', line 22 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.
31 32 33 |
# File 'lib/megam/core/error.rb', line 31 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
65 66 67 68 |
# File 'lib/megam/core/error.rb', line 65 def to_s Megam::Stuff.styled_hash(to_hash) #"---> Megam::Account:[error=#{error?}]\n"+ end |