fillparams 0.0.3 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 40bc376f336e9f6c067ebe6a524d8d4ab7d7ea81
4
- data.tar.gz: 5f889ec0330aee3cdca5ec9aaa4a7d356fbfaf29
2
+ SHA256:
3
+ metadata.gz: 626edd4bcbbc93f3aa0c6fcdbd419199b618e4b36f5f3414a8318fe7cf9f0089
4
+ data.tar.gz: bc92f306c837c684738a0da419a934e63648ad5291bbd504e7cf7bd75b57b7b9
5
5
  SHA512:
6
- metadata.gz: 8aaf09171ac516ba515c2d047b8224a6e68261dc26d7ceb174c3c22571415e2a2df9049dbae19270db6b49ed7a43cb6237cbc430c0cbc831128d946eae0f183c
7
- data.tar.gz: b938892dca6c047f5898cc7e15d038e8feedb6bb753ad1d17c7e6d74bed7178046f0a7ea5aefb94e425c27263c4ba4aa80380a4ebe547d8a9fd5c71ae6100324
6
+ metadata.gz: 9e577a6ceb9be2a13a544a117984a5d59a5622e9b184de116dd23b4a9b9e0f529d9b694fc17d547ed3a3f65f065f71bfd592f603ce4fd74f2d3118b657efffa5
7
+ data.tar.gz: 18fa85856d136aaa337a193e61858e4a4ae8e4ed0796872487f29db741df5f2e96d69b19949f0336acd2d4002a3f654e9458248172b515818f895472b50de9f5
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ language: ruby
3
+ notifications:
4
+ email:
5
+ - krzysztof.hasinski+fillparams@gmail.com
6
+ rvm:
7
+ - 2.6.9
8
+ - 2.7.6
9
+ - 3.1.2
10
+ - ruby-head
11
+ - jruby
12
+
data/FillParams.gemspec CHANGED
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.6'
21
+ spec.add_development_dependency 'bundler', '~> 2.0'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'rspec'
24
- spec.add_development_dependency 'rspec-activemodel-mocks'
25
24
  end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Krzysztof Hasiński
1
+ Copyright (c) 2014 Krzysztof Hasiński, Justyna Wojtczak
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # FillParams
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/fillparams.svg)](http://badge.fury.io/rb/fillparams)
4
+
5
+ # ⚠️ Deprecated
6
+
7
+ # Please use [ENVs](https://github.com/bkeepers/dotenv) or [encrypted credentials](https://edgeguides.rubyonrails.org/security.html#custom-credentials) instead
8
+
3
9
  This tool allows you to manage ignored YAML parameters in your config files.
4
10
  It is inspired by [Incenteev ParameterHandler](https://github.com/Incenteev/ParameterHandler).
5
11
 
@@ -19,7 +25,7 @@ Or install it yourself as:
19
25
 
20
26
  ## Usage
21
27
 
22
- By default, the dist file is assumed to be in the same place than the parameters
28
+ By default, the dist file is assumed to be in the same place as the parameters
23
29
  file, suffixed by ``.dist``.
24
30
 
25
31
  The script handler will ask you interactively for parameters which are missing
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -1,3 +1,3 @@
1
1
  module FillParams
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -14,9 +14,7 @@ class ParameterFiller
14
14
 
15
15
  def fill_file_list
16
16
  @config_files.each do |file_name|
17
- if verbose
18
- puts 'Filling ' + file_name + '...'
19
- end
17
+ puts 'Filling ' + file_name + '...' if verbose
20
18
  fill_file file_name
21
19
  end
22
20
  end
@@ -33,9 +31,7 @@ class ParameterFiller
33
31
  def load_yaml_file(file_name)
34
32
  begin
35
33
  data = YAML.load_file(file_name)
36
- unless data
37
- data = {}
38
- end
34
+ data = {} unless data
39
35
  rescue Exception => e
40
36
  raise ArgumentError, 'Invalid YAML in config file ' + file_name unless data
41
37
  end
@@ -44,9 +40,7 @@ class ParameterFiller
44
40
 
45
41
  def setup_files(file_name, dist_file_name)
46
42
  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
43
+ File.write(file_name, '') unless File.file?(file_name)
50
44
  return
51
45
  end
52
46
 
@@ -57,9 +51,7 @@ class ParameterFiller
57
51
  data[key] = ask_for_param(key, value)
58
52
  end
59
53
  if dist_data[key].is_a?(Hash)
60
- unless data.has_key?(key)
61
- data[key] = {}
62
- end
54
+ data[key] = {} unless data.has_key?(key)
63
55
  data[key] = fill_parameters(data[key], dist_data[key])
64
56
  end
65
57
  end
@@ -0,0 +1,196 @@
1
+ require 'spec_helper'
2
+
3
+ describe ParameterFiller do
4
+ describe '#fill_parameters' do
5
+ context 'simple input yml' do
6
+ def sample_dist_data
7
+ YAML.load(<<-EOF
8
+ NAME: value
9
+ string: abc
10
+ number: 1.23
11
+ EOF
12
+ )
13
+ end
14
+
15
+ let(:pf) { ParameterFiller.new('', false, false) }
16
+ context 'when the data is nil' do
17
+ let(:data){ nil }
18
+ it 'returns the same config as sample_dist_data' do
19
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
20
+ end
21
+ end
22
+ context 'when the dist data is nil' do
23
+ let(:dist_data){ nil }
24
+ let(:data){ sample_dist_data }
25
+ it 'returns the same config as sample_dist_data' do
26
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
27
+ end
28
+ end
29
+ context 'when the data is the same as sample data' do
30
+ let(:data){ sample_dist_data }
31
+ it 'returns the same config as sample_dist_data' do
32
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
33
+ end
34
+ end
35
+ context 'when the data has additional key' do
36
+ let(:data){ sample_dist_data.merge('new_key'=> 'new_val') }
37
+ it 'returns the same config as data' do
38
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq data
39
+ end
40
+ end
41
+ context 'when the dist data has additional key' do
42
+ let(:dist_data){ sample_dist_data.merge('new_key'=> 'new_val') }
43
+ let(:data){ sample_dist_data }
44
+ it 'returns the same config as dist_data' do
45
+ expect(pf.fill_parameters(data, dist_data)).to eq dist_data
46
+ end
47
+ end
48
+ context 'when both data and dist data have additional keys' do
49
+ let(:dist_data){ sample_dist_data.merge('new_key'=> 'new_val') }
50
+ let(:data){ sample_dist_data.merge('new_key2'=> 'new_val2') }
51
+ it 'returns data with this keys' do
52
+ expect(pf.fill_parameters(data, dist_data)).to eq dist_data.merge('new_key2'=> 'new_val2')
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'nested input yml' do
58
+ def sample_dist_data
59
+ YAML.load(<<-EOF
60
+ key01: val01
61
+ key02:
62
+ key11: val11
63
+ key12:
64
+ key20: val20
65
+ EOF
66
+ )
67
+ end
68
+ let(:pf) { ParameterFiller.new('', false, false) }
69
+ context 'when the data is nil' do
70
+ let(:data){ nil }
71
+ it 'returns the same config as sample_dist_data' do
72
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
73
+ end
74
+ end
75
+ context 'when the dist data is nil' do
76
+ let(:dist_data){ nil }
77
+ let(:data){ sample_dist_data }
78
+ it 'returns the same config as sample_dist_data' do
79
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
80
+ end
81
+ end
82
+ context 'when the data is the same as sample data' do
83
+ let(:data){ sample_dist_data }
84
+ it 'returns the same config as sample_dist_data' do
85
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
86
+ end
87
+ end
88
+ context 'when the data has additional key' do
89
+ context 'on zero level of nesting' do
90
+ let(:data){ sample_dist_data.merge('new_key'=> 'new_val') }
91
+ it 'returns the same config as data' do
92
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq data
93
+ end
94
+ end
95
+ context 'on first level of nesting' do
96
+ let(:data){ sample_dist_data.merge('key02' => sample_dist_data['key02'].merge('new_key'=> 'new_val')) }
97
+ it 'returns the same config as data' do
98
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq data
99
+ end
100
+ end
101
+ end
102
+ context 'when the dist data has additional key' do
103
+ context 'on zero level of nesting' do
104
+ let(:dist_data){ sample_dist_data.merge('new_key'=> 'new_val') }
105
+ let(:data){ sample_dist_data }
106
+ it 'returns the same config as dist_data' do
107
+ expect(pf.fill_parameters(data, dist_data)).to eq dist_data
108
+ end
109
+ end
110
+ context 'on first level of nesting' do
111
+ let(:dist_data){ sample_dist_data.merge('key02' => sample_dist_data['key02'].merge('new_key'=> 'new_val')) }
112
+ let(:data){ sample_dist_data }
113
+ it 'returns the same config as dist_data' do
114
+ expect(pf.fill_parameters(data, dist_data)).to eq dist_data
115
+ end
116
+ end
117
+ end
118
+ context 'when both data and dist data have additional keys' do
119
+ context 'dist data on zero level of nesting and data on first level of nesting' do
120
+ let(:dist_data){ sample_dist_data.merge('new_key'=> 'new_val') }
121
+ let(:data){ sample_dist_data.merge('key02' => sample_dist_data['key02'].merge('new_key2'=> 'new_val2')) }
122
+ it 'returns data with this keys' do
123
+ expect(pf.fill_parameters(data, dist_data)).to eq data.merge('new_key'=> 'new_val')
124
+ end
125
+ end
126
+ context 'dist data on first level of nesting and data on zero level of nesting' do
127
+ let(:dist_data){ sample_dist_data.merge('key02' => sample_dist_data['key02'].merge('new_key'=> 'new_val')) }
128
+ let(:data){ sample_dist_data.merge('new_key2'=> 'new_val2') }
129
+ it 'returns data with this keys' do
130
+ expect(pf.fill_parameters(data, dist_data)).to eq dist_data.merge('new_key2'=> 'new_val2')
131
+ end
132
+ end
133
+ context 'when both data and dist data on first level of nesting' do
134
+ let(:dist_data){ sample_dist_data.merge('key02' => sample_dist_data['key02'].merge('new_key'=> 'new_val')) }
135
+ let(:data){ sample_dist_data.merge('key02' => sample_dist_data['key02'].merge('new_key2'=> 'new_val2')) }
136
+ it 'returns data with this keys' do
137
+ expect(pf.fill_parameters(data, dist_data)).to eq dist_data.merge('key02' => dist_data['key02'].merge('new_key2'=> 'new_val2'))
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'yml with anchors and aliases' do
144
+ def sample_dist_data
145
+ YAML.load(<<-EOF
146
+ defaults: &defaults
147
+ adapter: postgres
148
+ host: localhost
149
+
150
+ development:
151
+ database: myapp_development
152
+ <<: *defaults
153
+
154
+ test:
155
+ database: myapp_test
156
+ <<: *defaults
157
+ EOF
158
+ )
159
+ end
160
+
161
+ def data_results
162
+ YAML.load(<<-EOF
163
+ defaults:
164
+ adapter: postgres
165
+ host: localhost
166
+
167
+ development:
168
+ database: myapp_development
169
+ adapter: postgres
170
+ host: localhost
171
+
172
+ test:
173
+ database: myapp_test
174
+ adapter: postgres
175
+ host: localhost
176
+ EOF
177
+ )
178
+ end
179
+
180
+ let(:pf) { ParameterFiller.new('', false, false) }
181
+ context 'when the data is nil' do
182
+ let(:data){ nil }
183
+ it 'returns data_results' do
184
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq data_results
185
+ end
186
+ end
187
+ context 'when the dist data is nil' do
188
+ let(:dist_data){ nil }
189
+ let(:data){ sample_dist_data }
190
+ it 'returns data_results' do
191
+ expect(pf.fill_parameters(data, sample_dist_data)).to eq data_results
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'bundler/setup'
2
- require 'rspec/active_model/mocks'
3
-
4
2
  require 'parameter_filler.rb'
5
3
 
6
4
  Bundler.setup
metadata CHANGED
@@ -1,70 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fillparams
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Hasiński
8
8
  - Justyna Wojtczak
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-04 00:00:00.000000000 Z
12
+ date: 2022-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.6'
20
+ version: '2.0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.6'
27
+ version: '2.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
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
- - - '>='
53
+ - - ">="
68
54
  - !ruby/object:Gem::Version
69
55
  version: '0'
70
56
  description: A gem for filling in parameters automatically
@@ -76,8 +62,9 @@ executables:
76
62
  extensions: []
77
63
  extra_rdoc_files: []
78
64
  files:
79
- - .gitignore
80
- - .rspec
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
81
68
  - FillParams.gemspec
82
69
  - Gemfile
83
70
  - LICENSE.txt
@@ -89,33 +76,32 @@ files:
89
76
  - lib/FillParams/version.rb
90
77
  - lib/config_manager.rb
91
78
  - lib/parameter_filler.rb
92
- - spec/foobar_spec.rb
79
+ - spec/parameter_filler_spec.rb
93
80
  - spec/spec_helper.rb
94
81
  - test.yml.dist
95
82
  homepage: http://github.com/khasinski/fillparams
96
83
  licenses:
97
84
  - MIT
98
85
  metadata: {}
99
- post_install_message:
86
+ post_install_message:
100
87
  rdoc_options: []
101
88
  require_paths:
102
89
  - lib
103
90
  required_ruby_version: !ruby/object:Gem::Requirement
104
91
  requirements:
105
- - - '>='
92
+ - - ">="
106
93
  - !ruby/object:Gem::Version
107
94
  version: '0'
108
95
  required_rubygems_version: !ruby/object:Gem::Requirement
109
96
  requirements:
110
- - - '>='
97
+ - - ">="
111
98
  - !ruby/object:Gem::Version
112
99
  version: '0'
113
100
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.0.3
116
- signing_key:
101
+ rubygems_version: 3.2.22
102
+ signing_key:
117
103
  specification_version: 4
118
104
  summary: Parameters handler, for usage see github page
119
105
  test_files:
120
- - spec/foobar_spec.rb
106
+ - spec/parameter_filler_spec.rb
121
107
  - spec/spec_helper.rb
data/spec/foobar_spec.rb DELETED
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
- describe ParameterFiller do
3
-
4
- def sample_dist_data
5
- YAML.load(<<-EOF
6
- NAME: value
7
- string: abc
8
- number: 1.23
9
- EOF
10
- )
11
- end
12
-
13
- let(:pf) { ParameterFiller.new('', false, false) }
14
- context 'when the data is nil' do
15
- let(:data){ nil }
16
- it 'returns the same config as sample_dist_data' do
17
- expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
18
- end
19
- end
20
- context 'when the dist data is nil' do
21
- let(:dist_data){ nil }
22
- let(:data){ sample_dist_data }
23
- it 'returns the same config as sample_dist_data' do
24
- expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
25
- end
26
- end
27
- context 'when the data is the same as sample data' do
28
- let(:data){ sample_dist_data }
29
- it 'returns the same config as sample_dist_data' do
30
- expect(pf.fill_parameters(data, sample_dist_data)).to eq sample_dist_data
31
- end
32
- end
33
- context 'when the data has additional key' do
34
- let(:data){ sample_dist_data.merge('new_key'=> 'new_val') }
35
- it 'returns the same config as data' do
36
- expect(pf.fill_parameters(data, sample_dist_data)).to eq data
37
- end
38
- end
39
- context 'when the dist data has additional key' do
40
- let(:dist_data){ sample_dist_data.merge('new_key'=> 'new_val') }
41
- let(:data){ sample_dist_data }
42
- it 'returns the same config as dist_data' do
43
- expect(pf.fill_parameters(data, dist_data)).to eq dist_data
44
- end
45
- end
46
- context 'when both data and dist data have additional keys' do
47
- let(:dist_data){ sample_dist_data.merge('new_key'=> 'new_val') }
48
- let(:data){ sample_dist_data.merge('new_key2'=> 'new_val2') }
49
- it 'returns data with this keys' do
50
- expect(pf.fill_parameters(data, dist_data)).to eq dist_data.merge('new_key2'=> 'new_val2')
51
- end
52
- end
53
- end