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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbacc93c95d02f6e115d53219e26913431688f04
4
- data.tar.gz: 86dc492e8d89c2211aac28bcd8633987e62b26a3
3
+ metadata.gz: ae2acd60f2606d5013fc3cbd7ae728a1052aa782
4
+ data.tar.gz: a8d364a84ba246aca70399c8a054a7c8bd7f0817
5
5
  SHA512:
6
- metadata.gz: e3f5a21ba10d41db7d6ad87aa05f2b85dacc9fa4ce172363ac27388e535de85e77a3576e86bb0a731bec20c8117375521ff155101492910fe549a0b2987a27fe
7
- data.tar.gz: 5a38f4c3fc4936a679930c7d286be36ab6054e6162274a75ed023ac26ba592f1764512ae44f5a56a35f4f39d6bd1433fc5edb61bd873e29398327d181b7dcf53
6
+ metadata.gz: 90ed4795d896d061d09553e09f13c09ae6dbe259d598a8ef7ed7cea680db38fcafaab0a45c1b36f7a3c39e2ca6b6fd297238323f4cc88e2305ca579b09a90d5b
7
+ data.tar.gz: 8eac147e359441f279957754a31cda214574642a47aa4e47a060a4acfa3d376be6317fd13421b560debd80a0321daf07428b0142a89ca8a77a84ef1617f38724
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fson (0.0.8)
4
+ fson (0.0.11)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 operating on response hash objects
138
+ You can add custom builder methods using builder private methods
139
139
 
140
140
  ```ruby
141
- @_response # top level response hash
142
- @_data # data hash
143
- @_errors # errors hash
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
- @_data[:attribute] = value
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
- if data
9
+ _initialized_data_array
10
+
11
+ if data and data.is_a?(Array)
10
12
  @_data = data
11
13
  end
12
14
 
13
- yield(@_data) if block_given?
15
+ yield(_initialized_data_array()) if block_given?
14
16
  self
15
17
  end
16
18
 
17
19
  def status(status)
18
- @_response[:status] = status
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
- @_errors << error
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.empty?
59
+ unless @_data.nil?
56
60
  @_response[:data] = @_data
57
61
  end
58
62
 
data/lib/fson/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fson
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -1,3 +1,5 @@
1
1
  require 'fson/loader'
2
2
 
3
- ::Fson::Loader::configure([])
3
+ ActionDispatch::Callbacks.to_prepare do
4
+ ::Fson::Loader::configure([])
5
+ end
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.8
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-28 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec