rails_db_guard 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f8a0fc06916b9f01df67d54964524c7e26249314386df6647c679c491ac1dff
4
- data.tar.gz: 65bb14cc692568e0596b7d6680ae1a61d4989238524923b00e7cbe480cea4488
3
+ metadata.gz: 69c7b5793bccce4da21d45f7ea2d88bda6036da8efb4b5df9eda0a398cd1f246
4
+ data.tar.gz: f65abc85d8389739a642877f69d9e18365ebdde607aa688dfe386da9c3a0f033
5
5
  SHA512:
6
- metadata.gz: 40862f3e2c43ff178170f08a5442395bc05ad85e20f9bf5bb5ab8de02cae48ca9c7d14fb46dbec4f1dc7474ed0f629443b0269fd832d6479a94f396c4fb6ad30
7
- data.tar.gz: d1bdd8d0f397a96d90936d7eead125e3f64b5fa1efa72f53676d2b386c2a784ff47fd3dc81ca5fab3fdff6601dedc570694dae02d7146b1baa0f0839cd73caf5
6
+ metadata.gz: e0e31cd1823b44ea721581fac1d5717c38d26ce5d90d7cde8c371029f14c32ed95a5a7940e57c3fb01b06240858447abbd697a195a025a8abe56effebe719c90
7
+ data.tar.gz: a5010994c1ca7b67eeeba83761606c7a8720f6bab1b674060ffa2fd6c942fe7c0a06d5dff911155a8de863ded56d15ff2d87d5c466cf6feeea5d68a77d1aa371
@@ -0,0 +1,37 @@
1
+ name: Main workflow
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - name: Checkout
11
+ uses: actions/checkout@v1
12
+
13
+ - name: Set up Ruby 2.6
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.6.2
17
+
18
+ - name: Install sqlite3
19
+ run: sudo apt-get install libsqlite3-dev
20
+
21
+ - name: Bundle
22
+ run: |
23
+ gem install bundler -v 1.17.3
24
+ bundle install --jobs 4 --retry 3
25
+
26
+ - name: Run rubocop
27
+ run: bundle exec rubocop
28
+
29
+ - name: Prepare test app
30
+ run: |
31
+ cd test/rails_app
32
+ RAILS_ENV=test bundle exec rake db:migrate
33
+ RAILS_ENV=development bundle exec rake db:migrate
34
+ RAILS_ENV=production bundle exec rake db:migrate
35
+
36
+ - name: Run tests
37
+ run: bundle exec rake test
@@ -0,0 +1,33 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ Exclude:
4
+ - "bin/console"
5
+ - "test/rails_app/db/schema.rb"
6
+
7
+ Metrics/AbcSize:
8
+ Exclude:
9
+ - "test/**/*"
10
+
11
+ Metrics/LineLength:
12
+ AllowHeredoc: true
13
+ AllowURI: true
14
+ IgnoreCopDirectives: true
15
+ Max: 120
16
+ Exclude:
17
+ - "authorize_that.gemspec"
18
+ - "test/**/*"
19
+
20
+ Metrics/MethodLength:
21
+ Exclude:
22
+ - "test/**/*"
23
+
24
+ Style/ClassAndModuleChildren:
25
+ Exclude:
26
+ - "test/**/*"
27
+
28
+ Style/StringLiterals:
29
+ EnforcedStyle: double_quotes
30
+
31
+ Style/SymbolProc:
32
+ Exclude:
33
+ - test/rails_app/db/migrate/20190708175731_create_tables.rb
data/.vimrc ADDED
@@ -0,0 +1,4 @@
1
+ if exists('+colorcolumn')
2
+ highlight ColorColumn ctermbg=237
3
+ set colorcolumn=120
4
+ endif
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in rails_db_guard.gemspec
6
8
  gemspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # RailsDbGuard
2
2
 
3
+ [![Actions Status](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/badge/betterdoc-org/rails_db_guard)](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/results/betterdoc-org/rails_db_guard)
4
+
3
5
  Prevents connecting to protected environments databases from other environments.
4
6
 
5
7
  Have you ever used `DATABASE_URL` from production in development? If yes, this is a gem for you. If not, some of your colleague has (or will), so this is a gem for you :)
@@ -69,7 +71,6 @@ This also mean you will need to prepare database for each environment.
69
71
  * MySQL adapter
70
72
  * CI setup (matrix for multiple database adapter and rails versions combinations)
71
73
  * Setup Rubocop
72
- * Add option to skip the check if `DISABLE_DATABASE_ENVIRONMENT_CHECK` environment variable is set
73
74
 
74
75
  ## Contributing
75
76
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
 
