rails_config_validator 0.1.2 → 0.2.0

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
2
  SHA1:
3
- metadata.gz: bbb9506342925e85eeca4059dee9057bc2cf7d95
4
- data.tar.gz: 724b787b2b6096b52493765d389ddd22a06b38d3
3
+ metadata.gz: ff18f579ada65dfbdd3d7c2d2678e04a6f610de8
4
+ data.tar.gz: af9422fa2f2b1dc175cc853b5991675b4773e32b
5
5
  SHA512:
6
- metadata.gz: 288657094f81e9571fa8d81c1ece0c27b91d64121ccdfe11dde7c2db0056aeddcdc27ff772a412a431629ed404c927c086bff80b271862e0de64b5f01bd8888b
7
- data.tar.gz: 6ba09385a82eda2c0767635ef515a292229b79a6bd57a04dbd4088344c87d83de2ef2c1f1c1841702a4c6989f23d4b2f3b7218929062be0177dd876cc375b2db
6
+ metadata.gz: 3ec6cbd1d5e01d9abfe746f09dc2fcb681eae068e89dfc1e7477af69e15ff4458468e9abe208c9e24a2561acba69eee2c7a07205f4b892f5290541f47afc633a
7
+ data.tar.gz: 8b23315e6016df39b9a14075e5e9e1da7ca4c714b6e943717d6ef0dd8196f0cded39a4570e2b60056e62561ab9b559baad0d6add6533f970e36289b712de6aca
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .idea
11
+ rails_config_validator-*.gem
data/README.md CHANGED
@@ -4,41 +4,60 @@
4
4
  [![Dependency Status](https://gemnasium.com/u2i/rails_config_validator.svg)](https://gemnasium.com/u2i/rails_config_validator)
5
5
  [![Code Climate](https://codeclimate.com/github/u2i/rails_config_validator/badges/gpa.svg)](https://codeclimate.com/github/u2i/rails_config_validator)
6
6
  [![Test Coverage](https://codeclimate.com/github/u2i/rails_config_validator/badges/coverage.svg)](https://codeclimate.com/github/u2i/rails_config_validator/coverage)
7
+ [![Gem Version](https://badge.fury.io/rb/rails_config_validator.svg)](http://badge.fury.io/rb/rails_config_validator)
7
8
 
8
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_config_validator`. To experiment with that code, run `bin/console` for an interactive prompt.
9
-
10
- TODO: Delete this and the text above, and describe your gem
9
+ The gem uses [Kwalify](http://www.kuwata-lab.com/kwalify/) schema validator to check Rails configuration files syntax.
11
10
 
12
11
  ## Installation
13
12
 
14
- Add this line to your application's Gemfile:
13
+ Add this line to your application's `Gemfile`:
15
14
 
16
15
  ```ruby
17
- gem 'rails_config_validator'
16
+ gem 'rails_config_validator', '~> 0.1'
18
17
  ```
19
18
 
20
19
  And then execute:
21
20
 
22
21
  $ bundle
23
22
 
24
- Or install it yourself as:
23
+ Add Rake tasks to `Rakefile`:
24
+
25
+ ```ruby
26
+ require 'rails_config_validator/rake_task'
27
+ RailsConfigValidator::RakeTask.new
28
+ ```
29
+
30
+ Run Rake task to copy default `database.yml` schema file and add `config/database.schema.yml` to your version control:
31
+
32
+ rake config_validator:init
33
+ git add config/database.schema.yml
25
34
 
26
- $ gem install rails_config_validator
35
+ Specify files for which the gem should run validation `config/application.rb` or in environment file:
36
+
37
+ ```ruby
38
+ config.config_validator.files = %w(database.yml your-config.yml)
39
+ ```
27
40
 
28
41
  ## Usage
29
42
 
30
- TODO: Write usage instructions here
43
+ After deployment the schema can be validated with Rake task:
44
+
45
+ export RAILS_ENV=production
46
+ bundle exec rake config_validator:validate[config/database.yml]
31
47
 
32
48
  ## Development
33
49
 
34
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
50
+ After checking out the repo, run `bin/setup` to install dependencies.
51
+ Then, run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ Use `bundle exec guard` to run `rspec` and `rubocop` on each code change.
35
54
 
36
- 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+ To install this gem onto your local machine, run `bundle exec rake install`.
37
56
 
38
57
  ## Contributing
39
58
 
40
- 1. Fork it ( https://github.com/[my-github-username]/rails_config_validator/fork )
41
- 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 1. [Fork it](https://github.com/u2i/rails_config_validator/fork)
60
+ 2. Create your feature branch (`git checkout -b feature/my-new-feature`)
42
61
  3. Commit your changes (`git commit -am 'Add some feature'`)
43
- 4. Push to the branch (`git push origin my-new-feature`)
44
- 5. Create a new Pull Request
62
+ 4. Push to the branch (`git push origin feature/my-new-feature`)
63
+ 5. Create a new Pull Request to branch `develop`.
data/Rakefile CHANGED
@@ -4,20 +4,20 @@ begin
4
4
  require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  rescue LoadError => e
7
- puts e
7
+ STDERR.puts e
8
8
  end
9
9
 
10
10
  begin
11
11
  require 'rubocop/rake_task'
12
12
  RuboCop::RakeTask.new(:rubocop)
13
13
  rescue LoadError => e
14
- puts e
14
+ STDERR.puts e
15
15
  end
16
16
 
17
17
  begin
18
18
  require 'ci/reporter/rake/rspec'
19
19
  rescue LoadError => e
20
- puts e
20
+ STDERR.puts e
21
21
  end
22
22
 
23
23
  task default: [:spec, :rubocop]
@@ -3,22 +3,38 @@ require 'rake/tasklib'
3
3
 
4
4
  module RailsConfigValidator
5
5
  class RakeTask < ::Rake::TaskLib
6
- include ::Rake::DSL if defined?(::Rake::DSL)
7
-
8
6
  def initialize
9
7
  require 'rails_config_validator/validator'
10
8
 
11
- desc 'Validates Rails config file against YML schema'
12
9
  namespace :config_validator do
13
- task :validate, [:config, :schema, :env] do |_, args|
14
- config = args[:config]
15
- schema = args[:schema]
16
- env = args[:env] || Rails.env
17
- fail 'Missing parameter :config' if args[:config].nil?
10
+ task_init
11
+ task_validate
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def task_init
18
+ desc "Copies database.schema.yml to Rails's config directory"
19
+ task :init do
20
+ rake_file_dir = File.expand_path(File.dirname(__FILE__))
21
+ FileUtils.cp(
22
+ File.join(rake_file_dir, 'templates', 'database.schema.yml'),
23
+ File.join(Dir.pwd, 'config')
24
+ )
25
+ end
26
+ end
27
+
28
+ def task_validate
29
+ desc 'Validates Rails config file against YML schema'
30
+ task :validate, [:config, :schema, :env] do |_, args|
31
+ config = args[:config]
32
+ schema = args[:schema]
33
+ env = args[:env] || Rails.env
34
+ fail 'Missing parameter :config' if args[:config].nil?
18
35
 
19
- v = RailsConfigValidator::Validator.new(config, env, schema_path: schema)
20
- v.valid!
21
- end
36
+ v = RailsConfigValidator::Validator.new(config, env, schema_path: schema)
37
+ v.valid!
22
38
  end
23
39
  end
24
40
  end
@@ -0,0 +1,26 @@
1
+ type: map
2
+ mapping:
3
+ adapter:
4
+ type: str
5
+ required: true
6
+ pool:
7
+ type: int
8
+ timeout:
9
+ type: int
10
+ database:
11
+ type: str
12
+ hostname:
13
+ type: str
14
+ username:
15
+ type: str
16
+ password:
17
+ type: str
18
+ socket:
19
+ type: str
20
+ encoding:
21
+ type: str
22
+ port:
23
+ type: int
24
+ range:
25
+ min: 0
26
+ max: 65535
@@ -1,3 +1,3 @@
1
1
  module RailsConfigValidator
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_config_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Knapik
@@ -229,6 +229,7 @@ files:
229
229
  - lib/rails_config_validator/errors.rb
230
230
  - lib/rails_config_validator/railtie.rb
231
231
  - lib/rails_config_validator/rake_task.rb
232
+ - lib/rails_config_validator/templates/database.schema.yml
232
233
  - lib/rails_config_validator/validator.rb
233
234
  - lib/rails_config_validator/version.rb
234
235
  - rails_config_validator.gemspec