yaml_master 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf6bb10efe0b9d8174aaeeac4d496bfb615ecd75
4
+ data.tar.gz: 40ed206f16f5a8c257ee1b3177c0c2a4c8379486
5
+ SHA512:
6
+ metadata.gz: 72044d3a058cca0e3194fd8e559826f45fb8356a81bd6435212e24fbe504c4b0b3915c25d8927fbaec04f67b07de26092e96d15e55223552c54c507a98aae7d4
7
+ data.tar.gz: ea18452f7cef940744971b30960704e49cabccd8b8e13be8e1343c59788d418e7efb0d8b2a90b2710ab8a0cc871c864a7aa1a7e82da52365c370ee8212805454
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yaml_master.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # YamlMaster
2
+
3
+ This gem is helper of yaml file generation from single master yaml file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'yaml_master'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install yaml_master
20
+
21
+ ## Usage
22
+
23
+ Write master.yml
24
+
25
+ ```yaml
26
+ yaml_master:
27
+ database_yml: <%= ENV["CONFIG_DIR"] %>/database.yml
28
+ embulk_yml: <%= ENV["CONFIG_DIR"] %>/embulk.yml
29
+
30
+ database_config: &database_config
31
+ development: &database_development
32
+ adapter: mysql2
33
+ encoding: utf8
34
+ database: development
35
+ pool: 5
36
+ host: &database_development_host
37
+ username: &database_development_username root
38
+ password: &database_development_password
39
+ socket: /tmp/mysql.sock
40
+
41
+ test: &database_test
42
+ adapter: mysql2
43
+ encoding: utf8
44
+ database: test
45
+ host: &database_test_host
46
+ username: &database_test_username root
47
+ password: &database_test_password
48
+
49
+ production: &database_production
50
+ adapter: mysql2
51
+ encoding: utf8
52
+ database: production
53
+ pool: 5
54
+ host: &database_production_host "192.168.1.100"
55
+ username: &database_production_username root
56
+ password: &database_production_password
57
+ socket: /tmp/mysql.sock
58
+
59
+
60
+ data:
61
+ database_yml:
62
+ <<: *database_config
63
+
64
+ embulk_yml:
65
+ in:
66
+ type: file
67
+ path_prefix: example.csv
68
+ parser:
69
+ type: csv
70
+ skip_header_lines: 1
71
+ columns:
72
+ - {name: key_name, type: string}
73
+ - {name: day, type: timestamp, format: '%Y-%m-%d'}
74
+ - {name: new_clients, type: long}
75
+
76
+ out:
77
+ type: mysql
78
+ host: *database_<%= ENV["RAILS_ENV"] %>_host
79
+ user: *database_<%= ENV["RAILS_ENV"] %>_username
80
+ password: *database_<%= ENV["RAILS_ENV"] %>_password
81
+ database: my_database
82
+ table: my_table
83
+ mode: insert
84
+ ```
85
+
86
+ execute command.
87
+
88
+ ```sh
89
+ $ RAILS_ENV=production CONFIG_DIR="." yaml_master -m master.yml --all
90
+ ```
91
+
92
+ outputs is following.
93
+
94
+ ```yaml
95
+ # ./database.yml
96
+
97
+ ---
98
+ development:
99
+ adapter: mysql2
100
+ encoding: utf8
101
+ database: development
102
+ pool: 5
103
+ host:
104
+ username: root
105
+ password:
106
+ socket: "/tmp/mysql.sock"
107
+ test:
108
+ adapter: mysql2
109
+ encoding: utf8
110
+ database: test
111
+ host:
112
+ username: root
113
+ password:
114
+ production:
115
+ adapter: mysql2
116
+ encoding: utf8
117
+ database: production
118
+ pool: 5
119
+ host: 192.168.1.100
120
+ username: root
121
+ password:
122
+ socket: "/tmp/mysql.sock"
123
+ ```
124
+
125
+ ```yaml
126
+ # ./embulk.yml
127
+
128
+ ---
129
+ in:
130
+ type: file
131
+ path_prefix: example.csv
132
+ parser:
133
+ type: csv
134
+ skip_header_lines: 1
135
+ columns:
136
+ - name: key_name
137
+ type: string
138
+ - name: day
139
+ type: timestamp
140
+ format: "%Y-%m-%d"
141
+ - name: new_clients
142
+ type: long
143
+ out:
144
+ type: mysql
145
+ host: 192.168.1.100
146
+ user: root
147
+ password:
148
+ database: my_database
149
+ table: my_table
150
+ mode: insert
151
+ ```
152
+
153
+ ## Development
154
+
155
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
156
+
157
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
158
+
159
+ ## Contributing
160
+
161
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joker1007/yaml_master.
162
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yaml_master"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/yaml_master ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "yaml_master"
4
+ require "slop"
5
+
6
+ opts = Slop.parse do |o|
7
+ o.string '-m', '--master', 'master yaml file'
8
+ o.string '-k', '--key', 'target yaml key (in data: block)'
9
+ o.string '-o', '--output', 'output filename'
10
+ o.bool '-a', '--all', 'target all key (defined in yaml_master: block)'
11
+ o.bool '-h', '--help', 'display this help'
12
+ o.on '--version', 'print the version' do
13
+ puts YamlMaster::VERSION
14
+ exit
15
+ end
16
+ end
17
+
18
+ options = opts.to_hash
19
+
20
+ if options[:help]
21
+ puts opts
22
+ exit
23
+ end
24
+
25
+ unless options[:master]
26
+ raise "--master options is necessary"
27
+ end
28
+
29
+ yaml_master = YamlMaster.new(options[:master])
30
+
31
+ if options[:all]
32
+ yaml_master.generate_all
33
+ else
34
+ yaml_master.generate(options[:key], options[:output])
35
+ end
@@ -0,0 +1,3 @@
1
+ class YamlMaster
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ require "yaml_master/version"
2
+
3
+ require "yaml"
4
+ require "erb"
5
+
6
+ class YamlMaster
7
+ attr_reader :master
8
+
9
+ def initialize(io_or_filename)
10
+ data =
11
+ if io_or_filename.is_a?(IO)
12
+ ERB.new(io_or_filename.read).result
13
+ else
14
+ ERB.new(File.read(io_or_filename)).result
15
+ end
16
+
17
+ @master = YAML.load(data)
18
+ raise "yaml_master key is necessary on toplevel" unless @master["yaml_master"]
19
+ raise "data key is necessary on toplevel" unless @master["data"]
20
+ end
21
+
22
+ def generate(key, output)
23
+ output_file = File.open(output, 'w')
24
+ YAML.dump(@master["data"][key], output_file)
25
+ output_file.close
26
+ end
27
+
28
+ def generate_all
29
+ @master["yaml_master"].each do |key, output|
30
+ generate(key, output)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yaml_master/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yaml_master"
8
+ spec.version = YamlMaster::VERSION
9
+ spec.authors = ["joker1007"]
10
+ spec.email = ["kakyoin.hierophant@gmail.com"]
11
+
12
+ spec.summary = %q{Helper of YAML file generation from single master YAML file}
13
+ spec.description = %q{Helper of YAML file generation from single master YAML file}
14
+ spec.homepage = "https://github.com/joker1007/yaml_master"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "slop"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "fakefs"
27
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaml_master
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - joker1007
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakefs
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Helper of YAML file generation from single master YAML file
84
+ email:
85
+ - kakyoin.hierophant@gmail.com
86
+ executables:
87
+ - yaml_master
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - exe/yaml_master
100
+ - lib/yaml_master.rb
101
+ - lib/yaml_master/version.rb
102
+ - yaml_master.gemspec
103
+ homepage: https://github.com/joker1007/yaml_master
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.8
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Helper of YAML file generation from single master YAML file
126
+ test_files: []