fson 0.0.6 → 0.0.7
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 +16 -3
- data/lib/fson/builder.rb +21 -1
- data/lib/fson/version.rb +1 -1
- data/spec/fson/response/as_json_spec.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: 23374c8f8aafdce860f47213ee34618dea8b09a7
|
4
|
+
data.tar.gz: b47e5fe45a7612aa9b843bdbfbb5cc7f1f21bf80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f3ff680a7d4d7c0b7b683d6029d72a8465ea1ae35d2285b32536cb3bf424b6f618b60a5fdae3dfcfccc24ba9b85bae4fc6d6f7494626d04f2ae4ed5dea45909
|
7
|
+
data.tar.gz: 89a0a1d67105b783e081f8393547f4ef2b95d762db77014d53e196631b4f9111c92f8a0237f6ba5d0aef8578bde0e0ac1a9328bf21169a2a4606a3b252f2b4c2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,6 +5,7 @@ Fson is a fluent builder for simple JSON API responses
|
|
5
5
|
[![Build Status](https://travis-ci.org/mkluczny/fson.svg?branch=develop)](https://travis-ci.org/mkluczny/fson)
|
6
6
|
[![Dependency Status](https://gemnasium.com/mkluczny/fson.svg)](https://gemnasium.com/mkluczny/fson)
|
7
7
|
[![Code Climate](https://codeclimate.com/github/mkluczny/fson/badges/gpa.svg)](https://codeclimate.com/github/mkluczny/fson)
|
8
|
+
[![Test Coverage](https://codeclimate.com/github/mkluczny/fson/badges/coverage.svg)](https://codeclimate.com/github/mkluczny/fson/coverage)
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -71,9 +72,9 @@ or defining block
|
|
71
72
|
optionally add errors
|
72
73
|
|
73
74
|
```ruby
|
74
|
-
.
|
75
|
+
.add_error('not authorized') { |e|
|
75
76
|
e[:code] = 401
|
76
|
-
}.
|
77
|
+
}.add_error('null pointer exception')
|
77
78
|
```
|
78
79
|
|
79
80
|
```json
|
@@ -101,7 +102,7 @@ and finally get JSON with
|
|
101
102
|
Builder chain
|
102
103
|
|
103
104
|
```ruby
|
104
|
-
Fson::Response.fail.data {|data| data[:id] = 12}.
|
105
|
+
Fson::Response.fail.data {|data| data[:id] = 12}.add_error('not authorized').as_json
|
105
106
|
```
|
106
107
|
|
107
108
|
will return
|
@@ -120,6 +121,18 @@ will return
|
|
120
121
|
}
|
121
122
|
```
|
122
123
|
|
124
|
+
## More builder methods
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
.success() # sets status to :success
|
128
|
+
.error() # sets status to :error
|
129
|
+
.fail() # sets status to :fail
|
130
|
+
|
131
|
+
.status('failure') # sets status
|
132
|
+
```
|
133
|
+
|
134
|
+
|
135
|
+
|
123
136
|
## Custom builders
|
124
137
|
|
125
138
|
You can add custom builder methods operating on response hash objects
|
data/lib/fson/builder.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Fson
|
2
2
|
module Builder
|
3
3
|
|
4
|
+
##
|
5
|
+
# Builder Methods
|
6
|
+
##
|
7
|
+
|
4
8
|
def data(data = nil, &block)
|
5
9
|
if data
|
6
10
|
@_data = data
|
@@ -15,7 +19,7 @@ module Fson
|
|
15
19
|
self
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
22
|
+
def add_error(message, &block)
|
19
23
|
error = { :message => message }
|
20
24
|
|
21
25
|
yield(error) if block_given?
|
@@ -24,5 +28,21 @@ module Fson
|
|
24
28
|
|
25
29
|
self
|
26
30
|
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Status Setters
|
34
|
+
##
|
35
|
+
|
36
|
+
def error
|
37
|
+
status(:error)
|
38
|
+
end
|
39
|
+
|
40
|
+
def success
|
41
|
+
status(:success)
|
42
|
+
end
|
43
|
+
|
44
|
+
def fail
|
45
|
+
status(:fail)
|
46
|
+
end
|
27
47
|
end
|
28
48
|
end
|
data/lib/fson/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe ::Fson::Response do
|
|
7
7
|
it 'should return json response' do
|
8
8
|
# given
|
9
9
|
response = ::Fson::Response.error
|
10
|
-
.
|
10
|
+
.add_error('invalid') { |e| e[:id] = 'text-set-1'}
|
11
11
|
.data { |data| data[:author] = 'Mateusz Kluczny' }
|
12
12
|
|
13
13
|
# when/then
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Kluczny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|