class ResultPacker

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

Public Class Methods

data(data_hash={}, msg='通信正常!') click to toggle source

封装数据

# 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={}) click to toggle source

异常错误

# 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='数据逻辑有误,请查看错误明细!') click to toggle source

前台验证错误

# 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='部分逻辑错误!') click to toggle source

前台验证错误

# 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={}) click to toggle source

自定义打包

# File lib/ns_service_pack/result_packer.rb, line 7
def self.pack(response_hash={})
  {:status=>'ok',:msg=>'', :data=>nil}.merge!(response_hash)
end