yaml_master 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/README.md +45 -2
- data/exe/yaml_master +2 -1
- data/lib/yaml_master/version.rb +1 -1
- data/lib/yaml_master.rb +23 -4
- 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: 37c428457e359817b6734d3b070b252cf44df8e8
|
4
|
+
data.tar.gz: d997fcfd8ea78e90be3da458323c8c6c0f350e17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e5eb100fb503983f9c34f936120c4b3a6fb53b8a157b2d3cfbb6d68dea0c33171056484d9f55d53a089b448aed17a3154e2cca6f03fca60693a05582162627d
|
7
|
+
data.tar.gz: 75eb14935e28563c4607527d0e6b7efb148cfaa055f448631c4f6147d495ad0d139f22363eed873af55eec0cbae4ba646e066b2c864f8527cc0f5ea9b445ce40
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# YamlMaster
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/yaml_master.svg)](https://badge.fury.io/rb/yaml_master)
|
3
|
+
[![Build Status](https://travis-ci.org/joker1007/yaml_master.svg)](https://travis-ci.org/joker1007/yaml_master)
|
2
4
|
|
3
5
|
This gem is helper of yaml file generation from single master yaml file.
|
4
6
|
|
@@ -20,7 +22,20 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
|
25
|
+
### command help
|
26
|
+
```
|
27
|
+
Usage: yaml_master [options]
|
28
|
+
-m, --master master yaml file
|
29
|
+
-k, --key single generate target key (in data: block)
|
30
|
+
-o, --output output filename for single generate target
|
31
|
+
-a, --all target all key (defined in yaml_master: block)
|
32
|
+
-p, --properties set property (--properties="NAME=VALUE,NAME=VALUE" or -p "NAME=VALUE" -p "NAME=VALUE")
|
33
|
+
-h, --help display this help
|
34
|
+
-v, --verbose verbose mode
|
35
|
+
--version print the version
|
36
|
+
```
|
37
|
+
|
38
|
+
at first, Write master.yml
|
24
39
|
|
25
40
|
```yaml
|
26
41
|
yaml_master:
|
@@ -83,8 +98,36 @@ data:
|
|
83
98
|
mode: insert
|
84
99
|
```
|
85
100
|
|
86
|
-
|
101
|
+
### single output
|
102
|
+
```sh
|
103
|
+
$ RAILS_ENV=production CONFIG_DIR="." yaml_master -m master.yml -k embulk_yml -o embulk_config.yml
|
104
|
+
```
|
105
|
+
|
106
|
+
```yaml
|
107
|
+
# ./embulk_config.yml
|
108
|
+
|
109
|
+
in:
|
110
|
+
type: file
|
111
|
+
path_prefix: example.csv
|
112
|
+
parser:
|
113
|
+
type: csv
|
114
|
+
skip_header_lines: 1
|
115
|
+
columns:
|
116
|
+
- {name: key_name, type: string}
|
117
|
+
- {name: day, type: timestamp, format: '%Y-%m-%d'}
|
118
|
+
- {name: new_clients, type: long}
|
119
|
+
|
120
|
+
out:
|
121
|
+
type: mysql
|
122
|
+
host: *database_<%= ENV["RAILS_ENV"] %>_host
|
123
|
+
user: *database_<%= ENV["RAILS_ENV"] %>_username
|
124
|
+
password: *database_<%= ENV["RAILS_ENV"] %>_password
|
125
|
+
database: my_database
|
126
|
+
table: my_table
|
127
|
+
mode: insert
|
128
|
+
```
|
87
129
|
|
130
|
+
### all output
|
88
131
|
```sh
|
89
132
|
$ RAILS_ENV=production CONFIG_DIR="." yaml_master -m master.yml --all
|
90
133
|
```
|
data/exe/yaml_master
CHANGED
@@ -8,6 +8,7 @@ opts = Slop.parse(strict: true) do
|
|
8
8
|
on 'k', 'key=', 'single generate target key (in data: block)'
|
9
9
|
on 'o', 'output=', 'output filename for single generate target'
|
10
10
|
on 'a', 'all', 'target all key (defined in yaml_master: block)'
|
11
|
+
on 'p', 'properties=', 'set property (--properties="NAME=VALUE,NAME=VALUE" or -p "NAME=VALUE" -p "NAME=VALUE")', as: Array
|
11
12
|
on 'h', 'help', 'display this help'
|
12
13
|
on 'v', 'verbose', 'verbose mode'
|
13
14
|
on '--version', 'print the version' do
|
@@ -35,7 +36,7 @@ if options[:all].nil? && options[:key].nil?
|
|
35
36
|
exit 1
|
36
37
|
end
|
37
38
|
|
38
|
-
yaml_master = YamlMaster.new(options[:master])
|
39
|
+
yaml_master = YamlMaster.new(options[:master], options[:properties])
|
39
40
|
|
40
41
|
if options[:all]
|
41
42
|
yaml_master.generate_all(verbose: options[:verbose])
|
data/lib/yaml_master/version.rb
CHANGED
data/lib/yaml_master.rb
CHANGED
@@ -15,12 +15,14 @@ class YamlMaster
|
|
15
15
|
super("cannot fetch key \"#{key}\" from\n#{data.pretty_inspect}")
|
16
16
|
end
|
17
17
|
end
|
18
|
+
class PropertyParseError < StandardError; end
|
18
19
|
|
19
|
-
attr_reader :master, :master_path
|
20
|
+
attr_reader :master, :master_path, :properties
|
20
21
|
|
21
|
-
def initialize(io_or_filename)
|
22
|
-
|
23
|
-
|
22
|
+
def initialize(io_or_filename, property_strings = [])
|
23
|
+
parse_properties(property_strings)
|
24
|
+
|
25
|
+
embedded_methods_binding = EmbeddedMethods.new(self).get_binding
|
24
26
|
data =
|
25
27
|
if io_or_filename.is_a?(IO)
|
26
28
|
ERB.new(io_or_filename.read).result(embedded_methods_binding)
|
@@ -74,6 +76,15 @@ class YamlMaster
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
79
|
+
def parse_properties(property_strings)
|
80
|
+
@properties = {}
|
81
|
+
property_strings.each_with_object(@properties) do |str, hash|
|
82
|
+
key, value = str.split("=")
|
83
|
+
raise PropertyParseError.new("#{str} is invalid format") unless key && value
|
84
|
+
hash[key] = value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
77
88
|
class EmbeddedMethods
|
78
89
|
def initialize(yaml_master)
|
79
90
|
@yaml_master = yaml_master
|
@@ -83,6 +94,10 @@ class YamlMaster
|
|
83
94
|
Pathname(@yaml_master.master_path)
|
84
95
|
end
|
85
96
|
|
97
|
+
def properties
|
98
|
+
@yaml_master.properties
|
99
|
+
end
|
100
|
+
|
86
101
|
def user_home
|
87
102
|
Pathname(ENV["HOME"])
|
88
103
|
end
|
@@ -91,5 +106,9 @@ class YamlMaster
|
|
91
106
|
return nil unless File.exist?(path)
|
92
107
|
File.read(path)
|
93
108
|
end
|
109
|
+
|
110
|
+
def get_binding
|
111
|
+
binding
|
112
|
+
end
|
94
113
|
end
|
95
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_master
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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-12-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|