grimen-bootstrapper 0.1.1 → 0.1.2
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/Rakefile +5 -2
- data/generators/bootstrapper/bootstrapper_generator.rb +2 -0
- data/lib/bootstrapper.rb +51 -32
- data/lib/connection_adapters/abstract_adapter.rb +6 -8
- data/lib/connection_adapters/mysql_adapter.rb +5 -7
- data/tasks/bootstrap.rake +2 -1
- data/test/bootstrapper_test.rb +1 -0
- metadata +4 -6
- data/lib/tasks.rb +0 -3
data/Rakefile
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
1
3
|
require 'rake'
|
2
4
|
require 'rake/testtask'
|
3
5
|
require 'rake/rdoctask'
|
4
6
|
|
5
7
|
NAME = "bootstrapper"
|
6
8
|
SUMMARY = %Q{A Rails plugin to assist in bootstrapping and seeding your database.}
|
7
|
-
HOMEPAGE = "http://github.com/
|
9
|
+
HOMEPAGE = "http://github.com/sevenwire/#{NAME}"
|
8
10
|
AUTHOR = "Sevenwire"
|
9
11
|
EMAIL = "git@sevenwire.com"
|
10
12
|
SUPPORT_FILES = %w(README.markdown)
|
11
13
|
|
12
14
|
begin
|
15
|
+
gem 'technicalpickles-jeweler', '>= 1.2.1'
|
13
16
|
require 'jeweler'
|
14
17
|
Jeweler::Tasks.new do |gem|
|
15
18
|
gem.name = NAME
|
@@ -28,7 +31,7 @@ rescue LoadError
|
|
28
31
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
29
32
|
end
|
30
33
|
|
31
|
-
desc %Q{Run unit tests for "#{NAME}".}
|
34
|
+
desc %Q{Default: Run unit tests for "#{NAME}".}
|
32
35
|
task :default => :test
|
33
36
|
|
34
37
|
desc %Q{Run unit tests for "#{NAME}".}
|
data/lib/bootstrapper.rb
CHANGED
@@ -1,41 +1,60 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
gem 'activesupport', '>= 1.2.3'
|
5
|
+
require 'active_support'
|
6
|
+
|
7
|
+
require File.join(File.dirname(__FILE__), *%w(connection_adapters abstract_adapter))
|
8
|
+
require File.join(File.dirname(__FILE__), *%w(connection_adapters mysql_adapter))
|
9
|
+
|
10
|
+
# Make tasks visible for Rails also when used as gem.
|
11
|
+
load File.expand_path(File.join(File.dirname(__FILE__), *%w(.. tasks bootstrap.rake)))
|
2
12
|
|
3
13
|
class Bootstrapper
|
14
|
+
|
4
15
|
class_inheritable_accessor :tasks
|
5
16
|
write_inheritable_attribute :tasks, HashWithIndifferentAccess.new
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
def for(key, &block)
|
21
|
+
tasks[key] = block
|
22
|
+
end
|
23
|
+
|
24
|
+
def run(key)
|
25
|
+
puts ">> Started executing bootstrap for #{key}"
|
26
|
+
tasks[key].call(self)
|
27
|
+
puts ">> Finished executing bootstrap for #{key}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def truncate_tables(*tables)
|
31
|
+
options = tables.last.is_a?(Hash) ? tables.pop : {}
|
32
|
+
if tables == [:all]
|
33
|
+
except = options[:except] || []
|
34
|
+
except = except.is_a?(Array) ? except.collect { |x| x.to_s } : [except.to_s]
|
35
|
+
|
36
|
+
tables = ActiveRecord::Base.connection.tables.select do |table|
|
37
|
+
table !~ /schema_(info|migrations)/ && !except.include?(table)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
tables.each do |table|
|
42
|
+
ActiveRecord::Base.connection.truncate_table(table)
|
25
43
|
end
|
26
44
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
45
|
+
|
46
|
+
def fixtures(*fixtures)
|
47
|
+
Fixtures.create_fixtures(File.join(RAILS_ROOT, 'db', 'populate'), fixtures)
|
48
|
+
|
49
|
+
if File.directory?(File.join(RAILS_ROOT, 'db', 'populate', RAILS_ENV))
|
50
|
+
Fixtures.create_fixtures(File.join(RAILS_ROOT, 'db', 'populate', RAILS_ENV), fixtures)
|
51
|
+
end
|
30
52
|
end
|
53
|
+
|
54
|
+
def sql(sql)
|
55
|
+
ActiveRecord::Base.connection.execute(sql)
|
56
|
+
end
|
57
|
+
|
31
58
|
end
|
32
|
-
|
33
|
-
def self.fixtures(*fixtures)
|
34
|
-
Fixtures.create_fixtures(File.join(RAILS_ROOT, 'db', 'populate'), fixtures)
|
35
|
-
Fixtures.create_fixtures(File.join(RAILS_ROOT, 'db', 'populate', RAILS_ENV), fixtures)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.sql(sql)
|
39
|
-
ActiveRecord::Base.connection.execute(sql)
|
40
|
-
end
|
59
|
+
|
41
60
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module ConnectionAdapters
|
1
|
+
# coding: utf-8
|
4
2
|
|
3
|
+
module ActiveRecord #:nodoc:
|
4
|
+
module ConnectionAdapters #:nodoc:
|
5
5
|
class AbstractAdapter
|
6
|
-
|
6
|
+
|
7
7
|
def truncate_table(table_name)
|
8
8
|
execute "DELETE FROM #{table_name}"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
14
|
-
|
15
|
-
end
|
13
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module ConnectionAdapters
|
1
|
+
# coding: utf-8
|
4
2
|
|
3
|
+
module ActiveRecord #:nodoc:
|
4
|
+
module ConnectionAdapters #:nodoc:
|
5
5
|
class MysqlAdapter
|
6
|
-
|
6
|
+
|
7
7
|
def truncate_table(table_name)
|
8
8
|
execute "TRUNCATE TABLE #{table_name}"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
data/tasks/bootstrap.rake
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
namespace :db do
|
2
3
|
desc "Bootstraps the database for the given environment. BOOTSTRAP option lets you run a specific bootstrap task in the given environment."
|
3
4
|
task :bootstrap => :environment do
|
4
5
|
require File.join(RAILS_ROOT, 'db', 'bootstrap')
|
5
6
|
Bootstrapper.run(ENV['BOOTSTRAP'] || RAILS_ENV)
|
6
7
|
end
|
7
|
-
|
8
|
+
|
8
9
|
namespace :bootstrap do
|
9
10
|
desc "Resets the database and bootstraps it for the given environment. BOOTSTRAP option lets you run a specific bootstrap task in the given environment."
|
10
11
|
task :reset => ['db:migrate:reset', 'reset_environment'] do
|
data/test/bootstrapper_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grimen-bootstrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sevenwire
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,12 +30,10 @@ files:
|
|
30
30
|
- lib/bootstrapper.rb
|
31
31
|
- lib/connection_adapters/abstract_adapter.rb
|
32
32
|
- lib/connection_adapters/mysql_adapter.rb
|
33
|
-
- lib/tasks.rb
|
34
33
|
- tasks/bootstrap.rake
|
35
34
|
- test/bootstrapper_test.rb
|
36
35
|
has_rdoc: false
|
37
|
-
homepage: http://github.com/
|
38
|
-
licenses:
|
36
|
+
homepage: http://github.com/sevenwire/bootstrapper
|
39
37
|
post_install_message:
|
40
38
|
rdoc_options:
|
41
39
|
- --charset=UTF-8
|
@@ -56,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
54
|
requirements: []
|
57
55
|
|
58
56
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.
|
57
|
+
rubygems_version: 1.2.0
|
60
58
|
signing_key:
|
61
59
|
specification_version: 3
|
62
60
|
summary: A Rails plugin to assist in bootstrapping and seeding your database.
|
data/lib/tasks.rb
DELETED