Module: UtilHelper

Defined in:
lib/helper/util_helper.rb

Instance Method Summary collapse

Instance Method Details

#api_return(rc = 0, message = '', obj = nil, exception = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/helper/util_helper.rb', line 28

def api_return(rc=0, message ='', obj=nil, exception=nil )
  ret = {
    rc: exception ? (rc > 0 ? rc : 8) : rc,
    message: message
  }
  ret[:exception] = exception.to_s if exception
  ret[:return] = obj if obj
  ret
end

#log(msg = 'no message') ⇒ Object



4
5
6
# File 'lib/helper/util_helper.rb', line 4

def log(msg='no message')
  puts obj_to_s(msg)
end

#obj_to_s(msg) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/helper/util_helper.rb', line 8

def obj_to_s(msg)
  case msg.class
  when Hash
    JSON.pretty_generate(msg)
  else
    begin
      JSON.pretty_generate(JSON.parse(msg.to_json))
    rescue 
      msg
    end
  end    
end