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'
EXTEND_DIR =
'lib/error_response/*.yml'

Class Method Summary collapse

Class Method Details

.allObject



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

def self.all
  yaml_hash
end

.to_api(key, message = nil) ⇒ Object



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

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



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

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

.yaml_hashObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/error_response.rb', line 26

def self.yaml_hash
  return @hash unless @hash.nil?

  @hash = YAML.load_file(File.join(GEM_ROOT,YAML_PATH))
  Dir.glob(EXTEND_DIR).each do |file|
    extend_yml = YAML.load_file(file)
    @hash.merge!(extend_yml)
  end

  @hash
end