api-blueprint 0.8.0 → 0.8.1

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: 107d220ee5caf5652b5aa9d19e6cf48d9650873f
4
- data.tar.gz: ddde847693510961973b9c9463373b6a92ae6104
3
+ metadata.gz: 84b4415cd8e7238b56f556969215b94c1ed7471d
4
+ data.tar.gz: fead4f882d90ea4e232dea148c22ebb93462fbc5
5
5
  SHA512:
6
- metadata.gz: 8eb0d1ccdf38f848f47d6a6a23d651f405cdd73c44b545565d03741c9a31443a3afb7d7cfa7d741991d05cc0873ebd8186ae659f99150899311f42d106037f82
7
- data.tar.gz: c60d05fc38eeb6039a31c6e18ab79d9080c55bfd5ae288cd7222f4feea145522a70d68cb7d4bb17f6c5b547ae2a4176cb4f850f9737f3fcbfb178ce04e32dd76
6
+ metadata.gz: d1c4fbce9cd213728a8985ae19b163942f9c46a5204d50edb34bd33adb75147492ecc9fa115b18aafb001f1c4c192eb2e711d328c7375a6007c9ac5f0c06c986
7
+ data.tar.gz: 04e83ea3a7a15d1d12859f56aedbf6f8b61ae623fd6c9ce287ae3ba22ff0e3dd4b333a9fa5d54af517e25f0870421e0e9a053dc712fe53271d03b6fb712f1fe3
@@ -9,6 +9,7 @@ require 'addressable'
9
9
  require 'active_support'
10
10
  require 'active_support/core_ext'
11
11
 
12
+ require 'api-blueprint/key_replacer'
12
13
  require 'api-blueprint/struct'
13
14
  require 'api-blueprint/response_middleware'
14
15
  require 'api-blueprint/cache'
@@ -23,7 +23,7 @@ module ApiBlueprint
23
23
  response_status: status
24
24
  }
25
25
 
26
- meta.merge with_replacements(item.deep_symbolize_keys)
26
+ meta.merge KeyReplacer.replace(item.deep_symbolize_keys, replacements)
27
27
  end
28
28
 
29
29
  def build_item(item)
@@ -34,15 +34,5 @@ module ApiBlueprint
34
34
  end
35
35
  end
36
36
 
37
- private
38
-
39
- def with_replacements(item)
40
- item.tap do |item|
41
- replacements.each do |bad, good|
42
- item[good] = item.delete bad if item.has_key? bad
43
- end
44
- end
45
- end
46
-
47
37
  end
48
38
  end
@@ -0,0 +1,13 @@
1
+ module ApiBlueprint
2
+ class KeyReplacer
3
+
4
+ def self.replace(attributes, replacements)
5
+ attributes.dup.deep_symbolize_keys.tap do |item|
6
+ replacements.each do |bad, good|
7
+ item[good] = item.delete bad if item.has_key? bad
8
+ end
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -5,5 +5,13 @@ module ApiBlueprint
5
5
  transform_types do |type|
6
6
  type.default? ? type : type.meta(omittable: true)
7
7
  end
8
+
9
+ def self.new(attributes = default_attributes)
10
+ if respond_to?(:config) && config.replacements
11
+ attributes = KeyReplacer.replace(attributes, config.replacements)
12
+ end
13
+
14
+ super
15
+ end
8
16
  end
9
17
  end
@@ -1,3 +1,3 @@
1
1
  module ApiBlueprint
2
- VERSION = '0.8.0'
2
+ VERSION = '0.8.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-blueprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Timewell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types
@@ -222,6 +222,7 @@ files:
222
222
  - lib/api-blueprint/builder.rb
223
223
  - lib/api-blueprint/cache.rb
224
224
  - lib/api-blueprint/collection.rb
225
+ - lib/api-blueprint/key_replacer.rb
225
226
  - lib/api-blueprint/model.rb
226
227
  - lib/api-blueprint/parser.rb
227
228
  - lib/api-blueprint/response_middleware.rb