@@ -7,4 +9,4 @@ Rake::TestTask.new(:test) do |t|
7
9
  t.test_files = FileList["test/**/*_test.rb"]
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails_db_guard/version"
4
+ require "rails_db_guard/railtie"
2
5
 
6
+ # :nodoc:
3
7
  module RailsDbGuard
4
8
  class Error < StandardError; end
5
9
 
@@ -14,11 +18,10 @@ module RailsDbGuard
14
18
  end
15
19
 
16
20
  def guard!(env)
17
- return unless (ActiveRecord::Base.protected_environments.include?(env) && Rails.env != env)
21
+ return if ENV.key?("DISABLE_DATABASE_ENVIRONMENT_CHECK")
22
+ return unless ActiveRecord::Base.protected_environments.include?(env) && Rails.env != env
18
23
 
19
24
  raise Error, "You are trying to connect to `#{env}` database from `#{Rails.env}` environment"
20
25
  end
21
26
  end
22
27
  end
23
-
24
- require "rails_db_guard/railtie"
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.set_callback :checkout, :after do
2
- begin
3
- env = raw_connection.exec(RailsDbGuard::ENV_NAME_SQL).values.flatten.first
4
- RailsDbGuard.guard!(env)
5
- rescue PG::UndefinedTable => e
6
- raise e unless e.message =~ /relation \"ar_internal_metadata\" does not exist/
7
- end
4
+ env = raw_connection.exec(RailsDbGuard::ENV_NAME_SQL).values.flatten.first
5
+ RailsDbGuard.guard!(env)
6
+ rescue PG::UndefinedTable => e
7
+ raise e unless e.message =~ /relation \"ar_internal_metadata\" does not exist/
8
8
  end
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveRecord::ConnectionAdapters::SQLite3Adapter.set_callback :checkout, :after do
2
- begin
3
- env = raw_connection.execute(RailsDbGuard::ENV_NAME_SQL).first["value"]
4
- RailsDbGuard.guard!(env)
5
- rescue SQLite3::SQLException => e
6
- raise e unless e.message =~ /no such table\: ar_internal_metadata/
7
- end
4
+ env = raw_connection.execute(RailsDbGuard::ENV_NAME_SQL).first["value"]
5
+ RailsDbGuard.guard!(env)
6
+ rescue SQLite3::SQLException => e
7
+ raise e unless e.message =~ /no such table\: ar_internal_metadata/
8
8
  end
@@ -1,5 +1,10 @@
1
- class RailsDbGuard::Railtie < Rails::Railtie
2
- config.to_prepare do
3
- RailsDbGuard.call
1
+ # frozen_string_literal: true
2
+
3
+ module RailsDbGuard
4
+ # :nodoc:
5
+ class Railtie < Rails::Railtie
6
+ config.to_prepare do
7
+ RailsDbGuard.call
8
+ end
4
9
  end
5
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsDbGuard
2
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
3
5
  end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require "rails_db_guard/version"
5
6
 
@@ -9,13 +10,13 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ["BetterDoc GmbH"]
10
11
  spec.email = ["pirates@betterdoc.org"]
11
12
 
12
- spec.summary = %q{Prevents connecting to protected environments databases from other environments}
13
+ spec.summary = "Prevents connecting to protected environments databases from other environments"
13
14
  spec.homepage = "https://github.com/betterdoc-org/rails_db_guard"
14
15
  spec.license = "MIT"
15
16
 
16
17
  # Specify which files should be added to the gem when it is released.
17
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
21
  end
21
22
  spec.bindir = "exe"
@@ -25,6 +26,8 @@ Gem::Specification.new do |spec|
25
26
  spec.add_dependency "rails", ">= 5"
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.17"
29
+ spec.add_development_dependency "climate_control", "~> 0.2.0"
28
30
  spec.add_development_dependency "minitest", "~> 5"
29
31
  spec.add_development_dependency "rake", "~> 10"
32
+ spec.add_development_dependency "rubocop", "~> 0.74"
30
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_db_guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BetterDoc GmbH
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-10 00:00:00.000000000 Z
11
+ date: 2019-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: climate_control
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.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.2.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: minitest
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.74'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.74'
69
97
  description:
70
98
  email:
71
99
  - pirates@betterdoc.org
@@ -73,8 +101,11 @@ executables: []
73
101
  extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
104
+ - ".github/workflows/main.yml"
76
105
  - ".gitignore"
106
+ - ".rubocop.yml"
77
107
  - ".travis.yml"
108
+ - ".vimrc"
78
109
  - CODE_OF_CONDUCT.md
79
110
  - Gemfile
80
111
  - LICENSE.txt