out_put 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e453a328154fd0f958739f27e03523228013d42
4
- data.tar.gz: b262f49030b0fc9b0a930e5d7471b37b8bbc918a
3
+ metadata.gz: 2f0bbf9be68f7e714bb08b8a421ec1466399e769
4
+ data.tar.gz: d246c2858b54288aff98ae6ac12fc63aa46c239f
5
5
  SHA512:
6
- metadata.gz: d79b90d8f999543c6cc9c0b1e294b415e8d858f799ade8cba7f4f4263b807e81fac840e4061de8f46be3d4a39424d1206c354b98a4c8fd736f3da0de4d731243
7
- data.tar.gz: 513191dd1f9e1a750300e3f3714a12bb71ce046ab88299759c6710c7ac07b875641fb03972241385d2aa83542bad49f39666452dcf5080b769e7938d4cdac27d
6
+ metadata.gz: 82b6913f4908c1c3ac71a8b2bfe07716cce4e2405a78a714a5bb9224b0f1788ba2acc2c8fbb16d83bdaf5626ff978a68d7f3ee48d1526c6c31a0a595bb712393
7
+ data.tar.gz: 189abd12eb85aa49b3ba77f92660c010fa4d8dec07aa87a3216aa83e75986e30268149186e6df250b6b35170baae5ca946ed21f9a8ef635c854a23ed2f7dbb43
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- out_put (2.1.2)
4
+ out_put (2.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -123,8 +123,17 @@ output 0, list: [ 1, 2, 3 ]
123
123
  #### 8.b use `build_with` to pass an variable `@view` to your view
124
124
 
125
125
  ```ruby
126
- build_with data: 'hello'
126
+ build_with key: 'val'
127
+ build_with code=0, msg='success', key: 'val'
127
128
 
128
129
  # the in your .jbuilder
129
- json.data @view[:data]
130
+ json.result do
131
+ json.code @view[:code] || 0
132
+ json.msg @view[:msg] || 'success'
133
+ end
134
+ json.data do
135
+ json.merge! @view.data # => expect code and msg, for example { key: 'val' }
136
+ # or
137
+ json.key @view[:key]
138
+ end
130
139
  ```
@@ -1,3 +1,3 @@
1
1
  module OutPut
2
- VERSION = '2.1.2'
2
+ VERSION = '2.1.3'
3
3
  end
@@ -0,0 +1,10 @@
1
+ module OutPut
2
+ class View < Hash
3
+ attr_accessor :data
4
+
5
+ def initialize(code, msg, **data)
6
+ self.data = data
7
+ self.merge!(code: code, msg: msg, **data)
8
+ end
9
+ end
10
+ end
data/lib/out_put.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'out_put/version'
2
2
  require 'out_put/config'
3
+ require 'out_put/view'
3
4
 
4
5
  module OutPut
5
6
  def output(code = 0, msg = '', only: nil, http: 200, **data)
@@ -24,15 +25,15 @@ module OutPut
24
25
 
25
26
  def _output_data(data)
26
27
  if data.key?(Config.pagination_for)
27
- # TODO now is noly for AR
28
+ # TODO now is only for AR
28
29
  data.merge!(total: data[Config.pagination_for].try(:unscoped).count)
29
30
  end
30
31
 
31
32
  data
32
33
  end
33
34
 
34
- def build_with(**data)
35
- @view = data
35
+ def build_with(code = 0, msg = 'success', **data)
36
+ @view = View.new(code, msg, **data)
36
37
  # Then jump to your view
37
38
  end
38
39
  end
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.1.2
4
+ version: 2.1.3
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-15 00:00:00.000000000 Z
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,7 @@ files:
73
73
  - lib/out_put.rb
74
74
  - lib/out_put/config.rb
75
75
  - lib/out_put/version.rb
76
+ - lib/out_put/view.rb
76
77
  - out_put.gemspec
77
78
  homepage: https://github.com/zhandao/out_put
78
79
  licenses: