Class: ResultPacker

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

Overview

Service模块提供的json数据格式封装

Class Method Summary collapse

Class Method Details

.data(data_hash = {}, msg = '通信正常!') ⇒ Object

封装数据



12
13
14
# File 'lib/ns_service_pack/result_packer.rb', line 12

def self.data(data_hash={}, msg='通信正常!')
  {:status=>'ok',:msg=>msg, :data=>data_hash}
end

.error(msg = '通信异常,请查看出错信息!', error_hash = {}) ⇒ Object

异常错误



27
28
29
# File 'lib/ns_service_pack/result_packer.rb', line 27

def self.error(msg='通信异常,请查看出错信息!', error_hash={})
  {:status=>'error',:msg=>msg, :errors=>error_hash}
end

.help(hint_hash = {}, msg = '数据逻辑有误,请查看错误明细!') ⇒ Object

前台验证错误



22
23
24
# File 'lib/ns_service_pack/result_packer.rb', line 22

def self.help(hint_hash={}, msg='数据逻辑有误,请查看错误明细!')
  {:status=>'illegal',:msg=>msg, :errors=>hint_hash}
end

.improve(ok_data = nil, hint_hash = {}, msg = '部分逻辑错误!') ⇒ Object

前台验证错误



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

def self.improve(ok_data = nil, hint_hash={}, msg='部分逻辑错误!')
  {:status=>'imperfect',:msg=>msg, :data=>ok_data, :errors=>hint_hash}
end

.pack(response_hash = {}) ⇒ Object

自定义打包



7
8
9
# File 'lib/ns_service_pack/result_packer.rb', line 7

def self.pack(response_hash={})
  {:status=>'ok',:msg=>'', :data=>nil}.merge!(response_hash)
end