codeclimate-yaml 0.10.1 → 0.10.2

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: 42b71f5275d2290ef4dca8a75e6d16c925811fa7
4
- data.tar.gz: f522feafc0362ed0e5a3b30f327f6f967ad9b29c
3
+ metadata.gz: 56bfd6fdea44b1984d887361fe8e8a0c0fe7b780
4
+ data.tar.gz: 9c2cb42b02eb6915b47016ce199a464c77a3f821
5
5
  SHA512:
6
- metadata.gz: b3e247c9cc22d3cf612c0eea805a1d9d33a324855fa10db8e2d517ac41affa294bb2ae768d7b6257f11df11f491a1a47613cfca602e95445fe34fc77ec428754
7
- data.tar.gz: 5e4cc074a59d32a4cf2875c3dc327e5d2c4d5ede5af6b098ce43796186275ae046587f1e6a18cb4d0e75d535c03a45f0ee4c7ee4295b51e1788909781b348396
6
+ metadata.gz: 436bc46332ab17eb4e393e22a3afcace0917fcb14099f4d0889fbcd3bb29aa2b4036125dc366137a9f9f2fe77ae81ebdcfcb6bc8b6cdf4644dc4085adc994dbc
7
+ data.tar.gz: b77518bf2d12fc22722c3eb03119f814ba484e318d3ef2f9c40321f3f81b03154d33d5e48990a954d31e6dde7fe129924bd99cc34d17eafaa3f54d54ccf4146d
@@ -65,19 +65,19 @@ module CC::Yaml
65
65
 
66
66
  def visit_pair(visitor, key, value)
67
67
  key = visitor.generate_key(self, key)
68
- unless set_warnings(key)
68
+ unless set_warnings(visitor, key, value)
69
69
  check_incompatibility(key)
70
70
  visit_key_value(visitor, key, value)
71
71
  end
72
72
  end
73
73
 
74
74
  def visit_key_value(visitor, key, value)
75
- node = subnode_for_key(key)
75
+ node = subnode_for(visitor, key, value)
76
76
  assign_node_and_visit(node, key, value, visitor)
77
77
  end
78
78
 
79
- def set_warnings(key)
80
- if subnode_for_key(key)
79
+ def set_warnings(visitor, key, value)
80
+ if subnode_for(visitor, key, value)
81
81
  check_duplicates(key)
82
82
  else
83
83
  warning("unexpected key %p, dropping", key)
@@ -113,7 +113,7 @@ module CC::Yaml
113
113
  self.class.mapping.include? key
114
114
  end
115
115
 
116
- def subnode_for_key(key)
116
+ def subnode_for(_visitor, key, _value)
117
117
  type = self.class.subnode_for_key(key)
118
118
  type.new(self) if type
119
119
  end
@@ -3,19 +3,19 @@ module CC
3
3
  module Nodes
4
4
  class NestedConfig < OpenMapping
5
5
  def visit_key_value(visitor, key, value)
6
- node = subnode_for_pair(key, value)
6
+ node = subnode_for_pair(visitor, key, value)
7
7
  assign_node_and_visit(node, key, value, visitor)
8
8
  end
9
9
 
10
10
  protected
11
11
 
12
- def subnode_for_pair(key, value)
12
+ def subnode_for_pair(visitor, key, value)
13
13
  if value.is_a?(::Psych::Nodes::Mapping)
14
14
  NestedConfig.new(self)
15
15
  elsif value.is_a?(::Psych::Nodes::Sequence)
16
16
  Sequence.new(self)
17
17
  else
18
- subnode_for_key(key)
18
+ subnode_for(visitor, key, value)
19
19
  end
20
20
  end
21
21
  end
@@ -3,11 +3,12 @@ module CC::Yaml
3
3
  class OpenMapping < Mapping
4
4
  def self.default_type(identifier = nil)
5
5
  @default_type = Nodes[identifier] if identifier
6
- @default_type ||= superclass.respond_to?(:default_type) ? superclass.default_type : Scalar
6
+ @default_type ||= superclass.respond_to?(:default_type) ? superclass.default_type : nil
7
7
  end
8
8
 
9
- def self.subnode_for_key(key)
10
- super(key) || default_type
9
+ def subnode_for(visitor, key, value)
10
+ klass = self.class.subnode_for_key(key) || self.class.default_type || visitor.node_wrapper_class(value)
11
+ klass.new(self)
11
12
  end
12
13
 
13
14
  def accept_key?(key)
@@ -11,7 +11,7 @@ module CC::Yaml
11
11
 
12
12
  def self.type(identifier = nil)
13
13
  @type = Nodes[identifier] if identifier
14
- @type ||= superclass.respond_to?(:type) ? superclass.type : Scalar
14
+ @type ||= superclass.respond_to?(:type) ? superclass.type : nil
15
15
  end
16
16
 
17
17
  def prepare
@@ -31,7 +31,12 @@ module CC::Yaml
31
31
  end
32
32
 
33
33
  def visit_child(visitor, value)
34
- child = self.class.type.new(self)
34
+ child =
35
+ if self.class.type
36
+ self.class.type.new(self)
37
+ else
38
+ visitor.node_wrapper_class(value).new(self)
39
+ end
35
40
  visitor.accept(child, value)
36
41
  @children << child
37
42
  end
@@ -160,6 +160,17 @@ module CC::Yaml
160
160
  end
161
161
  end
162
162
 
163
+ def node_wrapper_class(value)
164
+ case value
165
+ when ::Psych::Nodes::Scalar then ::CC::Yaml::Nodes::Scalar
166
+ when ::Psych::Nodes::Mapping then ::CC::Yaml::Nodes::OpenMapping
167
+ when ::Psych::Nodes::Sequence then ::CC::Yaml::Nodes::Sequence
168
+ when ::Psych::Nodes::Document then ::CC::Yaml::Nodes::OpenMapping
169
+ when ::Psych::Nodes::Stream then ::CC::Yaml::Nodes::Sequence
170
+ else raise ArgumentError, "Can't coerce #{value.inspect}"
171
+ end
172
+ end
173
+
163
174
  def simple(value)
164
175
  case value
165
176
  when ::Psych::Nodes::Scalar then value.value
@@ -1,5 +1,5 @@
1
1
  module CC
2
2
  module Yaml
3
- VERSION = "0.10.1".freeze
3
+ VERSION = "0.10.2".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Climate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-07 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: secure_string