public
Fork of vigetlabs/foreign_key_migrations
Description: A gem/plugin for ActiveRecord that lets you define foreign keys in migrations.
Clone URL: git://github.com/crnixon/foreign_key_migrations.git
moved to Mr Bones structure
crnixon (author)
Mon Jul 14 20:21:28 -0700 2008
commit  c55e20743ac60efbe2da1505f907e1534743d0e2
tree    4a5aa56747b917f8feadc14dd5a77bfd25d31876
parent  3adbfb919f6649535f9bdcce95e8d75f0a4b743d
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
 
35
36
37
38
39
 
 
40
41
42
43
44
45
46
47
48
49
50
 
51
52
53
54
55
56
57
 
 
 
 
 
 
 
58
59
60
61
62
63
64
65
 
 
66
67
68
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
 
 
 
 
6
7
8
 
 
 
 
 
 
 
 
 
 
9
10
 
 
 
 
 
 
11
12
13
14
15
16
17
18
 
 
 
 
 
 
19
20
21
22
 
23
0
@@ -1,67 +1,22 @@
0
-require 'rubygems'
0
-require 'rake'
0
-require 'rake/clean'
0
-require 'rake/testtask'
0
-require 'rake/packagetask'
0
-require 'rake/gempackagetask'
0
-require 'rake/rdoctask'
0
-require 'fileutils'
0
-
0
-include FileUtils
0
-require File.join(File.dirname(__FILE__), 'lib', 'foreign_key_migrations')
0
-
0
-AUTHOR = 'Clinton R. Nixon' # can also be an array of Authors
0
-EMAIL = "clinton.nixon@viget.com"
0
-DESCRIPTION = "Adds foreign key migrations to ActiveRecord."
0
-GEM_NAME = 'foreign_key_migrations' # what ppl will type to install your gem
0
-VERS = Viget::ForeignKeyMigrations::VERSION::STRING
0
+load 'tasks/setup.rb'
0
 
0
-spec = Gem::Specification.new do |s|
0
- s.name = GEM_NAME
0
- s.version = VERS
0
- s.author = AUTHOR
0
- s.email = EMAIL
0
- s.homepage = "http://trac.extendviget.com/"
0
- s.platform = Gem::Platform::RUBY
0
- s.summary = DESCRIPTION
0
- s.files = FileList["lib/**/*"].to_a
0
- s.require_path = "lib"
0
- s.rubyforge_project = 'viget'
0
- s.test_files = FileList["test/**/*_test.rb"].to_a
0
- s.has_rdoc = true
0
- s.extra_rdoc_files = ["README", "CHANGELOG", "MIT_LICENSE"]
0
- s.add_dependency("activerecord", ">= 1.15.0")
0
-end
0
+require 'rubygems'
0
+require 'activerecord'
0
 
0
-desc 'Generate a gem for foreign_key_migrations.'
0
-Rake::GemPackageTask.new(spec) do |pkg|
0
- pkg.need_tar = true
0
-end
0
+ensure_in_path 'lib'
0
+require 'foreign_key_migrations'
0
 
0
-desc 'Generate documentation for the foreign_key_migrations gem.'
0
-Rake::RDocTask.new(:rdoc) do |rdoc|
0
- rdoc.rdoc_dir = 'rdoc'
0
- rdoc.title = 'ForeignKeyMigrations'
0
- rdoc.options << '--main=README' << '--line-numbers' << '--inline-source'
0
- rdoc.rdoc_files.include('lib/**/*.rb')
0
- spec.extra_rdoc_files.each do |file|
0
- rdoc.rdoc_files.include(file)
0
- end
0
-end
0
+task :default => 'test:run'
0
 
0
-desc 'Test the foreign_key_migrations plugin.'
0
-Rake::TestTask.new(:test) do |t|
0
- t.libs << 'lib' << 'test'
0
- t.pattern = 'test/**/*_test.rb'
0
- t.verbose = true
0
-end
0
+PROJ.name = 'foreign_key_migrations'
0
+PROJ.authors = 'Clinton R. Nixon'
0
+PROJ.email = 'clinton.nixon@viget.com'
0
+PROJ.url = 'http://github.com/crnixon/foreign_key_migrations'
0
+PROJ.rubyforge.name = 'foreign_key_migrations'
0
+PROJ.version = Viget::ForeignKeyMigrations.version
0
+PROJ.gem.dependencies = [['activerecord']] # ['gem', '>= version']
0
 
0
-desc 'Test the foreign_key_migrations plugin against actual databases.'
0
-Rake::TestTask.new(:integration_test) do |t|
0
- t.libs << 'lib' << 'integration_tests'
0
- t.pattern = 'integration_tests/**/*_test.rb'
0
- t.verbose = true
0
-end
0
 
0
+DESCRIPTION = "Adds foreign key migrations to ActiveRecord."
0
+GEM_NAME = 'foreign_key_migrations' # what ppl will type to install your gem
0
 
0
-task :default => :test
0
\ No newline at end of file
...
1
2
3
4
 
 
 
 
 
 
 
 
5
6
7
8
9
10
11
 
 
 
 
 
12
13
 
 
 
 
 
 
14
15
16
17
18
19
 
 
 
 
 
 
 
20
21
 
 
 
 
 
 
 
 
 
 
 
22
23
24
25
26
27
28
29
30
31
32
33
34
 
 
 
 
 
 
 
 
 
 
35
36
37
38
 
 
 
 
39
40
41
42
43
44
45
46
47
48
 
 
 
 
 
 
 
49
50
51
 
...
1
 
2
3
4
5
6
7
8
9
10
11
12
 
 
 
 
 
 
13
14
15
16
17
18
 
