codeclimate-yaml 0.9.0 → 0.10.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c28a3785dba022ee6a05b05d61a0fe074fec7e6
|
4
|
+
data.tar.gz: 9b0396f71bed5e81d13d067c46aeff6df87d5457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d336af7276f0a55d990bde2675f6da8cd9a76937143b47e28d135af47bf2bc30f7aaaec150aad017ec496418b62faf8b32c972d36c5e36950c0742a0e284264
|
7
|
+
data.tar.gz: 962fe7dfabc7b31d942527ab4ed783fe83f4b43d5ef1c09689d5e73f6d371a7221fad0cf08e88089bcef59bd1bed46283c6469e69ff21032dba2e3bbab858d5d
|
data/lib/cc/yaml/nodes.rb
CHANGED
@@ -3,9 +3,12 @@ module CC
|
|
3
3
|
module Nodes
|
4
4
|
autoload :Check, "cc/yaml/nodes/check"
|
5
5
|
autoload :Checks, "cc/yaml/nodes/checks"
|
6
|
+
autoload :Dependencies, "cc/yaml/nodes/dependencies"
|
6
7
|
autoload :Engine, "cc/yaml/nodes/engine"
|
7
8
|
autoload :EngineConfig, "cc/yaml/nodes/engine_config"
|
8
9
|
autoload :EngineList, "cc/yaml/nodes/engine_list"
|
10
|
+
autoload :FileDependency, "cc/yaml/nodes/file_dependency"
|
11
|
+
autoload :FileDependencyList, "cc/yaml/nodes/file_dependency_list"
|
9
12
|
autoload :Glob, "cc/yaml/nodes/glob"
|
10
13
|
autoload :GlobList, "cc/yaml/nodes/glob_list"
|
11
14
|
autoload :LanguageList, "cc/yaml/nodes/language_list"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "pathname"
|
3
|
+
|
4
|
+
module CC
|
5
|
+
module Yaml
|
6
|
+
module Nodes
|
7
|
+
class FileDependency < Mapping
|
8
|
+
INVALID_URL_ERROR = "invalid URL: %s".freeze
|
9
|
+
EMPTY_PATH_ERROR = "path cannot be empty".freeze
|
10
|
+
ABSOLUTE_PATH_ERROR = "absolute path \"%s\" is invalid".freeze
|
11
|
+
PARENT_PATH_ERROR = "relative path elements in \"%s\" are invalid: use \"%s\" instead".freeze
|
12
|
+
|
13
|
+
map :url, to: Scalar[:str], required: true
|
14
|
+
map :path, to: Scalar[:str], required: true
|
15
|
+
|
16
|
+
def visit_scalar(_visitor, type, value_node, _implicit = true)
|
17
|
+
if type == :str
|
18
|
+
if valid_url?(value_node.value)
|
19
|
+
self.url = url_node_from_url(value_node.value)
|
20
|
+
else
|
21
|
+
error(format(INVALID_URL_ERROR, value_node.value))
|
22
|
+
end
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def verify
|
29
|
+
if !url.nil? && path.nil?
|
30
|
+
self.path = path_node_from_url(url.value)
|
31
|
+
end
|
32
|
+
error(format(INVALID_URL_ERROR, url.value)) if url && !valid_url?(url.value)
|
33
|
+
validate_path(path.value) if path
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def valid_url?(url)
|
40
|
+
uri = URI.parse(url)
|
41
|
+
uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
|
42
|
+
rescue URI::InvalidUriError
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_path(path)
|
47
|
+
if path.nil? || path.length.zero?
|
48
|
+
return error(EMPTY_PATH_ERROR)
|
49
|
+
end
|
50
|
+
|
51
|
+
pathname = Pathname.new(path)
|
52
|
+
if pathname.absolute?
|
53
|
+
error(format(ABSOLUTE_PATH_ERROR, path))
|
54
|
+
end
|
55
|
+
if pathname.cleanpath.to_s != pathname.to_s || path.include?("..")
|
56
|
+
error(format(PARENT_PATH_ERROR, path, pathname.cleanpath.to_s))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def url_node_from_url(url)
|
61
|
+
node = Scalar.new(self)
|
62
|
+
node.value = url
|
63
|
+
node
|
64
|
+
end
|
65
|
+
|
66
|
+
def path_node_from_url(url)
|
67
|
+
node = Scalar.new(self)
|
68
|
+
node.value = File.basename(URI.parse(url).path)
|
69
|
+
node
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/cc/yaml/nodes/root.rb
CHANGED
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.10.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: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: secure_string
|
@@ -48,9 +48,12 @@ files:
|
|
48
48
|
- lib/cc/yaml/nodes.rb
|
49
49
|
- lib/cc/yaml/nodes/check.rb
|
50
50
|
- lib/cc/yaml/nodes/checks.rb
|
51
|
+
- lib/cc/yaml/nodes/dependencies.rb
|
51
52
|
- lib/cc/yaml/nodes/engine.rb
|
52
53
|
- lib/cc/yaml/nodes/engine_config.rb
|
53
54
|
- lib/cc/yaml/nodes/engine_list.rb
|
55
|
+
- lib/cc/yaml/nodes/file_dependency.rb
|
56
|
+
- lib/cc/yaml/nodes/file_dependency_list.rb
|
54
57
|
- lib/cc/yaml/nodes/glob.rb
|
55
58
|
- lib/cc/yaml/nodes/glob_list.rb
|
56
59
|
- lib/cc/yaml/nodes/language_list.rb
|