yaml_ref_resolver 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/lib/yaml_ref_resolver.rb +9 -0
- data/lib/yaml_ref_resolver/cli.rb +34 -4
- data/lib/yaml_ref_resolver/version.rb +1 -1
- data/yaml_ref_resolver.gemspec +2 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bde85a7d2b1b92b65b0051abd1c6e9535f6b131f
|
4
|
+
data.tar.gz: f8534e41555fea5e98559b7a0eb6d7dccc7bfcda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1cec765fde7612ee449c95a4f6a17538e58677c713c18bf0728972539321183a9cf86f6e803e8cad57701a6b7e6d10dd1006fba57cbb03e5cb8faf1680e1213
|
7
|
+
data.tar.gz: 4133d83aefc93efcdfa54dd55326845c78475a9713c5f51b36abb1bf2e30492fa7bf7eff66b337c2ed3711544c4dcf3ec4fedef8387b2edb54c766a0ba1c28e0
|
data/README.md
CHANGED
@@ -45,6 +45,28 @@ Optionally you can specify the key.
|
|
45
45
|
resolver = YamlRefResolver.new(key: '$import')
|
46
46
|
```
|
47
47
|
|
48
|
+
### CLI
|
49
|
+
|
50
|
+
Give an entry point yaml with `-i` or `--input` option.
|
51
|
+
|
52
|
+
```console
|
53
|
+
$ yaml_ref_resolver -i ./path/to/index.yaml
|
54
|
+
|
55
|
+
# dump to stdout
|
56
|
+
```
|
57
|
+
|
58
|
+
Optionally output file path with `-o` or `--output` can be given.
|
59
|
+
|
60
|
+
```console
|
61
|
+
$ yaml_ref_resolver -i ./path/to/index.yaml -o ./path/to/output.yaml
|
62
|
+
```
|
63
|
+
|
64
|
+
`-w` or `--watch` options watches referenced yaml files and dump whole resolved yaml when one of them changed.
|
65
|
+
|
66
|
+
```console
|
67
|
+
$ yaml_ref_resolver -i ./path/to/index.yaml -w
|
68
|
+
```
|
69
|
+
|
48
70
|
## Contributing
|
49
71
|
|
50
72
|
Bug reports and pull requests are very welcome on GitHub at https://github.com/Joe-noh/yaml_ref_resolver.
|
data/lib/yaml_ref_resolver.rb
CHANGED
@@ -14,6 +14,15 @@ class YamlRefResolver
|
|
14
14
|
resolve_refs(@yaml[entry_point], entry_point)
|
15
15
|
end
|
16
16
|
|
17
|
+
def reload(path)
|
18
|
+
@yaml.delete(path)
|
19
|
+
preload_ref_yamls(path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def files
|
23
|
+
@yaml.keys
|
24
|
+
end
|
25
|
+
|
17
26
|
private
|
18
27
|
|
19
28
|
def preload_ref_yamls(abs_path)
|
@@ -1,28 +1,50 @@
|
|
1
1
|
require "yaml_ref_resolver"
|
2
2
|
require "optparse"
|
3
|
+
require "filewatcher"
|
3
4
|
|
4
5
|
class YamlRefResolver
|
5
6
|
class CLI
|
6
7
|
def initialize
|
7
8
|
@opt = OptionParser.new
|
8
9
|
@input = nil
|
10
|
+
@output = nil
|
11
|
+
@watch = false
|
9
12
|
|
10
13
|
define_options
|
11
14
|
end
|
12
15
|
|
13
16
|
def run(argv)
|
14
17
|
@opt.parse!(argv)
|
15
|
-
|
16
18
|
validate_input_path
|
17
19
|
|
18
|
-
|
19
|
-
yaml = resolver.resolve(@input)
|
20
|
+
resolve_and_dump
|
20
21
|
|
21
|
-
|
22
|
+
if @watch
|
23
|
+
FileWatcher.new(resolver.files).watch do |filename|
|
24
|
+
resolver.reload(File.expand_path(filename))
|
25
|
+
resolve_and_dump
|
26
|
+
end
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
30
|
private
|
25
31
|
|
32
|
+
def resolve_and_dump
|
33
|
+
yaml = resolver.resolve(@input).to_yaml
|
34
|
+
|
35
|
+
if @output
|
36
|
+
File.open(@output, "w") do |f|
|
37
|
+
f.puts yaml
|
38
|
+
end
|
39
|
+
else
|
40
|
+
$stdout.write yaml
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def resolver
|
45
|
+
@resolver ||= YamlRefResolver.new(key: @key)
|
46
|
+
end
|
47
|
+
|
26
48
|
def define_options
|
27
49
|
@opt.on('-v', '--version', 'show version number.') do
|
28
50
|
puts "YamlRefResolver v#{YamlRefResolver::VERSION}"
|
@@ -33,9 +55,17 @@ class YamlRefResolver
|
|
33
55
|
@input = path
|
34
56
|
end
|
35
57
|
|
58
|
+
@opt.on('-o path', '--output', 'output file path') do |path|
|
59
|
+
@output = path
|
60
|
+
end
|
61
|
+
|
36
62
|
@opt.on('-k key', '--key', 'key to be resolved. $ref by default') do |key|
|
37
63
|
@key = key
|
38
64
|
end
|
65
|
+
|
66
|
+
@opt.on('-w', '--watch', 'glob pattern to watch cahnges') do
|
67
|
+
@watch = true
|
68
|
+
end
|
39
69
|
end
|
40
70
|
|
41
71
|
def validate_input_path
|
data/yaml_ref_resolver.gemspec
CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.required_ruby_version = '>= 2.0.0'
|
24
24
|
|
25
|
+
spec.add_dependency "filewatcher", "~> 0.5"
|
26
|
+
|
25
27
|
spec.add_development_dependency "bundler", "~> 1.14"
|
26
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
29
|
spec.add_development_dependency "minitest", "~> 5.0"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_ref_resolver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe-noh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: filewatcher
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
121
|
version: '0'
|
108
122
|
requirements: []
|
109
123
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.6.8
|
111
125
|
signing_key:
|
112
126
|
specification_version: 4
|
113
127
|
summary: Resolves referencing to other YAML files.
|