tamplier 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tamplier.rb +7 -3
- data/lib/tamplier/exceptions/configuration_exception.rb +2 -0
- data/lib/tamplier/railtie.rb +7 -0
- data/lib/tamplier/validator.rb +33 -0
- data/lib/tamplier/version.rb +1 -1
- data/spec/dummy/config/environment.rb +20 -0
- data/spec/dummy/config/test.yml.sample +1 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/examples/absent_environment/environment.yml +2 -0
- data/spec/examples/absent_environment/environment.yml.sample +2 -0
- data/spec/examples/absent_environment_key/environment.yml +2 -0
- data/spec/examples/absent_environment_key/environment.yml.sample +3 -0
- data/spec/examples/absent_environment_keys/environment.yml +4 -0
- data/spec/examples/absent_environment_keys/environment.yml.sample +5 -0
- data/spec/examples/absent_file/invalid.yml.sample +1 -0
- data/spec/examples/absent_file/valid.yml +1 -0
- data/spec/examples/absent_file/valid.yml.sample +1 -0
- data/spec/examples/absent_keys/non_environment.yml +6 -0
- data/spec/examples/absent_keys/non_environment.yml.sample +6 -0
- data/spec/railtie_spec.rb +8 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/validator_spec.rb +25 -0
- metadata +95 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c19c4b86a92337ec4c88daf48eac19b48f18ba0d
|
4
|
+
data.tar.gz: ae4d04d4295cbbe1574f375599939c7dbb6283c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c02be62ff4cb55581ab70ef4f3dff913c2a765bb263983b41e097ecd5ecafe61c533d67b96dc3233fb0381bdaa9ced476058ce22c6396774e445f5b1f621e11
|
7
|
+
data.tar.gz: 782e381c1d7ff8a869d30ea50fae8c0b4fd437c64a13b415dc1fd3c8e7d2da85063b091cd02384868efc8fadaa08d1e30595205923ec5b46a34ac311f2354d47
|
data/lib/tamplier.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Tamplier
|
2
|
+
class Validator
|
3
|
+
def ensure(root, environment = nil)
|
4
|
+
Pathname.glob(File.join(root, '*.yml.sample')).each do |sample_file|
|
5
|
+
config_file = sample_file.sub_ext('')
|
6
|
+
raise ConfigurationException.new("Configuration file #{config_file} does not exist, but sample file #{sample_file} does.") unless config_file.exist?
|
7
|
+
|
8
|
+
if environmental_file?(sample_file)
|
9
|
+
raise ConfigurationException.new("There is no #{environment} environment in the #{config_file} file.") unless YAML.load(config_file.read)[environment].present?
|
10
|
+
end
|
11
|
+
|
12
|
+
diff = environmental_file?(sample_file) ?
|
13
|
+
flat_keys(YAML.load(sample_file.read)['development']) - flat_keys(YAML.load(config_file.read)[environment]) :
|
14
|
+
flat_keys(YAML.load(sample_file.read)) - flat_keys(YAML.load(config_file.read))
|
15
|
+
|
16
|
+
raise ConfigurationException.new("Several keys #{diff.inspect} from #{sample_file} are not in #{config_file} file.") unless diff.empty?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def environmental_file?(file)
|
23
|
+
(YAML.load(file.read).keys & %w[development test]).present?
|
24
|
+
end
|
25
|
+
|
26
|
+
def flat_keys(hash, path = '')
|
27
|
+
return path unless hash.is_a?(Hash)
|
28
|
+
hash.map do |key, value|
|
29
|
+
flat_keys(value, "#{path}/#{key}")
|
30
|
+
end.flatten
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/tamplier/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
require 'rails'
|
6
|
+
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
require 'tamplier'
|
9
|
+
|
10
|
+
module Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Rails.application.configure do
|
16
|
+
config.eager_load = false
|
17
|
+
config.root = File.dirname(File.expand_path('../', __FILE__))
|
18
|
+
end
|
19
|
+
|
20
|
+
Rails.application.initialize!
|
@@ -0,0 +1 @@
|
|
1
|
+
test.yml.sample
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
invalid.yml.sample
|
@@ -0,0 +1 @@
|
|
1
|
+
valid.yml
|
@@ -0,0 +1 @@
|
|
1
|
+
valid.yml.sample
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tamplier/exceptions/configuration_exception'
|
3
|
+
|
4
|
+
describe 'integration test' do
|
5
|
+
it 'should not let application start without proper config' do
|
6
|
+
expect { require File.expand_path("../dummy/config/environment", __FILE__) }.to raise_error(ConfigurationException)
|
7
|
+
end
|
8
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tamplier/exceptions/configuration_exception'
|
3
|
+
require 'tamplier/validator'
|
4
|
+
|
5
|
+
describe Tamplier::Validator do
|
6
|
+
it 'checks, that all required config files are present' do
|
7
|
+
expect { subject.ensure('spec/examples/absent_file/') }.to raise_error(ConfigurationException, %q[Configuration file spec/examples/absent_file/invalid.yml does not exist, but sample file spec/examples/absent_file/invalid.yml.sample does.])
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'checks, that there is a valid environment in yml file' do
|
11
|
+
expect { subject.ensure('spec/examples/absent_environment/', 'production') }.to raise_error(ConfigurationException, %q[There is no production environment in the spec/examples/absent_environment/environment.yml file.])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'checks, that all environmental keys from sample file exist in real file' do
|
15
|
+
expect { subject.ensure('spec/examples/absent_environment_key/', 'production') }.to raise_error(ConfigurationException, %q[Several keys ["/not_exist"] from spec/examples/absent_environment_key/environment.yml.sample are not in spec/examples/absent_environment_key/environment.yml file.])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'checks, that all environmental keys (in deep) from sample file exist in real file' do
|
19
|
+
expect { subject.ensure('spec/examples/absent_environment_keys/', 'production') }.to raise_error(ConfigurationException, %q[Several keys ["/first/second/fourth"] from spec/examples/absent_environment_keys/environment.yml.sample are not in spec/examples/absent_environment_keys/environment.yml file.])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'checks, that all non enviromental keys from sample file exist in real file' do
|
23
|
+
expect { subject.ensure('spec/examples/absent_keys/') }.to raise_error(ConfigurationException, %q[Several keys ["/first/second/third", "/first/second/fourth"] from spec/examples/absent_keys/non_environment.yml.sample are not in spec/examples/absent_keys/non_environment.yml file.])
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tamplier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Shestakov
|
@@ -38,6 +38,62 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '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: simplecov
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
41
97
|
description: |
|
42
98
|
How many times your deploys were failed, because you forgot to update .yml files on server... No more!
|
43
99
|
Tamplier gem checks, that all keys from any .yml.sample files are actually exist in real .yml files.
|
@@ -50,7 +106,27 @@ extensions: []
|
|
50
106
|
extra_rdoc_files: []
|
51
107
|
files:
|
52
108
|
- lib/tamplier.rb
|
109
|
+
- lib/tamplier/exceptions/configuration_exception.rb
|
110
|
+
- lib/tamplier/railtie.rb
|
111
|
+
- lib/tamplier/validator.rb
|
53
112
|
- lib/tamplier/version.rb
|
113
|
+
- spec/dummy/config/environment.rb
|
114
|
+
- spec/dummy/config/test.yml.sample
|
115
|
+
- spec/dummy/log/development.log
|
116
|
+
- spec/examples/absent_environment/environment.yml
|
117
|
+
- spec/examples/absent_environment/environment.yml.sample
|
118
|
+
- spec/examples/absent_environment_key/environment.yml
|
119
|
+
- spec/examples/absent_environment_key/environment.yml.sample
|
120
|
+
- spec/examples/absent_environment_keys/environment.yml
|
121
|
+
- spec/examples/absent_environment_keys/environment.yml.sample
|
122
|
+
- spec/examples/absent_file/invalid.yml.sample
|
123
|
+
- spec/examples/absent_file/valid.yml
|
124
|
+
- spec/examples/absent_file/valid.yml.sample
|
125
|
+
- spec/examples/absent_keys/non_environment.yml
|
126
|
+
- spec/examples/absent_keys/non_environment.yml.sample
|
127
|
+
- spec/railtie_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/validator_spec.rb
|
54
130
|
homepage: https://github.com/maksar/tamplier
|
55
131
|
licenses:
|
56
132
|
- MIT
|
@@ -76,4 +152,21 @@ signing_key:
|
|
76
152
|
specification_version: 4
|
77
153
|
summary: Tamplier gem provides ability to manage .yml.sample config files in your
|
78
154
|
ruby projects.
|
79
|
-
test_files:
|
155
|
+
test_files:
|
156
|
+
- spec/dummy/config/environment.rb
|
157
|
+
- spec/dummy/config/test.yml.sample
|
158
|
+
- spec/dummy/log/development.log
|
159
|
+
- spec/examples/absent_environment/environment.yml
|
160
|
+
- spec/examples/absent_environment/environment.yml.sample
|
161
|
+
- spec/examples/absent_environment_key/environment.yml
|
162
|
+
- spec/examples/absent_environment_key/environment.yml.sample
|
163
|
+
- spec/examples/absent_environment_keys/environment.yml
|
164
|
+
- spec/examples/absent_environment_keys/environment.yml.sample
|
165
|
+
- spec/examples/absent_file/invalid.yml.sample
|
166
|
+
- spec/examples/absent_file/valid.yml
|
167
|
+
- spec/examples/absent_file/valid.yml.sample
|
168
|
+
- spec/examples/absent_keys/non_environment.yml
|
169
|
+
- spec/examples/absent_keys/non_environment.yml.sample
|
170
|
+
- spec/railtie_spec.rb
|
171
|
+
- spec/spec_helper.rb
|
172
|
+
- spec/validator_spec.rb
|