fson 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cddfef5d630ad5cf03719127dcbd0e8a5fa4236
4
- data.tar.gz: c116041b17ede76525c20f74f5c8258bf19b3fad
3
+ metadata.gz: 23374c8f8aafdce860f47213ee34618dea8b09a7
4
+ data.tar.gz: b47e5fe45a7612aa9b843bdbfbb5cc7f1f21bf80
5
5
  SHA512:
6
- metadata.gz: cb5cd1db604ab6d2309466e17800193a94386fbf75f745d2c5d4f19f3227a8cfc86e206ea1adf55e15d29f1d627d1459384dbcc0bbc0077edd1bbe8c86c3a01b
7
- data.tar.gz: 45307d3145080234ea52640fc2f2c72596e2f675773d5b4a5625c49b2d8a20b37813b5c16e44b9b74870a19234c8735434881532c8b2fbf24f44d189c8e13c9f
6
+ metadata.gz: 4f3ff680a7d4d7c0b7b683d6029d72a8465ea1ae35d2285b32536cb3bf424b6f618b60a5fdae3dfcfccc24ba9b85bae4fc6d6f7494626d04f2ae4ed5dea45909
7
+ data.tar.gz: 89a0a1d67105b783e081f8393547f4ef2b95d762db77014d53e196631b4f9111c92f8a0237f6ba5d0aef8578bde0e0ac1a9328bf21169a2a4606a3b252f2b4c2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fson (0.0.6)
4
+ fson (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- .error('not authorized') { |e|
75
+ .add_error('not authorized') { |e|
75
76
  e[:code] = 401
76
- }.error('null pointer exception')
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}.error('not authorized').as_json
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 error(message, &block)
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
@@ -1,3 +1,3 @@
1
1
  module Fson
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -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
- .error('invalid') { |e| e[:id] = 'text-set-1'}
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.6
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-24 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec