out_put 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/out_put.rb +4 -12
- data/lib/out_put/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6263458e404b6c61cabd1e5474ccbbc2eb5546fed9c4e41b87467cf4d8859b46
|
4
|
+
data.tar.gz: 661005b6445528f58106a0485b9479f94b86575a0190504ac485c16a5a845eb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f4d8c0d385525cff1d423edee752d92c6412361c1bcffc28bb34b1730c2b470bd52a512c5ca0586d005c7940182efc9a5f23134775f61f8e1821637a2a90604
|
7
|
+
data.tar.gz: 909430d54859890ca183be0fb2262d481afe974c2f58dac58ea50ae8993762bd056f5b817ae462848272df616296ec4517ca969212d391d5bd107e77fd71eda1
|
data/lib/out_put.rb
CHANGED
@@ -5,7 +5,8 @@ require 'out_put/config'
|
|
5
5
|
require 'out_put/view'
|
6
6
|
|
7
7
|
module OutPut
|
8
|
-
def output(code = 0, msg = '', only: nil, http: 200, cache: nil,
|
8
|
+
def output(code = 0, msg = '', only: nil, http: 200, cache: nil, data: nil, **d, &block)
|
9
|
+
data ||= d || { }
|
9
10
|
if !code.is_a?(Integer) && code.respond_to?(:info)
|
10
11
|
only = code.info[:only]
|
11
12
|
code, msg, http, data = code.info.values_at(:code, :msg, :http, :data)
|
@@ -13,8 +14,8 @@ module OutPut
|
|
13
14
|
data, only = _output_cache(cache, data: data, only: only, &block)
|
14
15
|
end
|
15
16
|
|
16
|
-
return
|
17
|
-
render json: { result: _output_result(code, msg), data:
|
17
|
+
return render json: only.except(:http), status: only[:http] || http if only.present?
|
18
|
+
render json: { result: _output_result(code, msg), data: data }, status: http
|
18
19
|
end
|
19
20
|
|
20
21
|
alias ok output
|
@@ -36,15 +37,6 @@ module OutPut
|
|
36
37
|
{ code: code, message: msg }
|
37
38
|
end
|
38
39
|
|
39
|
-
def _output_data(data)
|
40
|
-
if data&.key?(Config.pagination_for)
|
41
|
-
# TODO now is only for AR
|
42
|
-
data.merge!(total: data[Config.pagination_for].try(:unscoped).count)
|
43
|
-
end
|
44
|
-
|
45
|
-
data || { }
|
46
|
-
end
|
47
|
-
|
48
40
|
def _output_cache(time, data: { }, only: nil, &block)
|
49
41
|
cached = Rails.cache.fetch("output/#{action_name}", expires_in: time) do
|
50
42
|
instance_eval(&block)
|
data/lib/out_put/version.rb
CHANGED
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.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.7.3
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Render JSON response in a unified format
|