19
20
21
22
23
24
25
 
 
26
 
 
27
28
29
30
31
32
33
34
 
35
36
37
38
39
40
41
42
43
44
45
46
 
 
 
 
 
 
47
 
48
 
 
 
49
50
51
52
53
54
55
56
57
58
59
 
 
 
60
61
62
63
64
 
 
 
 
 
 
 
 
 
65
66
67
68
69
70
71
72
 
73
74
0
@@ -1,50 +1,73 @@
0
 unless defined?(Viget::ForeignKeyMigrations)
0
-
0
   require 'rubygems'
0
   require 'activerecord'
0
+
0
+ module Viget
0
+ module ForeignKeyMigrations
0
+ # :stopdoc:
0
+ VERSION = '0.3.2'
0
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
0
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
0
+ # :startdoc:
0
 
0
- module Viget #:nodoc:
0
- module ForeignKeyMigrations #:nodoc:
0
- module VERSION #:nodoc:
0
- MAJOR = 0
0
- MINOR = 3
0
- TINY = 1
0
+ # Returns the version string for the library.
0
+ #
0
+ def self.version
0
+ VERSION
0
+ end
0
 
0
- STRING = [MAJOR, MINOR, TINY].join('.')
0
+ # Returns the library path for the module. If any arguments are given,
0
+ # they will be joined to the end of the libray path using
0
+ # <tt>File.join</tt>.
0
+ #
0
+ def self.libpath( *args )
0
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
0
       end
0
- end
0
- end
0
 
0
- module_name = 'ActiveRecord::ConnectionAdapters'
0
- adapter_names = [ 'MysqlAdapter', 'PostgreSQLAdapter', 'SQLiteAdapter', 'SQLite3Adapter' ]
0
+ # Returns the lpath for the module. If any arguments are given,
0
+ # they will be joined to the end of the path using
0
+ # <tt>File.join</tt>.
0
+ #
0
+ def self.path( *args )
0
+ args.empty? ? PATH : ::File.join(PATH, *args)
0
+ end
0
 
0
- libdir = File.dirname(__FILE__)
0
+ # Utility method used to rquire all files ending in .rb that lie in the
0
+ # directory below this file that has the same name as the filename passed
0
+ # in. Optionally, a specific _directory_ name can be passed in such that
0
+ # the _filename_ does not have to be equivalent to the directory.
0
+ #
0
+ def self.require_all_libs_relative_to( fname, dir = nil )
0
+ dir ||= ::File.basename(fname, '.*')
0
+ search_me = ::File.expand_path(::File.join(::File.dirname(fname), dir, '**', '*.rb'))
0
+
0
+ Dir.glob(search_me).sort.each {|rb| require rb}
0
+ end
0
 
0
- adapter_names.each do |name|
0
- filename = name.downcase.sub(/adapter$/, '_adapter')
0
- begin
0
- require "#{module_name.underscore}/#{filename}"
0
- rescue LoadError
0
- nil
0
     end
0
- end
0
 
0
- require File.join(libdir, "foreign_key_migrations/database_support")
0
- require File.join(libdir, "foreign_key_migrations/database_support/postgresql_adapter")
0
- require File.join(libdir, "foreign_key_migrations/database_support/sqlite_adapter")
0
+ module_name = 'ActiveRecord::ConnectionAdapters'
0
+ adapter_names = [ 'MysqlAdapter', 'PostgreSQLAdapter', 'SQLiteAdapter', 'SQLite3Adapter' ]
0
+ adapter_names.each do |name|
0
+ filename = name.downcase.sub(/adapter$/, '_adapter')
0
+ begin
0
+ require "#{module_name.underscore}/#{filename}"
0
+ rescue LoadError
0
+ nil
0
+ end
0
+ end
0
 
0
- require File.join(libdir, "foreign_key_migrations/schema_statements")
0
- require File.join(libdir, "foreign_key_migrations/table_definition")
0
- require File.join(libdir, "foreign_key_migrations/foreign_key_definition")
0
+ ForeignKeyMigrations.require_all_libs_relative_to __FILE__
0
+
0
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Viget::ForeignKeyMigrations::SchemaStatements)
0
+ ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Viget::ForeignKeyMigrations::TableDefinition)
0
 
0
- ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Viget::ForeignKeyMigrations::SchemaStatements)
0
- ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Viget::ForeignKeyMigrations::TableDefinition)
0
-
0
- # Enable foreign key migration support for the following databases.
0
- adapter_names.each do |adapter_name|
0
- if module_name.constantize.const_defined?(adapter_name)
0
- adapter = "#{module_name}::#{adapter_name}".constantize
0
- adapter.send(:include, Viget::ForeignKeyMigrations::DatabaseSupport)
0
- end
0
+ # Enable foreign key migration support for the following databases.
0
+ adapter_names.each do |adapter_name|
0
+ if module_name.constantize.const_defined?(adapter_name)
0
+ adapter = "#{module_name}::#{adapter_name}".constantize
0
+ adapter.send(:include, Viget::ForeignKeyMigrations::DatabaseSupport)
0
+ end
0
+ end
0
   end
0
-end
0
\ No newline at end of file
0
+end # unless defined?
...
1
2
3
4
5
6
 
 
...
 
 
1
2
 
 
3
4
0
@@ -1,6 +1,4 @@
0
-require File.join(File.dirname(__FILE__), '../lib/foreign_key_migrations')
0
-require 'test/unit'
0
 require 'rubygems'
0
 require 'mysticize'
0
-
0
-
0
+require 'test/unit'
0
+require File.join(File.dirname(__FILE__), '..', 'lib', 'foreign_key_migrations')

Comments

    No one has commented yet.