yaml_master 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/exe/yaml_master +20 -10
- data/lib/yaml_master/version.rb +1 -1
- data/lib/yaml_master.rb +47 -9
- data/yaml_master.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34993300413ebe4676e7cf80c868d219262334dc
|
4
|
+
data.tar.gz: 6ab8999f19b39b2d61116afea9bd67f406bc7b94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1096589dade1789f856a57e3bddd8b05ccf4a89c97965743a530b5f6d92efda5a9b25290c6260d0a66fd436ac57872a002b62f613fe9f07ba9f2668206326005
|
7
|
+
data.tar.gz: 282ed2538a8ef0c9fbc2deb54581f7402cc89d7805c788ccba37d8a604b486055debaf6ffe214a6d29efe00d649fabd7393da295fed56ae838c3cc613c0ad89f
|
data/.travis.yml
CHANGED
data/exe/yaml_master
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
require "yaml_master"
|
4
4
|
require "slop"
|
5
5
|
|
6
|
-
opts = Slop.parse do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
opts = Slop.parse(strict: true) do
|
7
|
+
on 'm', 'master=', 'master yaml file'
|
8
|
+
on 'k', 'key=', 'single generate target key (in data: block)'
|
9
|
+
on 'o', 'output=', 'output filename for single generate target'
|
10
|
+
on 'a', 'all', 'target all key (defined in yaml_master: block)'
|
11
|
+
on 'h', 'help', 'display this help'
|
12
|
+
on 'v', 'verbose', 'verbose mode'
|
13
|
+
on '--version', 'print the version' do
|
13
14
|
puts YamlMaster::VERSION
|
14
15
|
exit
|
15
16
|
end
|
@@ -23,13 +24,22 @@ if options[:help]
|
|
23
24
|
end
|
24
25
|
|
25
26
|
unless options[:master]
|
26
|
-
|
27
|
+
puts "--master options is necessary"
|
28
|
+
puts opts
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
if options[:all].nil? && options[:key].nil?
|
33
|
+
puts "--all or --key is necessary"
|
34
|
+
puts opts
|
35
|
+
exit 1
|
27
36
|
end
|
28
37
|
|
29
38
|
yaml_master = YamlMaster.new(options[:master])
|
30
39
|
|
31
40
|
if options[:all]
|
32
|
-
yaml_master.generate_all
|
41
|
+
yaml_master.generate_all(verbose: options[:verbose])
|
33
42
|
else
|
34
|
-
yaml_master.generate(options[:key], options[:output])
|
43
|
+
result = yaml_master.generate(options[:key], options[:output], {verbose: options[:verbose]})
|
44
|
+
puts result unless options[:output]
|
35
45
|
end
|
data/lib/yaml_master/version.rb
CHANGED
data/lib/yaml_master.rb
CHANGED
@@ -2,16 +2,24 @@ require "yaml_master/version"
|
|
2
2
|
|
3
3
|
require "yaml"
|
4
4
|
require "erb"
|
5
|
+
require "pathname"
|
6
|
+
|
7
|
+
YAML.add_domain_type(nil, "include") do |type, val|
|
8
|
+
YAML.load_file(val)
|
9
|
+
end
|
5
10
|
|
6
11
|
class YamlMaster
|
7
|
-
attr_reader :master
|
12
|
+
attr_reader :master, :master_path
|
8
13
|
|
9
14
|
def initialize(io_or_filename)
|
15
|
+
embedded_methods = EmbeddedMethods.new(self)
|
16
|
+
embedded_methods_binding = embedded_methods.instance_eval { binding }
|
10
17
|
data =
|
11
18
|
if io_or_filename.is_a?(IO)
|
12
|
-
ERB.new(io_or_filename.read).result
|
19
|
+
ERB.new(io_or_filename.read).result(embedded_methods_binding)
|
13
20
|
else
|
14
|
-
|
21
|
+
@master_path = File.expand_path(io_or_filename)
|
22
|
+
ERB.new(File.read(io_or_filename)).result(embedded_methods_binding)
|
15
23
|
end
|
16
24
|
|
17
25
|
@master = YAML.load(data)
|
@@ -19,15 +27,45 @@ class YamlMaster
|
|
19
27
|
raise "data key is necessary on toplevel" unless @master["data"]
|
20
28
|
end
|
21
29
|
|
22
|
-
def generate(key, output)
|
23
|
-
|
24
|
-
YAML.dump(
|
25
|
-
|
30
|
+
def generate(key, output, options = {})
|
31
|
+
puts "gen: #{output}" if options[:verbose]
|
32
|
+
yaml = YAML.dump(fetch_data_from_master(key))
|
33
|
+
|
34
|
+
return yaml unless output
|
35
|
+
|
36
|
+
File.open(output, 'w') do |f|
|
37
|
+
f.write(yaml)
|
38
|
+
end
|
26
39
|
end
|
27
40
|
|
28
|
-
def generate_all
|
41
|
+
def generate_all(options = {})
|
29
42
|
@master["yaml_master"].each do |key, output|
|
30
|
-
generate(key, output)
|
43
|
+
generate(key, output, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def fetch_data_from_master(key)
|
50
|
+
@master["data"].fetch(key)
|
51
|
+
end
|
52
|
+
|
53
|
+
class EmbeddedMethods
|
54
|
+
def initialize(yaml_master)
|
55
|
+
@yaml_master = yaml_master
|
56
|
+
end
|
57
|
+
|
58
|
+
def master_path
|
59
|
+
Pathname(@yaml_master.master_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
def user_home
|
63
|
+
Pathname(ENV["HOME"])
|
64
|
+
end
|
65
|
+
|
66
|
+
def read_file_if_exist(path)
|
67
|
+
return nil unless File.exist?(path)
|
68
|
+
File.read(path)
|
31
69
|
end
|
32
70
|
end
|
33
71
|
end
|
data/yaml_master.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "slop"
|
21
|
+
spec.add_runtime_dependency "slop", "~> 3.6"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.10"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_master
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.5.0
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Helper of YAML file generation from single master YAML file
|