Class: ErrorResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/error_response.rb

Constant Summary collapse

GEM_ROOT =
File.expand_path("../..", __FILE__)
YAML_PATH =
'lib/error_response.yml'

Class Method Summary collapse

Class Method Details

.allObject



20
21
22
# File 'lib/error_response.rb', line 20

def self.all
  yaml_hash
end

.to_api(key, message = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/error_response.rb', line 6

def self.to_api(key, message=nil)
  err_json = yaml_hash[key.to_s] || {'error_code' => 500000, 'error_message' => message}

  status = err_json['error_code'] / 1000
  {
    'status' => status,
    'json' => err_json
  }
end

.to_hash(key) ⇒ Object



16
17
18
# File 'lib/error_response.rb', line 16

def self.to_hash(key)
  yaml_hash[key.to_s]
end

.yaml_hashObject



25
26
27
# File 'lib/error_response.rb', line 25

def self.yaml_hash
  yaml ||= YAML.load_file(File.join(GEM_ROOT,YAML_PATH))
end