table-flip 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9f088ee1392f2b62dc4d99059856a71d67c0d8f
4
+ data.tar.gz: bc017bfd6ebb09481c557fbdb414e9d7c676535c
5
+ SHA512:
6
+ metadata.gz: 2c093761df2c569822b7bffb2599a35cefc9b35d6b3d5f029a9e80b9b840f671476bb3d192e4ef39f8d0e37568c92052b525401551b9c39d833b7dc7f7ed832e
7
+ data.tar.gz: efa61bce9a0c6370b8de23f0fc4a30842237be56c73e67d25a172a268ccf59e27b3f3d0d52f2073ef13535dc21bfb7d8517bf7dab33f224d7f047faea78c6233
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in table-flip.gemspec
4
+ gemspec
@@ -0,0 +1,57 @@
1
+ # ❨╯°□°❩╯︵┻━┻
2
+
3
+ You know when you accidentally do a stupid thing like running tests against a
4
+ database with data in it and you loose the data because your test suite cleans
5
+ the database before running? Table flip lets you safeguard against that if
6
+ you're using [Sequel](http://sequel.jeremyevans.net/) as your ORM.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "table-flip"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install table-flip
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ # spec/spec_helper.rb
28
+ require "table-flip"
29
+
30
+ RSpec.configure do |config|
31
+ # ...
32
+ TableFlip.new(Sequel::Model.db).check!
33
+ # ...
34
+ end
35
+ ```
36
+
37
+ This will raise a `TableFlip::DBNotEmptyError` if the database contains any
38
+ records. If you really really really want to wipe it anyway, you can run your
39
+ command with an easy to remember environment variable:
40
+
41
+ ```bash
42
+ WIPE_DB_YES_I_REALLY_REALLY_KNOW_WHAT_IM_DOING=true rspec
43
+ ```
44
+
45
+ ## Development
46
+
47
+ 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.
48
+
49
+ 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).
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/[my-github-username]/table-flip/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "table-flip"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+ require "table_flip/version"
2
+
3
+ class TableFlip
4
+ OVERRIDE_FLAG = "WIPE_DB_YES_I_REALLY_REALLY_KNOW_WHAT_IM_DOING"
5
+
6
+ class DBNotEmptyError < StandardError
7
+ end
8
+
9
+ def initialize(db)
10
+ @db = db
11
+ end
12
+
13
+ def check!
14
+ return if ENV[OVERRIDE_FLAG] == "true"
15
+ ❨╯°□°❩╯︵┻━┻ if non_empty_tables.any?
16
+ end
17
+
18
+ private
19
+
20
+ def ❨╯°□°❩╯︵┻━┻
21
+ if non_empty_tables.count == 1
22
+ table = "table"
23
+ is_are = "is"
24
+ else
25
+ table = "tables"
26
+ is_are = "are"
27
+ end
28
+
29
+ raise DBNotEmptyError, "The #{table} #{non_empty_table_names} #{is_are} not " \
30
+ "empty! Running this command would wipe the database, " \
31
+ "if you're sure you want this, run " \
32
+ "`#{OVERRIDE_FLAG}=true YOUR_COMMAND`"
33
+ end
34
+
35
+ def non_empty_table_names
36
+ non_empty_tables.map { |table| "'#{table.to_s}'"}.join(', ')
37
+ end
38
+
39
+ def non_empty_tables
40
+ @non_empty_tables ||= tables.select { |table| @db[table].count > 0 }
41
+ end
42
+
43
+ def tables
44
+ Sequel::Model.db.tables.reject { |name| name == :schema_migrations }
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Table
2
+ module Flip
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -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 'table_flip/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "table-flip"
8
+ spec.version = Table::Flip::VERSION
9
+ spec.authors = ["Andrew Appleton"]
10
+ spec.email = ["andrew@heroku.com"]
11
+
12
+ spec.summary = "Bail if the database contains any data. Handy to prevent stupid stuff like running tests against a database full of data. Which I have never done. Nope, not me."
13
+ spec.homepage = "https://github.com/heroku/table-flip"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.9"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "sequel"
24
+ spec.add_development_dependency "sqlite3"
25
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: table-flip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Appleton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: sequel
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: sqlite3
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
+ description:
84
+ email:
85
+ - andrew@heroku.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/table_flip.rb
99
+ - lib/table_flip/version.rb
100
+ - table-flip.gemspec
101
+ homepage: https://github.com/heroku/table-flip
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Bail if the database contains any data. Handy to prevent stupid stuff like
124
+ running tests against a database full of data. Which I have never done. Nope, not
125
+ me.
126
+ test_files: []