out_put 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/out_put/config.rb +5 -3
- data/lib/out_put/version.rb +3 -1
- data/lib/out_put/view.rb +2 -0
- data/lib/out_put.rb +16 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b5565a2cfe9fabb5a97d40b9bc7c2f512fcad54
|
4
|
+
data.tar.gz: f57098b58b8d4ba72d8c7536bfd89e9712b670bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79c6083a2d017dc7831c4d07e5bf2dec795e7143e4041f49684d5652eab88f8024d8d5ca90ddd7e31e0bf9938b1393da7d6d80eaa991facb6f63494eb2bcae24
|
7
|
+
data.tar.gz: d56be4ee9103076c9c7850c227611b3f64862576e40fc287d20d42bad8134f6e26cd6d80d816f837580f8433ae9d7cb1cd79d73767d68d44d798c06539aefcb5
|
data/lib/out_put/config.rb
CHANGED
data/lib/out_put/version.rb
CHANGED
data/lib/out_put/view.rb
CHANGED
data/lib/out_put.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'out_put/version'
|
2
4
|
require 'out_put/config'
|
3
5
|
require 'out_put/view'
|
@@ -6,19 +8,13 @@ module OutPut
|
|
6
8
|
def output(code = 0, msg = '', only: nil, http: 200, cache: nil, **data, &block)
|
7
9
|
if !code.is_a?(Integer) && code.respond_to?(:info)
|
8
10
|
only = code.info[:only]
|
9
|
-
code, msg, http = code.info.
|
11
|
+
code, msg, http, data = code.info.values_at(:code, :msg, :http, :data)
|
10
12
|
elsif cache && block_given?
|
11
13
|
data, only = _output_cache(cache, data: data, only: only, &block)
|
12
14
|
end
|
13
15
|
|
14
|
-
return
|
15
|
-
|
16
|
-
code = code.zero? ? 0 : Config.project_code + code
|
17
|
-
msg = 'success' if msg.blank? && code.zero?
|
18
|
-
render json: {
|
19
|
-
result: { code: code, message: msg },
|
20
|
-
data: _output_data(data)
|
21
|
-
}, status: http
|
16
|
+
return rendrer json: only.except(:http), status: only[:http] || http if only.present?
|
17
|
+
render json: { result: _output_result(code, msg), data: _output_data(data) }, status: http
|
22
18
|
end
|
23
19
|
|
24
20
|
alias ok output
|
@@ -31,13 +27,22 @@ module OutPut
|
|
31
27
|
# Then jump to your view
|
32
28
|
end
|
33
29
|
|
30
|
+
# ***
|
31
|
+
|
32
|
+
def _output_result(code, msg)
|
33
|
+
# code = code.zero? ? 0 : Config.project_code + code
|
34
|
+
msg = 'success' if msg.blank? && code.zero?
|
35
|
+
msg = "[#{instance_exec(&Config.request_id)}] #{msg}" if Config.request_id && !code.zero?
|
36
|
+
{ code: code, message: msg }
|
37
|
+
end
|
38
|
+
|
34
39
|
def _output_data(data)
|
35
|
-
if data
|
40
|
+
if data&.key?(Config.pagination_for)
|
36
41
|
# TODO now is only for AR
|
37
42
|
data.merge!(total: data[Config.pagination_for].try(:unscoped).count)
|
38
43
|
end
|
39
44
|
|
40
|
-
data
|
45
|
+
data || { }
|
41
46
|
end
|
42
47
|
|
43
48
|
def _output_cache(time, data: { }, only: nil, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: out_put
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|