codeclimate-yaml 0.2.3 → 0.3.0

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: 8744a4c6ac64def6988bfdcd0b4ffb820e3d54ee
4
- data.tar.gz: 1e6901cf5ed4cdd3cf28fcfb7e7f25728145ad2d
3
+ metadata.gz: 71d782fa25bad738efd94fcc20f94902ac73d485
4
+ data.tar.gz: c22fdb5275b93887fefd1f6cb11a925089fd4a30
5
5
  SHA512:
6
- metadata.gz: 5c1ea958544066b658210a893375fef2137cec9f2ec62a5b236b59e8336cd3c65679d68b216fbc4a696412c87d2ce7258e3a1ddc1775b23387339142ce3337ba
7
- data.tar.gz: d8b3704063ac92cdbf72437d354ac3c5c99ddb9fdfa213f4972fd05bd5e7a14eef461b528caedde8f81fb4fd0bfb1eea9482ebe3c6045a5bae2a3b0c2d7fa3bf
6
+ metadata.gz: e876bb9daf725313ac2ded6d0ded54464b4bfe57e38e4dff07aaf371d2daa51dd646dd19fd3bdc4202f3a4c05c80f1f55ede032e8cad96c6a388a4f23b01c7b3
7
+ data.tar.gz: bc1ff4e054002bb4b3c100805100de89adee6fd9438538860134d3a2d3c61865299f43004f69f74b53044bfc72cab9d7f2965c1d14ace12df4181acf2a4f0a83
@@ -10,6 +10,7 @@ module CC
10
10
  autoload :GlobList, "cc/yaml/nodes/glob_list"
11
11
  autoload :LanguageList, "cc/yaml/nodes/language_list"
12
12
  autoload :Mapping, "cc/yaml/nodes/mapping"
13
+ autoload :NestedConfig, "cc/yaml/nodes/nested_config"
13
14
  autoload :Node, "cc/yaml/nodes/node"
14
15
  autoload :OpenMapping, "cc/yaml/nodes/open_mapping"
15
16
  autoload :Ratings, "cc/yaml/nodes/ratings"
@@ -1,7 +1,7 @@
1
1
  module CC
2
2
  module Yaml
3
3
  module Nodes
4
- class EngineConfig < OpenMapping
4
+ class EngineConfig < NestedConfig
5
5
  prefix_scalar :file
6
6
  end
7
7
  end
@@ -35,7 +35,7 @@ module CC::Yaml
35
35
  define_method("#{key}?") { | | !!self[key] } unless method_defined? "#{key}?"
36
36
  end
37
37
 
38
- def self.subnode_for(key)
38
+ def self.subnode_for_key(key)
39
39
  mapping[aliases.fetch(key.to_s, key.to_s)]
40
40
  end
41
41
 
@@ -72,13 +72,12 @@ module CC::Yaml
72
72
  end
73
73
 
74
74
  def visit_key_value(visitor, key, value)
75
- node = subnode_for(key)
76
- self[key] = node
77
- visitor.accept(node, value)
75
+ node = subnode_for_key(key)
76
+ assign_node_and_visit(node, key, value, visitor)
78
77
  end
79
78
 
80
79
  def set_warnings(key)
81
- if subnode_for(key)
80
+ if subnode_for_key(key)
82
81
  check_duplicates(key)
83
82
  else
84
83
  warning("unexpected key %p, dropping", key)
@@ -114,8 +113,8 @@ module CC::Yaml
114
113
  self.class.mapping.include? key
115
114
  end
116
115
 
117
- def subnode_for(key)
118
- type = self.class.subnode_for(key)
116
+ def subnode_for_key(key)
117
+ type = self.class.subnode_for_key(key)
119
118
  type.new(self) if type
120
119
  end
121
120
 
@@ -141,7 +140,7 @@ module CC::Yaml
141
140
  def verify_required
142
141
  self.class.required.each do |key|
143
142
  next if @mapping.include? key
144
- type = self.class.subnode_for(key)
143
+ type = self.class.subnode_for_key(key)
145
144
  if type.has_default?
146
145
  warning "missing key %p, defaulting to %p", key, type.default
147
146
  @mapping[key] = type.new(self)
@@ -183,6 +182,11 @@ module CC::Yaml
183
182
 
184
183
  protected
185
184
 
185
+ def assign_node_and_visit(node, key, value, visitor)
186
+ self[key] = node
187
+ visitor.accept(node, value)
188
+ end
189
+
186
190
  def dup_values
187
191
  duped_mapping = @mapping.map { |key, value| [key.dup, value.dup] }
188
192
  @mapping = Hash[duped_mapping]
@@ -0,0 +1,24 @@
1
+ module CC
2
+ module Yaml
3
+ module Nodes
4
+ class NestedConfig < OpenMapping
5
+ def visit_key_value(visitor, key, value)
6
+ node = subnode_for_pair(key, value)
7
+ assign_node_and_visit(node, key, value, visitor)
8
+ end
9
+
10
+ protected
11
+
12
+ def subnode_for_pair(key, value)
13
+ if value.is_a?(::Psych::Nodes::Mapping)
14
+ NestedConfig.new(self)
15
+ elsif value.is_a?(::Psych::Nodes::Sequence)
16
+ Sequence.new(self)
17
+ else
18
+ subnode_for_key(key)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -6,7 +6,7 @@ module CC::Yaml
6
6
  @default_type ||= superclass.respond_to?(:default_type) ? superclass.default_type : Scalar
7
7
  end
8
8
 
9
- def self.subnode_for(key)
9
+ def self.subnode_for_key(key)
10
10
  super(key) || default_type
11
11
  end
12
12
 
@@ -1,5 +1,5 @@
1
1
  module CC
2
2
  module Yaml
3
- VERSION = "0.2.3".freeze
3
+ VERSION = "0.3.0".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.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Climate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-30 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: secure_string
@@ -55,6 +55,7 @@ files:
55
55
  - lib/cc/yaml/nodes/glob_list.rb
56
56
  - lib/cc/yaml/nodes/language_list.rb
57
57
  - lib/cc/yaml/nodes/mapping.rb
58
+ - lib/cc/yaml/nodes/nested_config.rb
58
59
  - lib/cc/yaml/nodes/node.rb
59
60
  - lib/cc/yaml/nodes/open_mapping.rb
60
61
  - lib/cc/yaml/nodes/ratings.rb