fson 0.0.8 → 0.0.11
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 +8 -5
- data/lib/fson/builder.rb +28 -5
- data/lib/fson/response.rb +6 -2
- data/lib/fson/version.rb +1 -1
- data/lib/generators/fson/templates/initializer.rb +3 -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: ae2acd60f2606d5013fc3cbd7ae728a1052aa782
|
4
|
+
data.tar.gz: a8d364a84ba246aca70399c8a054a7c8bd7f0817
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ed4795d896d061d09553e09f13c09ae6dbe259d598a8ef7ed7cea680db38fcafaab0a45c1b36f7a3c39e2ca6b6fd297238323f4cc88e2305ca579b09a90d5b
|
7
|
+
data.tar.gz: 8eac147e359441f279957754a31cda214574642a47aa4e47a060a4acfa3d376be6317fd13421b560debd80a0321daf07428b0142a89ca8a77a84ef1617f38724
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -135,12 +135,13 @@ will return
|
|
135
135
|
|
136
136
|
## Custom builders
|
137
137
|
|
138
|
-
You can add custom builder methods
|
138
|
+
You can add custom builder methods using builder private methods
|
139
139
|
|
140
140
|
```ruby
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
_response # returns response hash
|
142
|
+
_errors # returns errors hash
|
143
|
+
_data # returns data hash
|
144
|
+
_initialized_data_array # returns existing data array or initializes it with empty array
|
144
145
|
```
|
145
146
|
|
146
147
|
For example you can add builder
|
@@ -149,7 +150,9 @@ For example you can add builder
|
|
149
150
|
module MyCustomBuilder
|
150
151
|
|
151
152
|
def attribute(value)
|
152
|
-
|
153
|
+
_initialized_data_array << {
|
154
|
+
:attribute => 'value'
|
155
|
+
}
|
153
156
|
self
|
154
157
|
end
|
155
158
|
end
|
data/lib/fson/builder.rb
CHANGED
@@ -6,16 +6,18 @@ module Fson
|
|
6
6
|
##
|
7
7
|
|
8
8
|
def data(data = nil, &block)
|
9
|
-
|
9
|
+
_initialized_data_array
|
10
|
+
|
11
|
+
if data and data.is_a?(Array)
|
10
12
|
@_data = data
|
11
13
|
end
|
12
14
|
|
13
|
-
yield(
|
15
|
+
yield(_initialized_data_array()) if block_given?
|
14
16
|
self
|
15
17
|
end
|
16
18
|
|
17
19
|
def status(status)
|
18
|
-
|
20
|
+
_response[:status] = status
|
19
21
|
self
|
20
22
|
end
|
21
23
|
|
@@ -24,8 +26,7 @@ module Fson
|
|
24
26
|
|
25
27
|
yield(error) if block_given?
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
_errors.push(error)
|
29
30
|
self
|
30
31
|
end
|
31
32
|
|
@@ -44,5 +45,27 @@ module Fson
|
|
44
45
|
def fail
|
45
46
|
status(:fail)
|
46
47
|
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Private
|
51
|
+
##
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def _data
|
56
|
+
@_data
|
57
|
+
end
|
58
|
+
|
59
|
+
def _response
|
60
|
+
@_response
|
61
|
+
end
|
62
|
+
|
63
|
+
def _errors
|
64
|
+
@_errors
|
65
|
+
end
|
66
|
+
|
67
|
+
def _initialized_data_array
|
68
|
+
@_data ||= []
|
69
|
+
end
|
47
70
|
end
|
48
71
|
end
|
data/lib/fson/response.rb
CHANGED
@@ -14,7 +14,7 @@ module Fson
|
|
14
14
|
|
15
15
|
def initialize(status = nil)
|
16
16
|
@_response = {}
|
17
|
-
@_data =
|
17
|
+
@_data = nil
|
18
18
|
@_errors = []
|
19
19
|
|
20
20
|
unless status.nil?
|
@@ -26,6 +26,10 @@ module Fson
|
|
26
26
|
::Oj.dump(build, :mode => :compat)
|
27
27
|
end
|
28
28
|
|
29
|
+
##
|
30
|
+
# Static
|
31
|
+
##
|
32
|
+
|
29
33
|
class << self
|
30
34
|
|
31
35
|
##
|
@@ -52,7 +56,7 @@ module Fson
|
|
52
56
|
private
|
53
57
|
|
54
58
|
def build
|
55
|
-
unless @_data.
|
59
|
+
unless @_data.nil?
|
56
60
|
@_response[:data] = @_data
|
57
61
|
end
|
58
62
|
|
data/lib/fson/version.rb
CHANGED
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.11
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|