surgicalstrike 0.0.2 → 0.0.3
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.
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# SurgicalStrike
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'SurgicalStrike'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install SurgicalStrike
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'active_record/base'
|
2
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
3
|
+
require 'SurgicalStrike/active_record/base'
|
4
|
+
require 'SurgicalStrike/generic/SurgicalStrike'
|
5
|
+
|
6
|
+
module ActiveRecord
|
7
|
+
class Base
|
8
|
+
include ::DatabaseCleaner::Generic::Dataholder
|
9
|
+
extend ActiveRecord::Callbacks
|
10
|
+
|
11
|
+
after_create :add_vip
|
12
|
+
|
13
|
+
private
|
14
|
+
def add_vip
|
15
|
+
checktarget(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ConnectionAdapters
|
20
|
+
|
21
|
+
class AbstractAdapter
|
22
|
+
def views
|
23
|
+
@views ||= select_values("select table_name from information_schema.views where table_schema = '#{current_database}'") rescue []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module DatabaseCleaner::ActiveRecord
|
30
|
+
class Surgicalstrike
|
31
|
+
include ::DatabaseCleaner::ActiveRecord::Base
|
32
|
+
include ::DatabaseCleaner::Generic::Dataholder
|
33
|
+
include ::DatabaseCleaner::Generic::Surgicalstrike
|
34
|
+
|
35
|
+
def start
|
36
|
+
connection = connection_klass.connection
|
37
|
+
|
38
|
+
$strike_targets = tables_to_strike(connection)
|
39
|
+
$vips = Array.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def clean
|
43
|
+
strike_tables
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
private
|
48
|
+
def strike_tables
|
49
|
+
$vips = $vips.reverse
|
50
|
+
$vips.each do |record|
|
51
|
+
record.delete
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def tables_to_strike(connection)
|
56
|
+
(@only || connection.tables) - @tables_to_exclude - connection.views
|
57
|
+
end
|
58
|
+
|
59
|
+
# overwritten
|
60
|
+
def migration_storage_name
|
61
|
+
'schema_migrations'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module DatabaseCleaner
|
2
|
+
module Generic
|
3
|
+
module Dataholder
|
4
|
+
def checktarget(target)
|
5
|
+
if ($strike_targets.include?(target.class.table_name.upcase))
|
6
|
+
$vips.push(target)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
module Surgicalstrike
|
11
|
+
def initialize(opts={})
|
12
|
+
if !opts.empty? && !(opts.keys - [:only, :except]).empty?
|
13
|
+
raise ArgumentError, "The only valid options are :only and :except. You specified #{opts.keys.join(',')}."
|
14
|
+
end
|
15
|
+
if opts.has_key?(:only) && opts.has_key?(:except)
|
16
|
+
raise ArgumentError, "You may only specify either :only or :except. Doing both doesn't really make sense does it?"
|
17
|
+
end
|
18
|
+
|
19
|
+
@only = opts[:only]
|
20
|
+
@tables_to_exclude = (opts[:except] || []).dup
|
21
|
+
@tables_to_exclude << migration_storage_name if migration_storage_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
|
28
|
+
def clean
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def tables_to_strike(connection)
|
35
|
+
raise NotImplementedError
|
36
|
+
end
|
37
|
+
|
38
|
+
# overwrite in subclasses
|
39
|
+
# default implementation given because migration storage need not be present
|
40
|
+
def migration_storage_name
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surgicalstrike
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -17,7 +17,13 @@ email:
|
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
|
-
files:
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- lib/SurgicalStrike.rb
|
23
|
+
- lib/SurgicalStrike/active_record/surgicalstrike.rb
|
24
|
+
- lib/SurgicalStrike/generic/base.rb
|
25
|
+
- lib/SurgicalStrike/generic/surgicalstrike.rb
|
26
|
+
- lib/SurgicalStrike/version.rb
|
21
27
|
homepage: ''
|
22
28
|
licenses: []
|
23
29
|
post_install_message:
|