out_put 2.1.3 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +21 -3
- data/lib/out_put.rb +14 -4
- data/lib/out_put/version.rb +1 -1
- 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: c39b950419b24b87b7be771a242866ca754b66d4
|
4
|
+
data.tar.gz: e91476c98ce8e57c1f99f65ae5984adced45a407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b71f6421cbcf135c415fe436336d5bd9bcd4c904d2c22246714008c17b5471b78219fa93fa89efcc56c8ec9d236480e8568182abe1e0ee98b1d49819ecadab58
|
7
|
+
data.tar.gz: 233b32f3cd0bad137225e799d3a68073975aa8458fcee54e7f6fda33eadeba538611850a7a28985496f86c8b6869593f5ba72418808e473e1fb667f4a9659bcc
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -105,9 +105,27 @@ output only: { foo: 'bar' }
|
|
105
105
|
output only: [ 1, 2, 3 ]
|
106
106
|
```
|
107
107
|
|
108
|
-
### 8.
|
108
|
+
### 8. cache
|
109
109
|
|
110
|
-
|
110
|
+
```ruby
|
111
|
+
output cache: 24.hours do
|
112
|
+
{ list: User.all }
|
113
|
+
end # will render: { list: [...] }
|
114
|
+
|
115
|
+
output foo: 'bar', cache: 24.hours do
|
116
|
+
{ list: User.all }
|
117
|
+
end # will render: { foo: 'bar', list: [...] }
|
118
|
+
|
119
|
+
output only: { foo: 'bar' }, cache: 24.hours do
|
120
|
+
{ only: { list: User.all } }
|
121
|
+
end # will ONLY render: { foo: 'bar', list: [...] }
|
122
|
+
```
|
123
|
+
|
124
|
+
Note: the cache key will be `"output/#{action_name}"`
|
125
|
+
|
126
|
+
### X. Other
|
127
|
+
|
128
|
+
#### X.a automatically set `total`:
|
111
129
|
|
112
130
|
if `config.pagination_for = :list`:
|
113
131
|
|
@@ -120,7 +138,7 @@ output 0, list: [ 1, 2, 3 ]
|
|
120
138
|
# }
|
121
139
|
```
|
122
140
|
|
123
|
-
####
|
141
|
+
#### X.b use `build_with` to pass an variable `@view` to your view
|
124
142
|
|
125
143
|
```ruby
|
126
144
|
build_with key: 'val'
|
data/lib/out_put.rb
CHANGED
@@ -3,9 +3,11 @@ require 'out_put/config'
|
|
3
3
|
require 'out_put/view'
|
4
4
|
|
5
5
|
module OutPut
|
6
|
-
def output(code = 0, msg = '', only: nil, http: 200, **data)
|
6
|
+
def output(code = 0, msg = '', only: nil, http: 200, cache: nil, **data, &block)
|
7
7
|
if !code.is_a?(Integer) && code.respond_to?(:info)
|
8
8
|
code, msg, http, only = code.info.slice(:code, :msg, :http, :only).values
|
9
|
+
elsif cache && block_given?
|
10
|
+
data, only = _output_cache(cache, data: data, only: only, &block)
|
9
11
|
end
|
10
12
|
|
11
13
|
return render json: only, status: http if only.present?
|
@@ -23,6 +25,11 @@ module OutPut
|
|
23
25
|
alias error output
|
24
26
|
alias error_with output
|
25
27
|
|
28
|
+
def build_with(code = 0, msg = 'success', **data)
|
29
|
+
@view = View.new(code, msg, **data)
|
30
|
+
# Then jump to your view
|
31
|
+
end
|
32
|
+
|
26
33
|
def _output_data(data)
|
27
34
|
if data.key?(Config.pagination_for)
|
28
35
|
# TODO now is only for AR
|
@@ -32,8 +39,11 @@ module OutPut
|
|
32
39
|
data
|
33
40
|
end
|
34
41
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
42
|
+
def _output_cache(time, data: { }, only: nil, &block)
|
43
|
+
cached = Rails.cache.fetch("output/#{action_name}", expires_in: time) do
|
44
|
+
instance_eval(&block)
|
45
|
+
end
|
46
|
+
|
47
|
+
[ data.merge(cached), only&.merge(cached[:only]) ]
|
38
48
|
end
|
39
49
|
end
|
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.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|