codeclimate-yaml 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cc/yaml/nodes/engine_list.rb +23 -0
- data/lib/cc/yaml/nodes/mapping.rb +3 -3
- data/lib/cc/yaml/nodes/node.rb +5 -5
- data/lib/cc/yaml/nodes/root.rb +4 -0
- data/lib/cc/yaml/parser/psych.rb +19 -18
- data/lib/cc/yaml/serializer/generic.rb +6 -6
- data/lib/cc/yaml/serializer/json.rb +8 -8
- data/lib/cc/yaml/version.rb +1 -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: a7245f6f455befe3f6b8ca5a7d5db3c0cc90f94d
|
4
|
+
data.tar.gz: 5919951b30ab401f965b8b75041be0b5e23494e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5007979ccd4e0a85e85fc306ba9c6ba95a191442efb4ddab20cc6e60283f82a97c7b1ab87ade729f167904fa24842923f742cee4ed9c92b6a8bbad0183cab20
|
7
|
+
data.tar.gz: 0bf4693e9accf963178411d706f0629e1439c8d15fd2173f2e11e504e54bbeb0b567bb525d8fe6e578df8c993a8db754cc313682e25585bb4430a0967dc2a915
|
@@ -2,7 +2,30 @@ module CC
|
|
2
2
|
module Yaml
|
3
3
|
module Nodes
|
4
4
|
class EngineList < OpenMapping
|
5
|
+
GENERIC_ERROR_MESSAGE = "The engines key should be a mapping from engine name to engine config.".freeze
|
6
|
+
EMPTY_ERROR_MESSAGE = "The engines key cannot be empty.".freeze
|
7
|
+
|
5
8
|
default_type Engine
|
9
|
+
|
10
|
+
def verify
|
11
|
+
super
|
12
|
+
verify_not_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
def visit_unexpected(_visitor, _value, message = nil)
|
16
|
+
if message
|
17
|
+
message = message << ". #{GENERIC_ERROR_MESSAGE}"
|
18
|
+
else
|
19
|
+
message = GENERIC_ERROR_MESSAGE
|
20
|
+
end
|
21
|
+
error(message)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def verify_not_empty
|
27
|
+
error(EMPTY_ERROR_MESSAGE) if mapping.keys.empty? && errors.empty?
|
28
|
+
end
|
6
29
|
end
|
7
30
|
end
|
8
31
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module CC::Yaml
|
2
2
|
module Nodes
|
3
3
|
class Mapping < Node
|
4
|
-
INCOMPATIBLE_KEYS_WARNING = "Use either a
|
4
|
+
INCOMPATIBLE_KEYS_WARNING = "Use either a languages key or an engines key, but not both. They are mutually exclusive.".freeze
|
5
5
|
|
6
6
|
def self.mapping
|
7
7
|
@mapping ||= superclass.respond_to?(:mapping) ? superclass.mapping.dup : {}
|
@@ -24,7 +24,7 @@ module CC::Yaml
|
|
24
24
|
when Symbol then aliases[key.to_s] = options[:to].to_s
|
25
25
|
when Module then mapping[key.to_s] = options[:to]
|
26
26
|
when nil then mapping[key.to_s] = Nodes[key]
|
27
|
-
else raise ArgumentError,
|
27
|
+
else raise ArgumentError, "unexpected value for to: %p" % options[:to]
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -153,7 +153,7 @@ module CC::Yaml
|
|
153
153
|
def verify_errors
|
154
154
|
@mapping.delete_if do |key, value|
|
155
155
|
if value.errors?
|
156
|
-
|
156
|
+
error "invalid %p section: %s", key, value.errors.join(", ")
|
157
157
|
true
|
158
158
|
end
|
159
159
|
end
|
data/lib/cc/yaml/nodes/node.rb
CHANGED
@@ -65,23 +65,23 @@ module CC
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def visit_mapping(visitor, value)
|
68
|
-
|
68
|
+
visit_unexpected(visitor, value, "unexpected mapping")
|
69
69
|
end
|
70
70
|
|
71
71
|
def visit_pair(visitor, key, value)
|
72
|
-
|
72
|
+
visit_unexpected(visitor, value, "unexpected pair")
|
73
73
|
end
|
74
74
|
|
75
75
|
def visit_scalar(visitor, type, value, implicit = true)
|
76
|
-
|
76
|
+
visit_unexpected(visitor, value, "unexpected scalar") unless type == :null
|
77
77
|
end
|
78
78
|
|
79
79
|
def visit_sequence(visitor, value)
|
80
|
-
|
80
|
+
visit_unexpected(visitor, value, "unexpected sequence")
|
81
81
|
end
|
82
82
|
|
83
83
|
def visit_child(visitor, value)
|
84
|
-
|
84
|
+
visit_unexpected(visitor, value, "unexpected child")
|
85
85
|
end
|
86
86
|
|
87
87
|
def respond_to_missing?(method, include_private = false)
|
data/lib/cc/yaml/nodes/root.rb
CHANGED
data/lib/cc/yaml/parser/psych.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "psych"
|
2
|
+
require "delegate"
|
3
3
|
|
4
4
|
module CC::Yaml
|
5
5
|
module Parser
|
@@ -37,14 +37,14 @@ module CC::Yaml
|
|
37
37
|
TRUE = /\A(?:y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)\z/
|
38
38
|
FALSE = /\A(?:n|N|no|No|NO|false|False|FALSE|off|Off|OFF)\z/
|
39
39
|
REGEXP = /\A!(?:ruby\/)?regexp\z/
|
40
|
-
REG_FLAGS = {
|
40
|
+
REG_FLAGS = { "i" => Regexp::IGNORECASE, "m" => Regexp::MULTILINE, "x" => Regexp::EXTENDED }
|
41
41
|
FORMATS = {
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
"!bool" => Regexp.union(TRUE, FALSE),
|
43
|
+
"!float" => ::Psych::ScalarScanner::FLOAT,
|
44
|
+
"!null" => /\A(:?~|null|Null|NULL|)\z/,
|
45
|
+
"!timestamp" => ::Psych::ScalarScanner::TIME,
|
46
|
+
"!int" => ::Psych::ScalarScanner::INTEGER,
|
47
|
+
"!regexp" => /\A\/(.*)\/([imx]*)\z/,
|
48
48
|
}
|
49
49
|
|
50
50
|
if defined? ::Psych::ClassLoader
|
@@ -87,11 +87,12 @@ module CC::Yaml
|
|
87
87
|
root.verify
|
88
88
|
root.warnings.clear
|
89
89
|
root.error("syntax error: %s", error.message)
|
90
|
+
root.parseable = false
|
90
91
|
root
|
91
92
|
end
|
92
93
|
|
93
94
|
def check_for_analysis_key(root)
|
94
|
-
unless root.engines? || root.languages?
|
95
|
+
unless root.engines? || root.languages? || root.errors.any?
|
95
96
|
root.error NO_ANALYSIS_KEY_FOUND_ERROR
|
96
97
|
end
|
97
98
|
end
|
@@ -127,10 +128,10 @@ module CC::Yaml
|
|
127
128
|
when SET then node.visit_sequence self, SetNode.new(value)
|
128
129
|
when SEQ then node.visit_sequence self, value
|
129
130
|
when nil
|
130
|
-
if value.children.size == 2 and value.children.first.value ==
|
131
|
+
if value.children.size == 2 and value.children.first.value == "secure"
|
131
132
|
secret_value = value.children.last
|
132
133
|
if secret_value.is_a? ::Psych::Nodes::Scalar
|
133
|
-
secret_value.tag ||=
|
134
|
+
secret_value.tag ||= "!secure"
|
134
135
|
node.visit_scalar(self, :secure, secret_value, false)
|
135
136
|
else
|
136
137
|
node.visit_unexpected(self, value, "secret value needs to be a string")
|
@@ -179,16 +180,16 @@ module CC::Yaml
|
|
179
180
|
|
180
181
|
def scalar_tag(value)
|
181
182
|
return value.tag if value.tag
|
182
|
-
return
|
183
|
+
return "!str" if value.quoted
|
183
184
|
FORMATS.each do |tag, format|
|
184
185
|
return tag if value.value =~ format
|
185
186
|
end
|
186
|
-
|
187
|
+
"!str"
|
187
188
|
end
|
188
189
|
|
189
190
|
def regexp(pattern)
|
190
191
|
return pattern if pattern.is_a? Regexp
|
191
|
-
return Regexp.new(pattern) unless pattern =~ FORMATS[
|
192
|
+
return Regexp.new(pattern) unless pattern =~ FORMATS["!regexp"]
|
192
193
|
flag = $2.chars.inject(0) { |f,c| f | REG_FLAGS.fetch(c, 0) }
|
193
194
|
Regexp.new($1, flag)
|
194
195
|
rescue RegexpError => error
|
@@ -198,15 +199,15 @@ module CC::Yaml
|
|
198
199
|
def cast(type, value)
|
199
200
|
case type
|
200
201
|
when :str then value.value
|
201
|
-
when :binary then value.value.unpack(
|
202
|
+
when :binary then value.value.unpack("m").first
|
202
203
|
when :bool then value.value !~ FALSE
|
203
204
|
when :float then Float @scanner.tokenize(value.value)
|
204
205
|
when :int then Integer @scanner.tokenize(value.value)
|
205
206
|
when :time then @scanner.parse_time(value.value)
|
206
|
-
when :secure then SecureString.new(value.value, value.tag !=
|
207
|
+
when :secure then SecureString.new(value.value, value.tag != "!decrypted")
|
207
208
|
when :regexp then regexp(value.value)
|
208
209
|
when :null then nil
|
209
|
-
else raise ArgumentError,
|
210
|
+
else raise ArgumentError, "unknown scalar type %p" % type
|
210
211
|
end
|
211
212
|
end
|
212
213
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "secure_string"
|
2
2
|
|
3
3
|
module CC::Yaml
|
4
4
|
module Serializer
|
@@ -23,7 +23,7 @@ module CC::Yaml
|
|
23
23
|
when Nodes::Scalar then serialize_scalar(node)
|
24
24
|
when Nodes::Mapping then serialize_mapping(node)
|
25
25
|
when Nodes::Sequence then serialize_sequence(node)
|
26
|
-
else raise NotSupportedError,
|
26
|
+
else raise NotSupportedError, "do not know how to serialize %p" % node.class
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -57,13 +57,13 @@ module CC::Yaml
|
|
57
57
|
def serialize_secure(value)
|
58
58
|
case options[:secure]
|
59
59
|
when :decrypted
|
60
|
-
raise ArgumentError,
|
60
|
+
raise ArgumentError, "secure option is set decrypted, but a secure value is not decrypted" unless value.decrypted?
|
61
61
|
serialize_decrypted(value)
|
62
62
|
when :encrypted
|
63
|
-
raise ArgumentError,
|
63
|
+
raise ArgumentError, "secure option is set encrypted, but a secure value is not encrypted" unless value.encrypted?
|
64
64
|
serialize_encrypted(value)
|
65
65
|
else
|
66
|
-
raise ArgumentError,
|
66
|
+
raise ArgumentError, "unexpected value for secure option: %p" % options[:secure] if options[:secure]
|
67
67
|
value.encrypted? ? serialize_encrypted(value) : serialize_decrypted(value)
|
68
68
|
end
|
69
69
|
end
|
@@ -93,7 +93,7 @@ module CC::Yaml
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def serialize_value(node)
|
96
|
-
raise NotSupportedError,
|
96
|
+
raise NotSupportedError, "cannot serialize %p with %p" % [node.class, self.class]
|
97
97
|
end
|
98
98
|
|
99
99
|
def serialize_root(node)
|
@@ -16,7 +16,7 @@ module CC
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def serialize_float(value)
|
19
|
-
raise NotSupportedError,
|
19
|
+
raise NotSupportedError, "cannot serialize infinity as JSON" if value.infinite?
|
20
20
|
"#{value}"
|
21
21
|
end
|
22
22
|
|
@@ -29,15 +29,15 @@ module CC
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def serialize_str(value)
|
32
|
-
string = value.encode(
|
33
|
-
string.force_encoding(
|
32
|
+
string = value.encode("utf-8")
|
33
|
+
string.force_encoding("binary")
|
34
34
|
string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
|
35
|
-
string.force_encoding(
|
35
|
+
string.force_encoding("utf-8")
|
36
36
|
"\"#{string}\""
|
37
37
|
end
|
38
38
|
|
39
39
|
def serialize_binary(value)
|
40
|
-
raise NotSupportedError,
|
40
|
+
raise NotSupportedError, "cannot serialize binary data as JSON"
|
41
41
|
end
|
42
42
|
|
43
43
|
def serialize_bool(value)
|
@@ -45,11 +45,11 @@ module CC
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def serialize_mapping(node)
|
48
|
-
lines(
|
48
|
+
lines("{%s}", super.map { |key, value| key_value(key, value) })
|
49
49
|
end
|
50
50
|
|
51
51
|
def serialize_sequence(node)
|
52
|
-
lines(
|
52
|
+
lines("[%s]", super)
|
53
53
|
end
|
54
54
|
|
55
55
|
def key_value(key, value, wrapper = "%s")
|
@@ -58,7 +58,7 @@ module CC
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def lines(wrapper, lines)
|
61
|
-
return wrapper % lines.join(
|
61
|
+
return wrapper % lines.join(",") unless pretty?
|
62
62
|
return wrapper % "" if lines.empty?
|
63
63
|
return wrapper % " #{lines.first} " unless lines.size > 1 or lines.first.include?("\n") or lines.first.size > 50
|
64
64
|
lines = "\n " + lines.join(",\n").strip.gsub("\n", "\n ") + "\n"
|
data/lib/cc/yaml/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: secure_string
|