bio-gem 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/README.rdoc +92 -5
- data/VERSION +1 -1
- data/bio-gem.gemspec +8 -4
- data/lib/bio-gem/mod/jeweler.rb +62 -19
- data/lib/bio-gem/mod/jeweler/options.rb +7 -1
- data/lib/bio-gem/templates/database +7 -0
- data/lib/bio-gem/templates/lib +10 -0
- data/lib/bio-gem/templates/migration +20 -0
- data/lib/bio-gem/templates/rakefile +524 -0
- data/lib/bio-gem/templates/seeds +12 -0
- metadata +10 -23
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
= bioruby-gem
|
2
2
|
|
3
|
-
BioGem is a scaffold generator for those Bioinformaticans who want to
|
4
|
-
for using/extending BioRuby's
|
3
|
+
BioGem is a scaffold generator for those Bioinformaticans who want to
|
4
|
+
start coding an application or a library for using/extending BioRuby's
|
5
|
+
core library and sharing it through http://rubygems.org . Biogems are
|
6
|
+
listed at http://biogems.info
|
5
7
|
|
6
8
|
The basic idea is to simplify and promote a modular approach to the BioRuby package.
|
7
9
|
|
@@ -52,8 +54,11 @@ Some of these steps have been condensed:
|
|
52
54
|
|-- Rakefile
|
53
55
|
|-- lib
|
54
56
|
| `-- bio-mystuff.rb
|
55
|
-
|--
|
56
|
-
| `--
|
57
|
+
|-- conf[optional = --with-db]
|
58
|
+
| `-- database.yml put here the configuration of your database like in a rails app
|
59
|
+
|-- db [optional = --with-db] empty but put here your datasets or database(SQLite3?)
|
60
|
+
| |-- seeds.rb a file containing the preloaded datasets, they will be loaded during db setup process
|
61
|
+
| `-- migrate directory for migration, you must create migrations by hand, there is a template inside.
|
57
62
|
`-- test
|
58
63
|
|-- data [optional = --with-test-data]
|
59
64
|
|-- helper.rb
|
@@ -80,6 +85,7 @@ Usage: biogem [options] reponame
|
|
80
85
|
e.g. biogem the-perfect-gem
|
81
86
|
--directory [DIRECTORY] specify the directory to generate into
|
82
87
|
These options are for BioGem
|
88
|
+
--meta create a meta package, just the Rakefile, Gemfile, Licence, Readme. This options takes the precedence over every other option.
|
83
89
|
--with-bin create the bin directory and an executable template script called bioreponame
|
84
90
|
--with-db create the database directory for a db application-library
|
85
91
|
--with-test-data create the data directory inside the test directory if the user need to set up a test with its own dataset
|
@@ -118,6 +124,44 @@ These options are for Jeweler
|
|
118
124
|
--rdoc use rdoc for documentation
|
119
125
|
-h, --help display this help and exit
|
120
126
|
|
127
|
+
== Tasks
|
128
|
+
|
129
|
+
rake build # Build gem into pkg/
|
130
|
+
rake clobber_rcov # Remove rcov products for rcov
|
131
|
+
rake clobber_rdoc # Remove rdoc products
|
132
|
+
rake console[script] # Start IRB with all runtime dependencies loaded
|
133
|
+
rake db:create # Create the database from config/database.yml for the current default (use db:create:all to create all dbs in the config)
|
134
|
+
rake db:drop # Drops the database for the current default (use db:drop:all to drop all databases)
|
135
|
+
rake db:fixtures:load # Load fixtures into the current environment's database.
|
136
|
+
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
|
137
|
+
rake db:migrate:status # Display status of migrations
|
138
|
+
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
|
139
|
+
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
|
140
|
+
rake db:schema:load # Load a schema.rb file into the database
|
141
|
+
rake db:seed # Load the seed data from db/seeds.rb
|
142
|
+
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
|
143
|
+
rake db:structure:dump # Dump the database structure to an SQL file
|
144
|
+
rake db:version # Retrieves the current schema version number
|
145
|
+
rake gemcutter:release # Release gem to Gemcutter
|
146
|
+
rake gemspec # Generate and validate gemspec
|
147
|
+
rake gemspec:debug # Display the gemspec for debugging purposes, as jeweler knows it (not from the filesystem)
|
148
|
+
rake gemspec:generate # Regenreate the gemspec on the filesystem
|
149
|
+
rake gemspec:release # Regenerate and validate gemspec, and then commits and pushes to git
|
150
|
+
rake gemspec:validate # Validates the gemspec on the filesystem
|
151
|
+
rake git:release # Tag and push release to git.
|
152
|
+
rake install # Build and install gem using `gem install`
|
153
|
+
rake rcov # Analyze code coverage with tests
|
154
|
+
rake rdoc # Build the rdoc HTML Files
|
155
|
+
rake release # Release gem
|
156
|
+
rake rerdoc # Force a rebuild of the RDOC files
|
157
|
+
rake test # Run tests
|
158
|
+
rake version # Displays the current version
|
159
|
+
rake version:bump:major # Bump the major version by 1
|
160
|
+
rake version:bump:minor # Bump the a minor version by 1
|
161
|
+
rake version:bump:patch # Bump the patch version by 1
|
162
|
+
rake version:write # Writes out an explicit version.
|
163
|
+
|
164
|
+
|
121
165
|
== NoTes For Developers
|
122
166
|
|
123
167
|
* A GitHub Account is required and you MUST create a repository for your new bioruby plugin.
|
@@ -133,7 +177,50 @@ These options are for Jeweler
|
|
133
177
|
* Help
|
134
178
|
* please use help $ biogem -h to discover other options for creating rspec or cucumber tests
|
135
179
|
|
136
|
-
|
180
|
+
=== DataBaseConnection
|
181
|
+
Is a best practices, at least for me, to have a dummy class which establishes the connection with the database and inherit that class by the models. The benefit of this approach is to have multiple connections available at the same time in case you are developing/using multiple gems with different databases. This file is located in lib/bio/kb
|
182
|
+
|
183
|
+
module Bio
|
184
|
+
module KB
|
185
|
+
class DummyMySpecialDB < ActiveRecord::Base
|
186
|
+
self.abstract_class = true
|
187
|
+
establish_connection(:adapter =>'sqlite3',:database =>"#{File.dirname(__FILE__)}/../../../db/yourdb.sqlite3")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
or you can use the configuration file db/database.yml and add this code to the module above. Note I don't like very much to add every time this code so in a future release I'll find out a way to add it automatically, probably overwriting the configurations call.
|
193
|
+
|
194
|
+
root_path = File.join(File.dirname(__FILE__),"../../../")
|
195
|
+
configurations = YAML.load_file(File.join(root_path,"conf/database.yml"))
|
196
|
+
configurations.each_pair do |key, db_info|
|
197
|
+
db_info["database"] = File.join(root_path, db_info["database"]) if db_info["adapter"]=='sqlite3'
|
198
|
+
end
|
199
|
+
establish_connection(configurations["default"])
|
200
|
+
|
201
|
+
This code is necessary because the db is inside the gem and you can't know where the file will be installed ( using the YAML config file.)
|
202
|
+
|
203
|
+
The model must be located in a directory structure like lib/bio/kb/yourclass this is important because ActiveRecord can map the namespace with the directory tree.
|
204
|
+
|
205
|
+
module Bio
|
206
|
+
module KB
|
207
|
+
module MySpecialDB
|
208
|
+
class Mytable < Bio::KB::DummyMySpecialDB
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
=== Seeds
|
215
|
+
Before populate you seeds.rb file you must declare a model. The model is declared in the usual Rails' way, see above.
|
216
|
+
|
217
|
+
#Use this file to load a default dataset into your database
|
218
|
+
%w(Raoul Toshiaki Francesco).each do |coder|
|
219
|
+
Bio::KB::MySpecialDB::Example.create(:name=>coder, :tag=>"bioruby", :type=>"developer")
|
220
|
+
end
|
221
|
+
|
222
|
+
=== StepByStep
|
223
|
+
Toshiaki Katayama wrote a step by step guide for a bio-foobar plugin @ http://bioruby.open-bio.org/wiki/BiogemInstallation.
|
137
224
|
|
138
225
|
== BioRuby's Wiki Official Documentation
|
139
226
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bio-gem.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bio-gem}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Raoul J.P. Bonnal"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-05}
|
13
13
|
s.default_executable = %q{biogem}
|
14
14
|
s.description = %q{BioGem is a scaffold generator for those Bioinformaticans who want to start coding an application or a library for using/extending BioRuby core library and sharing it through rubygems.org .
|
15
15
|
The basic idea is to simplify and promote a modular approach to the BioRuby package.}
|
@@ -35,13 +35,18 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/bio-gem/mod/jeweler/github_mixin.rb",
|
36
36
|
"lib/bio-gem/mod/jeweler/options.rb",
|
37
37
|
"lib/bio-gem/templates/bin",
|
38
|
+
"lib/bio-gem/templates/database",
|
39
|
+
"lib/bio-gem/templates/lib",
|
40
|
+
"lib/bio-gem/templates/migration",
|
41
|
+
"lib/bio-gem/templates/rakefile",
|
42
|
+
"lib/bio-gem/templates/seeds",
|
38
43
|
"test/helper.rb",
|
39
44
|
"test/test_bio-gem.rb"
|
40
45
|
]
|
41
46
|
s.homepage = %q{http://github.com/helios/bioruby-gem}
|
42
47
|
s.licenses = ["MIT"]
|
43
48
|
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.
|
49
|
+
s.rubygems_version = %q{1.5.0}
|
45
50
|
s.summary = %q{BioGem helps Bioinformaticians start developing plugins/modules for BioRuby creating a scaffold and a gem package}
|
46
51
|
s.test_files = [
|
47
52
|
"test/helper.rb",
|
@@ -49,7 +54,6 @@ Gem::Specification.new do |s|
|
|
49
54
|
]
|
50
55
|
|
51
56
|
if s.respond_to? :specification_version then
|
52
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
57
|
s.specification_version = 3
|
54
58
|
|
55
59
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/bio-gem/mod/jeweler.rb
CHANGED
@@ -9,13 +9,23 @@ class Jeweler
|
|
9
9
|
alias original_initialize initialize
|
10
10
|
def initialize(options = {})
|
11
11
|
original_initialize(options)
|
12
|
-
development_dependencies
|
12
|
+
development_dependencies << ["bio", ">= 1.4.1"]
|
13
|
+
if options[:biogem_db]
|
14
|
+
development_dependencies << ["activerecord", ">= 3.0.7"]
|
15
|
+
development_dependencies << ["activesupport", ">= 3.0.7"]
|
16
|
+
development_dependencies << ["sqlite3", ">= 1.3.3"]
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
alias original_project_name project_name
|
16
21
|
def project_name
|
17
22
|
"bio-#{original_project_name}"
|
18
23
|
end
|
24
|
+
|
25
|
+
def lib_dir
|
26
|
+
'lib'
|
27
|
+
end
|
28
|
+
|
19
29
|
def lib_filename
|
20
30
|
"#{project_name}.rb"
|
21
31
|
end
|
@@ -53,37 +63,70 @@ class Jeweler
|
|
53
63
|
template.result(binding).gsub(/\n\n\n+/, "\n\n")
|
54
64
|
end
|
55
65
|
|
56
|
-
def output_template_in_target_generic(source, destination = source, template_dir = template_dir_biogem)
|
66
|
+
def output_template_in_target_generic(source, destination = source, template_dir = template_dir_biogem, write_type='w')
|
57
67
|
final_destination = File.join(target_dir, destination)
|
58
68
|
template_result = render_template_generic(source, template_dir)
|
59
69
|
|
60
|
-
File.open(final_destination,
|
61
|
-
|
62
|
-
|
70
|
+
File.open(final_destination, write_type) {|file| file.write(template_result)}
|
71
|
+
status = case write_type
|
72
|
+
when 'w' then 'create'
|
73
|
+
when 'a' then 'update'
|
74
|
+
end
|
75
|
+
$stdout.puts "\t#{status}\t#{destination}"
|
63
76
|
end
|
64
77
|
|
65
78
|
def template_dir_biogem
|
66
79
|
File.join(File.dirname(__FILE__),'..', 'templates')
|
67
80
|
end
|
68
81
|
|
82
|
+
|
83
|
+
def create_db_structure
|
84
|
+
migrate_dir = File.join(db_dir, "migrate")
|
85
|
+
mkdir_in_target(db_dir)
|
86
|
+
mkdir_in_target(migrate_dir)
|
87
|
+
mkdir_in_target("conf")
|
88
|
+
output_template_in_target_generic 'database', File.join("conf", "database.yml")
|
89
|
+
output_template_in_target_generic 'migration', File.join(migrate_dir, "001_create_example.rb" )
|
90
|
+
output_template_in_target_generic 'seeds', File.join(db_dir, "seeds.rb")
|
91
|
+
output_template_in_target_generic 'rakefile', 'Rakefile', template_dir_biogem, 'a' #need to spec all the option to enable the append option
|
92
|
+
end
|
93
|
+
|
69
94
|
alias original_create_files create_files
|
70
|
-
# this is the
|
95
|
+
# this is the default directory for storing library datasets
|
71
96
|
# creates a data directory for every needs.
|
72
97
|
#the options are defined in mod/jeweler/options.rb
|
73
98
|
def create_files
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
99
|
+
if options[:biogem_meta]
|
100
|
+
unless File.exists?(target_dir) || File.directory?(target_dir)
|
101
|
+
FileUtils.mkdir target_dir
|
102
|
+
else
|
103
|
+
raise FileInTheWay, "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?"
|
104
|
+
end
|
105
|
+
|
106
|
+
output_template_in_target '.gitignore'
|
107
|
+
output_template_in_target 'Rakefile'
|
108
|
+
output_template_in_target 'Gemfile' if should_use_bundler
|
109
|
+
output_template_in_target 'LICENSE.txt'
|
110
|
+
output_template_in_target 'README.rdoc'
|
111
|
+
output_template_in_target '.document'
|
112
|
+
else
|
113
|
+
original_create_files
|
114
|
+
|
115
|
+
if options[:biogem_test_data]
|
116
|
+
mkdir_in_target("test") unless File.exists? "#{target_dir}/test"
|
117
|
+
mkdir_in_target test_data_dir
|
118
|
+
end
|
119
|
+
create_db_structure if options[:biogem_db]
|
120
|
+
if options[:biogem_bin]
|
121
|
+
mkdir_in_target bin_dir
|
122
|
+
output_template_in_target_generic 'bin', File.join(bin_dir, bin_name)
|
123
|
+
# TODO: set the file as executable
|
124
|
+
File.chmod 0655, File.join(target_dir, bin_dir, bin_name)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Fill lib/bio-plugin.rb with some default comments
|
128
|
+
output_template_in_target_generic 'lib', File.join(lib_dir, lib_filename)
|
129
|
+
end #not_bio_gem_meta
|
87
130
|
end
|
88
131
|
|
89
132
|
def create_and_push_repo
|
@@ -33,7 +33,13 @@ class Jeweler
|
|
33
33
|
|
34
34
|
o.separator "These options are for BioGem"
|
35
35
|
|
36
|
-
#TODO: Scrivere le altre opzioni
|
36
|
+
#TODO: Scrivere le altre opzioni
|
37
|
+
|
38
|
+
#Note this option has the priority over all the other options.
|
39
|
+
o.on("--meta", 'create a meta package, just the Rakefile, Gemfile, Licence, Readme. This options takes the precedence over every other option.') do
|
40
|
+
self[:biogem_meta] = true
|
41
|
+
end
|
42
|
+
|
37
43
|
o.on("--with-bin", 'create the bin directory and an executable template script called bioreponame') do
|
38
44
|
self[:biogem_bin] = true
|
39
45
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Please require your code below, respecting the bioruby directory tree.
|
2
|
+
# For instance, perhaps the only uncommented line in this file might
|
3
|
+
# be something like this:
|
4
|
+
#
|
5
|
+
# require 'bio/sequence/awesome_sequence_plugin_thingy'
|
6
|
+
#
|
7
|
+
# and then create the ruby file 'lib/bio/sequence/awesome_sequence_thingy.rb'
|
8
|
+
# and put your plugin's code there. It is bad practice to write other code
|
9
|
+
# directly into this file, because doing so causes confusion if this biogem
|
10
|
+
# was ever to get merged into the main bioruby tree.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# # The code below create a table name example
|
2
|
+
# # As best practice name this file with a prefix index like 001_create_example.rb and the next migration 002.... and so on, this will help you to keep track over the time.
|
3
|
+
# # Please refer to Rails' documentation
|
4
|
+
#
|
5
|
+
# class CreateExample < ActiveRecord::Migration
|
6
|
+
# def self.up
|
7
|
+
# #primary key id is created automatically by ActiveRecord::Migration
|
8
|
+
# create_table :example do |t|
|
9
|
+
# t.string :name
|
10
|
+
# t.string :tag
|
11
|
+
# t.string :type
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# add_index :example, :name
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# def self.down
|
18
|
+
# drop_table :example
|
19
|
+
# end
|
20
|
+
# end
|
@@ -0,0 +1,524 @@
|
|
1
|
+
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'lib')
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
5
|
+
require 'active_support/core_ext/module/delegation'
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
#This code is coming from activerecord-3.0.7/lib/active_record/railties/databases.rake
|
9
|
+
namespace :db do
|
10
|
+
task :load_config do
|
11
|
+
require 'active_record'
|
12
|
+
ActiveRecord::Base.configurations = YAML.load_file("conf/database.yml")
|
13
|
+
end
|
14
|
+
|
15
|
+
task :environment => :load_config do
|
16
|
+
ActiveRecord::Base.establish_connection('default')
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :create do
|
20
|
+
# desc 'Create all the local databases defined in config/database.yml'
|
21
|
+
task :all => :load_config do
|
22
|
+
ActiveRecord::Base.configurations.each_value do |config|
|
23
|
+
# Skip entries that don't have a database key, such as the first entry here:
|
24
|
+
#
|
25
|
+
# defaults: &defaults
|
26
|
+
# adapter: mysql
|
27
|
+
# username: root
|
28
|
+
# password:
|
29
|
+
# host: localhost
|
30
|
+
#
|
31
|
+
# development:
|
32
|
+
# database: blog_development
|
33
|
+
# <<: *defaults
|
34
|
+
next unless config['database']
|
35
|
+
# Only connect to local databases
|
36
|
+
local_database?(config) { create_database(config) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Create the database from config/database.yml for the current default (use db:create:all to create all dbs in the config)'
|
42
|
+
task :create => :load_config do
|
43
|
+
# Make the test database at the same time as the development one, if it exists
|
44
|
+
# if 'default'.development? && ActiveRecord::Base.configurations['test']
|
45
|
+
create_database(ActiveRecord::Base.configurations['default'])
|
46
|
+
# end
|
47
|
+
# create_database(ActiveRecord::Base.configurations['default'])
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_database(config)
|
51
|
+
begin
|
52
|
+
if config['adapter'] =~ /sqlite/
|
53
|
+
if File.exist?(config['database'])
|
54
|
+
$stderr.puts "#{config['database']} already exists"
|
55
|
+
else
|
56
|
+
begin
|
57
|
+
# Create the SQLite database
|
58
|
+
ActiveRecord::Base.establish_connection(config)
|
59
|
+
ActiveRecord::Base.connection
|
60
|
+
rescue Exception => e
|
61
|
+
$stderr.puts e, *(e.backtrace)
|
62
|
+
$stderr.puts "Couldn't create database for #{config.inspect}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return # Skip the else clause of begin/rescue
|
66
|
+
else
|
67
|
+
ActiveRecord::Base.establish_connection(config)
|
68
|
+
ActiveRecord::Base.connection
|
69
|
+
end
|
70
|
+
rescue
|
71
|
+
case config['adapter']
|
72
|
+
when /mysql/
|
73
|
+
@charset = ENV['CHARSET'] || 'utf8'
|
74
|
+
@collation = ENV['COLLATION'] || 'utf8_unicode_ci'
|
75
|
+
creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
|
76
|
+
error_class = config['adapter'] =~ /mysql2/ ? Mysql2::Error : Mysql::Error
|
77
|
+
access_denied_error = 1045
|
78
|
+
begin
|
79
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
80
|
+
ActiveRecord::Base.connection.create_database(config['database'], creation_options)
|
81
|
+
ActiveRecord::Base.establish_connection(config)
|
82
|
+
rescue error_class => sqlerr
|
83
|
+
if sqlerr.errno == access_denied_error
|
84
|
+
print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
|
85
|
+
root_password = $stdin.gets.strip
|
86
|
+
grant_statement = "GRANT ALL PRIVILEGES ON #{config['database']}.* " \
|
87
|
+
"TO '#{config['username']}'@'localhost' " \
|
88
|
+
"IDENTIFIED BY '#{config['password']}' WITH GRANT OPTION;"
|
89
|
+
ActiveRecord::Base.establish_connection(config.merge(
|
90
|
+
'database' => nil, 'username' => 'root', 'password' => root_password))
|
91
|
+
ActiveRecord::Base.connection.create_database(config['database'], creation_options)
|
92
|
+
ActiveRecord::Base.connection.execute grant_statement
|
93
|
+
ActiveRecord::Base.establish_connection(config)
|
94
|
+
else
|
95
|
+
$stderr.puts sqlerr.error
|
96
|
+
$stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation}"
|
97
|
+
$stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config['charset']
|
98
|
+
end
|
99
|
+
end
|
100
|
+
when 'postgresql'
|
101
|
+
@encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'
|
102
|
+
begin
|
103
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
104
|
+
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
|
105
|
+
ActiveRecord::Base.establish_connection(config)
|
106
|
+
rescue Exception => e
|
107
|
+
$stderr.puts e, *(e.backtrace)
|
108
|
+
$stderr.puts "Couldn't create database for #{config.inspect}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
else
|
112
|
+
$stderr.puts "#{config['database']} already exists"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
namespace :drop do
|
117
|
+
# desc 'Drops all the local databases defined in config/database.yml'
|
118
|
+
task :all => :load_config do
|
119
|
+
ActiveRecord::Base.configurations.each_value do |config|
|
120
|
+
# Skip entries that don't have a database key
|
121
|
+
next unless config['database']
|
122
|
+
begin
|
123
|
+
# Only connect to local databases
|
124
|
+
local_database?(config) { drop_database(config) }
|
125
|
+
rescue Exception => e
|
126
|
+
$stderr.puts "Couldn't drop #{config['database']} : #{e.inspect}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
desc 'Drops the database for the current default (use db:drop:all to drop all databases)'
|
133
|
+
task :drop => :load_config do
|
134
|
+
config = ActiveRecord::Base.configurations['default' || 'development']
|
135
|
+
begin
|
136
|
+
drop_database(config)
|
137
|
+
rescue Exception => e
|
138
|
+
$stderr.puts "Couldn't drop #{config['database']} : #{e.inspect}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def local_database?(config, &block)
|
143
|
+
if %w( 127.0.0.1 localhost ).include?(config['host']) || config['host'].blank?
|
144
|
+
yield
|
145
|
+
else
|
146
|
+
$stderr.puts "This task only modifies local databases. #{config['database']} is on a remote host."
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
|
152
|
+
task :migrate => :environment do
|
153
|
+
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
154
|
+
ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
155
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
156
|
+
end
|
157
|
+
|
158
|
+
namespace :migrate do
|
159
|
+
# desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
160
|
+
task :redo => :environment do
|
161
|
+
if ENV["VERSION"]
|
162
|
+
Rake::Task["db:migrate:down"].invoke
|
163
|
+
Rake::Task["db:migrate:up"].invoke
|
164
|
+
else
|
165
|
+
Rake::Task["db:rollback"].invoke
|
166
|
+
Rake::Task["db:migrate"].invoke
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# desc 'Resets your database using your migrations for the current environment'
|
171
|
+
task :reset => ["db:drop", "db:create", "db:migrate"]
|
172
|
+
|
173
|
+
# desc 'Runs the "up" for a given migration VERSION.'
|
174
|
+
task :up => :environment do
|
175
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
176
|
+
raise "VERSION is required" unless version
|
177
|
+
ActiveRecord::Migrator.run(:up, "db/migrate/", version)
|
178
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
179
|
+
end
|
180
|
+
|
181
|
+
# desc 'Runs the "down" for a given migration VERSION.'
|
182
|
+
task :down => :environment do
|
183
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
184
|
+
raise "VERSION is required" unless version
|
185
|
+
ActiveRecord::Migrator.run(:down, "db/migrate/", version)
|
186
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
187
|
+
end
|
188
|
+
|
189
|
+
desc "Display status of migrations"
|
190
|
+
task :status => :environment do
|
191
|
+
config = ActiveRecord::Base.configurations['default']
|
192
|
+
ActiveRecord::Base.establish_connection(config)
|
193
|
+
unless ActiveRecord::Base.connection.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
|
194
|
+
puts 'Schema migrations table does not exist yet.'
|
195
|
+
next # means "return" for rake task
|
196
|
+
end
|
197
|
+
db_list = ActiveRecord::Base.connection.select_values("SELECT version FROM #{ActiveRecord::Migrator.schema_migrations_table_name}")
|
198
|
+
file_list = []
|
199
|
+
Dir.foreach(File.join('db', 'migrate')) do |file|
|
200
|
+
# only files matching "20091231235959_some_name.rb" pattern
|
201
|
+
if match_data = /(\d{14})_(.+)\.rb/.match(file)
|
202
|
+
status = db_list.delete(match_data[1]) ? 'up' : 'down'
|
203
|
+
file_list << [status, match_data[1], match_data[2]]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
# output
|
207
|
+
puts "\ndatabase: #{config['database']}\n\n"
|
208
|
+
puts "#{"Status".center(8)} #{"Migration ID".ljust(14)} Migration Name"
|
209
|
+
puts "-" * 50
|
210
|
+
file_list.each do |file|
|
211
|
+
puts "#{file[0].center(8)} #{file[1].ljust(14)} #{file[2].humanize}"
|
212
|
+
end
|
213
|
+
db_list.each do |version|
|
214
|
+
puts "#{'up'.center(8)} #{version.ljust(14)} *** NO FILE ***"
|
215
|
+
end
|
216
|
+
puts
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
221
|
+
task :rollback => :environment do
|
222
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
223
|
+
ActiveRecord::Migrator.rollback('db/migrate/', step)
|
224
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
225
|
+
end
|
226
|
+
|
227
|
+
# desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
|
228
|
+
task :forward => :environment do
|
229
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
230
|
+
ActiveRecord::Migrator.forward('db/migrate/', step)
|
231
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
232
|
+
end
|
233
|
+
|
234
|
+
# desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
|
235
|
+
task :reset => [ 'db:drop', 'db:setup' ]
|
236
|
+
|
237
|
+
# desc "Retrieves the charset for the current environment's database"
|
238
|
+
task :charset => :environment do
|
239
|
+
config = ActiveRecord::Base.configurations['default' || 'development']
|
240
|
+
case config['adapter']
|
241
|
+
when /mysql/
|
242
|
+
ActiveRecord::Base.establish_connection(config)
|
243
|
+
puts ActiveRecord::Base.connection.charset
|
244
|
+
when 'postgresql'
|
245
|
+
ActiveRecord::Base.establish_connection(config)
|
246
|
+
puts ActiveRecord::Base.connection.encoding
|
247
|
+
when 'sqlite3'
|
248
|
+
ActiveRecord::Base.establish_connection(config)
|
249
|
+
puts ActiveRecord::Base.connection.encoding
|
250
|
+
else
|
251
|
+
$stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# desc "Retrieves the collation for the current environment's database"
|
256
|
+
task :collation => :environment do
|
257
|
+
config = ActiveRecord::Base.configurations['default']
|
258
|
+
case config['adapter']
|
259
|
+
when /mysql/
|
260
|
+
ActiveRecord::Base.establish_connection(config)
|
261
|
+
puts ActiveRecord::Base.connection.collation
|
262
|
+
else
|
263
|
+
$stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
desc "Retrieves the current schema version number"
|
268
|
+
task :version => :environment do
|
269
|
+
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
270
|
+
end
|
271
|
+
|
272
|
+
# desc "Raises an error if there are pending migrations"
|
273
|
+
task :abort_if_pending_migrations => :environment do
|
274
|
+
if defined? ActiveRecord
|
275
|
+
pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
|
276
|
+
|
277
|
+
if pending_migrations.any?
|
278
|
+
puts "You have #{pending_migrations.size} pending migrations:"
|
279
|
+
pending_migrations.each do |pending_migration|
|
280
|
+
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
|
281
|
+
end
|
282
|
+
abort %{Run "rake db:migrate" to update your database then try again.}
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
desc 'Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)'
|
288
|
+
task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ]
|
289
|
+
|
290
|
+
desc 'Load the seed data from db/seeds.rb'
|
291
|
+
task :seed => 'db:abort_if_pending_migrations' do
|
292
|
+
seed_file = File.join('db', 'seeds.rb')
|
293
|
+
load(seed_file) if File.exist?(seed_file)
|
294
|
+
end
|
295
|
+
|
296
|
+
namespace :fixtures do
|
297
|
+
desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
|
298
|
+
task :load => :environment do
|
299
|
+
require 'active_record/fixtures'
|
300
|
+
|
301
|
+
ActiveRecord::Base.establish_connection('default')
|
302
|
+
base_dir = ENV['FIXTURES_PATH'] ? File.join(ENV['FIXTURES_PATH']) : File.join('test', 'fixtures')
|
303
|
+
fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
|
304
|
+
|
305
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir["#{fixtures_dir}/**/*.{yml,csv}"]).each do |fixture_file|
|
306
|
+
Fixtures.create_fixtures(fixtures_dir, fixture_file[(fixtures_dir.size + 1)..-5])
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
# desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
|
311
|
+
task :identify => :environment do
|
312
|
+
require 'active_record/fixtures'
|
313
|
+
|
314
|
+
label, id = ENV["LABEL"], ENV["ID"]
|
315
|
+
raise "LABEL or ID required" if label.blank? && id.blank?
|
316
|
+
|
317
|
+
puts %Q(The fixture ID for "#{label}" is #{Fixtures.identify(label)}.) if label
|
318
|
+
|
319
|
+
base_dir = ENV['FIXTURES_PATH'] ? File.join(ENV['FIXTURES_PATH']) : File.join('test', 'fixtures')
|
320
|
+
Dir["#{base_dir}/**/*.yml"].each do |file|
|
321
|
+
if data = YAML::load(ERB.new(IO.read(file)).result)
|
322
|
+
data.keys.each do |key|
|
323
|
+
key_id = Fixtures.identify(key)
|
324
|
+
|
325
|
+
if key == label || key_id == id.to_i
|
326
|
+
puts "#{file}: #{key} (#{key_id})"
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
namespace :schema do
|
335
|
+
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
|
336
|
+
task :dump => :environment do
|
337
|
+
require 'active_record/schema_dumper'
|
338
|
+
File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
|
339
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
340
|
+
end
|
341
|
+
Rake::Task["db:schema:dump"].reenable
|
342
|
+
end
|
343
|
+
|
344
|
+
desc "Load a schema.rb file into the database"
|
345
|
+
task :load => :environment do
|
346
|
+
file = ENV['SCHEMA'] || "db/schema.rb"
|
347
|
+
if File.exists?(file)
|
348
|
+
load(file)
|
349
|
+
else
|
350
|
+
abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter config/application.rb to limit the frameworks that will be loaded}
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
namespace :structure do
|
356
|
+
desc "Dump the database structure to an SQL file"
|
357
|
+
task :dump => :environment do
|
358
|
+
abcs = ActiveRecord::Base.configurations
|
359
|
+
case abcs['default']["adapter"]
|
360
|
+
when /mysql/, "oci", "oracle"
|
361
|
+
ActiveRecord::Base.establish_connection(abcs['default'])
|
362
|
+
File.open("db/#{'default'}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
363
|
+
when "postgresql"
|
364
|
+
ENV['PGHOST'] = abcs['default']["host"] if abcs['default']["host"]
|
365
|
+
ENV['PGPORT'] = abcs['default']["port"].to_s if abcs['default']["port"]
|
366
|
+
ENV['PGPASSWORD'] = abcs['default']["password"].to_s if abcs['default']["password"]
|
367
|
+
search_path = abcs['default']["schema_search_path"]
|
368
|
+
unless search_path.blank?
|
369
|
+
search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
|
370
|
+
end
|
371
|
+
`pg_dump -i -U "#{abcs['default']["username"]}" -s -x -O -f db/default_structure.sql #{search_path} #{abcs['default']["database"]}`
|
372
|
+
raise "Error dumping database" if $?.exitstatus == 1
|
373
|
+
when "sqlite", "sqlite3"
|
374
|
+
dbfile = abcs['default']["database"] || abcs['default']["dbfile"]
|
375
|
+
`#{abcs['default']["adapter"]} #{dbfile} .schema > db/#{'default'}_structure.sql`
|
376
|
+
when "sqlserver"
|
377
|
+
`scptxfr /s #{abcs['default']["host"]} /d #{abcs['default']["database"]} /I /f db\\#{'default'}_structure.sql /q /A /r`
|
378
|
+
`scptxfr /s #{abcs['default']["host"]} /d #{abcs['default']["database"]} /I /F db\ /q /A /r`
|
379
|
+
when "firebird"
|
380
|
+
set_firebird_env(abcs['default'])
|
381
|
+
db_string = firebird_db_string(abcs['default'])
|
382
|
+
sh "isql -a #{db_string} > db/#{'default'}_structure.sql"
|
383
|
+
else
|
384
|
+
raise "Task not supported by '#{abcs['default']["adapter"]}'"
|
385
|
+
end
|
386
|
+
|
387
|
+
if ActiveRecord::Base.connection.supports_migrations?
|
388
|
+
File.open("db/#{'default'}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
namespace :test do
|
394
|
+
# desc "Recreate the test database from the current schema.rb"
|
395
|
+
task :load => 'db:test:purge' do
|
396
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
|
397
|
+
ActiveRecord::Schema.verbose = false
|
398
|
+
Rake::Task["db:schema:load"].invoke
|
399
|
+
end
|
400
|
+
|
401
|
+
# desc "Recreate the test database from the current environment's database schema"
|
402
|
+
task :clone => %w(db:schema:dump db:test:load)
|
403
|
+
|
404
|
+
# desc "Recreate the test databases from the development structure"
|
405
|
+
task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
|
406
|
+
abcs = ActiveRecord::Base.configurations
|
407
|
+
case abcs["test"]["adapter"]
|
408
|
+
when /mysql/
|
409
|
+
ActiveRecord::Base.establish_connection(:test)
|
410
|
+
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
|
411
|
+
IO.readlines("db/#{'default'}_structure.sql").join.split("\n\n").each do |table|
|
412
|
+
ActiveRecord::Base.connection.execute(table)
|
413
|
+
end
|
414
|
+
when "postgresql"
|
415
|
+
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
|
416
|
+
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
|
417
|
+
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
|
418
|
+
`psql -U "#{abcs["test"]["username"]}" -f db/#{'default'}_structure.sql #{abcs["test"]["database"]}`
|
419
|
+
when "sqlite", "sqlite3"
|
420
|
+
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
|
421
|
+
`#{abcs["test"]["adapter"]} #{dbfile} < db/#{'default'}_structure.sql`
|
422
|
+
when "sqlserver"
|
423
|
+
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{'default'}_structure.sql`
|
424
|
+
when "oci", "oracle"
|
425
|
+
ActiveRecord::Base.establish_connection(:test)
|
426
|
+
IO.readlines("db/#{'default'}_structure.sql").join.split(";\n\n").each do |ddl|
|
427
|
+
ActiveRecord::Base.connection.execute(ddl)
|
428
|
+
end
|
429
|
+
when "firebird"
|
430
|
+
set_firebird_env(abcs["test"])
|
431
|
+
db_string = firebird_db_string(abcs["test"])
|
432
|
+
sh "isql -i db/#{'default'}_structure.sql #{db_string}"
|
433
|
+
else
|
434
|
+
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
# desc "Empty the test database"
|
439
|
+
task :purge => :environment do
|
440
|
+
abcs = ActiveRecord::Base.configurations
|
441
|
+
case abcs["test"]["adapter"]
|
442
|
+
when /mysql/
|
443
|
+
ActiveRecord::Base.establish_connection(:test)
|
444
|
+
ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"], abcs["test"])
|
445
|
+
when "postgresql"
|
446
|
+
ActiveRecord::Base.clear_active_connections!
|
447
|
+
drop_database(abcs['test'])
|
448
|
+
create_database(abcs['test'])
|
449
|
+
when "sqlite","sqlite3"
|
450
|
+
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
|
451
|
+
File.delete(dbfile) if File.exist?(dbfile)
|
452
|
+
when "sqlserver"
|
453
|
+
dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
|
454
|
+
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
|
455
|
+
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{'default'}_structure.sql`
|
456
|
+
when "oci", "oracle"
|
457
|
+
ActiveRecord::Base.establish_connection(:test)
|
458
|
+
ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
|
459
|
+
ActiveRecord::Base.connection.execute(ddl)
|
460
|
+
end
|
461
|
+
when "firebird"
|
462
|
+
ActiveRecord::Base.establish_connection(:test)
|
463
|
+
ActiveRecord::Base.connection.recreate_database!
|
464
|
+
else
|
465
|
+
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
# desc 'Check for pending migrations and load the test schema'
|
470
|
+
task :prepare => 'db:abort_if_pending_migrations' do
|
471
|
+
if defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
|
472
|
+
Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:load" }[ActiveRecord::Base.schema_format]].invoke
|
473
|
+
end
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
namespace :sessions do
|
478
|
+
# desc "Creates a sessions migration for use with ActiveRecord::SessionStore"
|
479
|
+
task :create => :environment do
|
480
|
+
raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
|
481
|
+
require 'rails/generators'
|
482
|
+
Rails::Generators.configure!
|
483
|
+
require 'rails/generators/rails/session_migration/session_migration_generator'
|
484
|
+
Rails::Generators::SessionMigrationGenerator.start [ ENV["MIGRATION"] || "add_sessions_table" ]
|
485
|
+
end
|
486
|
+
|
487
|
+
# desc "Clear the sessions table"
|
488
|
+
task :clear => :environment do
|
489
|
+
ActiveRecord::Base.connection.execute "DELETE FROM #{session_table_name}"
|
490
|
+
end
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
task 'test:prepare' => 'db:test:prepare'
|
495
|
+
|
496
|
+
def drop_database(config)
|
497
|
+
case config['adapter']
|
498
|
+
when /mysql/
|
499
|
+
ActiveRecord::Base.establish_connection(config)
|
500
|
+
ActiveRecord::Base.connection.drop_database config['database']
|
501
|
+
when /^sqlite/
|
502
|
+
require 'pathname'
|
503
|
+
path = Pathname.new(config['database'])
|
504
|
+
file = path.absolute? ? path.to_s : File.join( path)
|
505
|
+
|
506
|
+
FileUtils.rm(file)
|
507
|
+
when 'postgresql'
|
508
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
509
|
+
ActiveRecord::Base.connection.drop_database config['database']
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
def session_table_name
|
514
|
+
ActiveRecord::SessionStore::Session.table_name
|
515
|
+
end
|
516
|
+
|
517
|
+
def set_firebird_env(config)
|
518
|
+
ENV["ISC_USER"] = config["username"].to_s if config["username"]
|
519
|
+
ENV["ISC_PASSWORD"] = config["password"].to_s if config["password"]
|
520
|
+
end
|
521
|
+
|
522
|
+
def firebird_db_string(config)
|
523
|
+
FireRuby::Database.db_string_for(config.symbolize_keys)
|
524
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#require '<%= project_name %>'
|
2
|
+
# # NOTE: You must define your model somewhere in your library
|
3
|
+
# # and you must keep in mind that if you decide to have
|
4
|
+
# # MultilabelNamespace you must create the right directory
|
5
|
+
# # structure for it:
|
6
|
+
# # Suppose Bio::Project::Mymodel < ActiveRecord::Base or a dummy class with the connection.
|
7
|
+
# # Checkout the documentation.
|
8
|
+
# # bioruby-gem/lib/bio/project/mymodel.rb
|
9
|
+
# #Use this file to load a default dataset into your database
|
10
|
+
# %w(Raoul Toshiaki Francesco).each do |coder|
|
11
|
+
# YourNameSpace Example.create(:name=>coder, :tag=>"bioruby", :type=>"developer")
|
12
|
+
# end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bio-gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 2
|
9
|
-
version: 0.2.2
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Raoul J.P. Bonnal
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-08-05 00:00:00 +02:00
|
18
14
|
default_executable: biogem
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,8 +20,6 @@ dependencies:
|
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
23
|
version: "0"
|
30
24
|
type: :development
|
31
25
|
prerelease: false
|
@@ -37,10 +31,6 @@ dependencies:
|
|
37
31
|
requirements:
|
38
32
|
- - ~>
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
segments:
|
41
|
-
- 1
|
42
|
-
- 0
|
43
|
-
- 0
|
44
34
|
version: 1.0.0
|
45
35
|
type: :development
|
46
36
|
prerelease: false
|
@@ -52,10 +42,6 @@ dependencies:
|
|
52
42
|
requirements:
|
53
43
|
- - ~>
|
54
44
|
- !ruby/object:Gem::Version
|
55
|
-
segments:
|
56
|
-
- 1
|
57
|
-
- 5
|
58
|
-
- 1
|
59
45
|
version: 1.5.1
|
60
46
|
type: :development
|
61
47
|
prerelease: false
|
@@ -67,8 +53,6 @@ dependencies:
|
|
67
53
|
requirements:
|
68
54
|
- - ">="
|
69
55
|
- !ruby/object:Gem::Version
|
70
|
-
segments:
|
71
|
-
- 0
|
72
56
|
version: "0"
|
73
57
|
type: :development
|
74
58
|
prerelease: false
|
@@ -100,6 +84,11 @@ files:
|
|
100
84
|
- lib/bio-gem/mod/jeweler/github_mixin.rb
|
101
85
|
- lib/bio-gem/mod/jeweler/options.rb
|
102
86
|
- lib/bio-gem/templates/bin
|
87
|
+
- lib/bio-gem/templates/database
|
88
|
+
- lib/bio-gem/templates/lib
|
89
|
+
- lib/bio-gem/templates/migration
|
90
|
+
- lib/bio-gem/templates/rakefile
|
91
|
+
- lib/bio-gem/templates/seeds
|
103
92
|
- test/helper.rb
|
104
93
|
- test/test_bio-gem.rb
|
105
94
|
has_rdoc: true
|
@@ -116,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
105
|
requirements:
|
117
106
|
- - ">="
|
118
107
|
- !ruby/object:Gem::Version
|
119
|
-
hash:
|
108
|
+
hash: -1492955173838724395
|
120
109
|
segments:
|
121
110
|
- 0
|
122
111
|
version: "0"
|
@@ -125,13 +114,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
114
|
requirements:
|
126
115
|
- - ">="
|
127
116
|
- !ruby/object:Gem::Version
|
128
|
-
segments:
|
129
|
-
- 0
|
130
117
|
version: "0"
|
131
118
|
requirements: []
|
132
119
|
|
133
120
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.
|
121
|
+
rubygems_version: 1.5.0
|
135
122
|
signing_key:
|
136
123
|
specification_version: 3
|
137
124
|
summary: BioGem helps Bioinformaticians start developing plugins/modules for BioRuby creating a scaffold and a gem package
|