fillparams 0.0.1

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: b88aeb7930519bfc66751d9f379ec588ce39b20d
4
+ data.tar.gz: 65d9c29154e466e7165d1ba30092cc4e4a518bb5
5
+ SHA512:
6
+ metadata.gz: 69be4a484fedad6c41448ca14119e1e21ae2ab55750e42aab0bb2e7d29158b3cabbe864c2360cd56d2f9c7d817be82fbce37749d32665c306502e715c15ad4fa
7
+ data.tar.gz: cb1b92e75f6fe49ce4d1490ef108174d4db3eed9e9bfb0f29233ea6d53d4b06a2da5b0e8395b21f1fb03440c518a490c4d37e8f46ab1c775fd46c5bfc3ea787a
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ .idea
23
+ mkmf.log
24
+ test.yml
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --profile
4
+ --order rand
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'FillParams/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fillparams'
8
+ spec.version = FillParams::VERSION
9
+ spec.authors = ['Krzysztof Hasiński', 'Justyna Wojtczak']
10
+ spec.email = ['krzysztof.hasinski+parameterhandler@gmail.com']
11
+ spec.summary = 'Parameters handler'
12
+ spec.description = 'A gem for filling in parameters automatically'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rspec-activemodel-mocks'
25
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Krzysztof Hasiński
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # FillParams
2
+
3
+ This tool allows you to manage ignored YAML parameters in your config files.
4
+ It is inspired by [Incenteev ParameterHandler](https://github.com/Incenteev/ParameterHandler).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fillparams'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fillparams
19
+
20
+ ## Usage
21
+
22
+ By default, the dist file is assumed to be in the same place than the parameters
23
+ file, suffixed by ``.dist``.
24
+
25
+ The script handler will ask you interactively for parameters which are missing
26
+ in the parameters file, using the value of the dist file as default value.
27
+ All prompted values are parsed as inline YAML, to allow you to define ``true``,
28
+ ``false``, ``null`` or numbers easily.
29
+
30
+ If fillparams is run in a non-interactive mode, the values of the dist file
31
+ will be used for missing parameters.
32
+
33
+ **Warning:** This parameters handler will overwrite any comments or spaces into
34
+ your parameters.yml file so handle with care. If you want to give format
35
+ and comments to your parameter's file you should do it on your dist version.
36
+
37
+ Basic usage is:
38
+
39
+ $ fillparams
40
+
41
+ This will look for a file called `init.yml`, which should contain:
42
+
43
+ files:
44
+ - some_config.yml
45
+ - config/database.yml
46
+ - more_configs.yml
47
+
48
+ fillparams will look for each of those files and a corresponding ``.dist`` file (ex. ``config/database.yml.dist``),
49
+ go through parameters and ask for the missing ones. Check ``fillparams --help`` for more options.
50
+
51
+ **Important:** fillparams will ask for parameters that are strings, numbers, arrays, nulls (nils) and booleans. For
52
+ hashes it will go deeper until it finds something to work on.
53
+
54
+ For example in file ``database.yml.dist``
55
+
56
+ development:
57
+ username: dbuser
58
+ host: localhost
59
+ fancy_options:
60
+ - a
61
+ - b
62
+ - c
63
+
64
+ it will ask for `username`, `host` and `fancy_options`, it **won't** ask for `development` itself as it can go deeper into nested options.
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it ( https://github.com/khasinski/fillparams/fork )
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
data/bin/fillparams ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # For running without installation:
4
+ # ruby -Ilib bin/fillparams
5
+
6
+ require 'optparse'
7
+ require 'ostruct'
8
+ require 'config_manager'
9
+ require 'parameter_filler'
10
+
11
+ options = OpenStruct.new
12
+ options.init_file = 'init.yml'
13
+ options.verbose = false
14
+ options.interactive = STDIN.isatty
15
+
16
+ OptionParser.new do |opts|
17
+ opts.banner = 'Usage: fillparams [-i init.yml] [-v] [-n]'
18
+
19
+ opts.on('-i', '--init [INIT_FILE]',
20
+ 'provide init file', '(list of configuration files to fill in)') do |init|
21
+ options.init_file = init
22
+ end
23
+
24
+ opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
25
+ options.verbose = v
26
+ end
27
+
28
+ opts.on('-n', '--non-interactive', 'Run without asking for parameters') do |n|
29
+ options.interactive = !n
30
+ end
31
+ end.parse!
32
+
33
+ conf = ConfigManager.new(options.init_file)
34
+ parameter_filler = ParameterFiller.new(conf.get_config_files, options.verbose, options.interactive)
35
+ parameter_filler.fill_file_list
data/init.yml ADDED
@@ -0,0 +1,2 @@
1
+ files:
2
+ - test.yml
@@ -0,0 +1,3 @@
1
+ module FillParams
2
+ VERSION = '0.0.1'
3
+ end
data/lib/FillParams.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'FillParams/version'
2
+
3
+ module FillParams
4
+
5
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+ require 'yaml'
3
+
4
+ class ConfigManager
5
+ attr_reader :init_file
6
+
7
+ def initialize(init_yml_file)
8
+ @init_file = load init_yml_file
9
+ end
10
+
11
+ def load yml_file
12
+ YAML.load_file(yml_file)
13
+ end
14
+
15
+ def get_config_files
16
+ @init_file && @init_file.has_key?('files') ? @init_file['files'] : []
17
+ end
18
+ end
19
+
@@ -0,0 +1,80 @@
1
+ require 'yaml'
2
+
3
+ class ParameterFiller
4
+
5
+ attr_reader :config_files
6
+ attr_reader :verbose
7
+ attr_reader :interactive
8
+
9
+ def initialize(files_list, verbose, interactive)
10
+ @config_files = files_list
11
+ @verbose = verbose
12
+ @interactive = interactive
13
+ end
14
+
15
+ def fill_file_list
16
+ @config_files.each do |file_name|
17
+ if verbose
18
+ puts 'Filling ' + file_name + '...'
19
+ end
20
+ fill_file file_name
21
+ end
22
+ end
23
+
24
+ def fill_file(file_name)
25
+ dist_file_name = file_name + '.dist'
26
+ setup_files(file_name, dist_file_name)
27
+ config_data = load_yaml_file file_name
28
+ dist_data = load_yaml_file dist_file_name
29
+ config_data = fill_parameters(config_data, dist_data)
30
+ File.write(file_name, config_data.to_yaml)
31
+ end
32
+
33
+ def load_yaml_file(file_name)
34
+ begin
35
+ data = YAML.load_file(file_name)
36
+ unless data
37
+ data = {}
38
+ end
39
+ rescue Exception => e
40
+ raise ArgumentError, 'Invalid YAML in config file ' + file_name unless data
41
+ end
42
+ data
43
+ end
44
+
45
+ def setup_files(file_name, dist_file_name)
46
+ raise ArgumentError, 'Dist file not found for ' + file_name unless File.file?(dist_file_name)
47
+ unless File.file?(file_name)
48
+ File.write(file_name, '')
49
+ end
50
+ return
51
+ end
52
+
53
+ def fill_parameters(data, dist_data)
54
+ dist_data.each do |key, value|
55
+ if !data.has_key?(key) && !dist_data[key].is_a?(Hash)
56
+ data[key] = ask_for_param(key, value)
57
+ end
58
+ if dist_data[key].is_a?(Hash)
59
+ unless data.has_key?(key)
60
+ data[key] = {}
61
+ end
62
+ data[key] = fill_parameters(data[key], dist_data[key])
63
+ end
64
+ end
65
+ data
66
+ end
67
+
68
+ def ask_for_param(key, default)
69
+ return default unless interactive
70
+ print "Key \"#{key}\" (default: #{default}): "
71
+ param = gets.chomp
72
+ if param.empty? || !interactive
73
+ param = default
74
+ else
75
+ param = YAML.load(param)
76
+ end
77
+ param
78
+ end
79
+ end
80
+
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ describe ParameterFiller do
3
+ pending "write it"
4
+ it 'should be true' do
5
+ expect(1).to eq 1
6
+ end
7
+ end
8
+
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ require 'rspec/active_model/mocks'
3
+
4
+ require 'parameter_filler.rb'
5
+
6
+ Bundler.setup
7
+
8
+ RSpec.configure do |config|
9
+ end
data/test.yml.dist ADDED
@@ -0,0 +1,9 @@
1
+ number: 1
2
+ float: 3.2
3
+ string: 'text'
4
+ array:
5
+ - "array_elem_1"
6
+ - "array_elem_2"
7
+ - array_elem_3: {'nested_obj_1':'text'}
8
+ object:
9
+ hash: "hash_value"
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fillparams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Krzysztof Hasiński
8
+ - Justyna Wojtczak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-activemodel-mocks
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: A gem for filling in parameters automatically
71
+ email:
72
+ - krzysztof.hasinski+parameterhandler@gmail.com
73
+ executables:
74
+ - fillparams
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rspec
80
+ - FillParams.gemspec
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/fillparams
86
+ - init.yml
87
+ - lib/FillParams.rb
88
+ - lib/FillParams/version.rb
89
+ - lib/config_manager.rb
90
+ - lib/parameter_filler.rb
91
+ - spec/foobar_spec.rb
92
+ - spec/spec_helper.rb
93
+ - test.yml.dist
94
+ homepage: ''
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Parameters handler
118
+ test_files:
119
+ - spec/foobar_spec.rb
120
+ - spec/spec_helper.rb