activerecord-amalgalite-adapter 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/LICENSE +13 -0
- data/README +51 -0
- data/gemspec.rb +52 -0
- data/lib/active_record/connection_adapters/amalgalite_adapter.rb +442 -0
- data/lib/activerecord-amalgalite-adapter.rb +5 -0
- data/tasks/announce.rake +39 -0
- data/tasks/config.rb +108 -0
- data/tasks/distribution.rake +38 -0
- data/tasks/documentation.rake +32 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/testunit.rake +19 -0
- data/tasks/utils.rb +78 -0
- data/test/activerecord_amalgalite_adapter_test.rb +19 -0
- data/test/config.rb +20 -0
- data/test/connection.rb +29 -0
- data/test/schema/amalgalite_specific_schema.rb +22 -0
- data/test/schema/schema.rb +473 -0
- data/test/schema/schema2.rb +6 -0
- data/test/test_helper.rb +3 -0
- metadata +109 -0
data/tasks/announce.rake
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'tasks/config'
|
2
|
+
#-------------------------------------------------------------------------------
|
3
|
+
# announcement methods
|
4
|
+
#-------------------------------------------------------------------------------
|
5
|
+
|
6
|
+
proj_config = Configuration.for('project')
|
7
|
+
namespace :announce do
|
8
|
+
desc "create email for ruby-talk"
|
9
|
+
task :email do
|
10
|
+
info = Utils.announcement
|
11
|
+
|
12
|
+
File.open("email.txt", "w") do |mail|
|
13
|
+
mail.puts "From: #{proj_config.author} <#{proj_config.email}>"
|
14
|
+
mail.puts "To: ruby-talk@ruby-lang.org"
|
15
|
+
mail.puts "Date: #{Time.now.rfc2822}"
|
16
|
+
mail.puts "Subject: [ANN] #{info[:subject]}"
|
17
|
+
mail.puts
|
18
|
+
mail.puts info[:title]
|
19
|
+
mail.puts
|
20
|
+
mail.puts " gem install #{ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.name}"
|
21
|
+
mail.puts
|
22
|
+
mail.puts info[:urls]
|
23
|
+
mail.puts
|
24
|
+
mail.puts info[:description]
|
25
|
+
mail.puts
|
26
|
+
mail.puts "{{ Release notes for Version #{ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION} }}"
|
27
|
+
mail.puts
|
28
|
+
mail.puts info[:release_notes]
|
29
|
+
mail.puts
|
30
|
+
end
|
31
|
+
puts "Created the following as email.txt:"
|
32
|
+
puts "-" * 72
|
33
|
+
puts File.read("email.txt")
|
34
|
+
puts "-" * 72
|
35
|
+
end
|
36
|
+
|
37
|
+
CLOBBER << "email.txt"
|
38
|
+
end
|
39
|
+
|
data/tasks/config.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'configuration'
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'tasks/utils'
|
5
|
+
require 'activerecord-amalgalite-adapter'
|
6
|
+
|
7
|
+
#-----------------------------------------------------------------------
|
8
|
+
# General project configuration
|
9
|
+
#-----------------------------------------------------------------------
|
10
|
+
Configuration.for('project') {
|
11
|
+
name "activerecord-amalgalite-adapter"
|
12
|
+
version ::ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION
|
13
|
+
author "Jeremy Hinegadner"
|
14
|
+
email "jeremy@copiousfreetime.org"
|
15
|
+
homepage "http://copiousfreetime.rubyforge.org/activerecord-amalgalite-adapter/"
|
16
|
+
description Utils.section_of("README", "description")
|
17
|
+
summary description.split(".").first
|
18
|
+
history "HISTORY"
|
19
|
+
license FileList["LICENSE"]
|
20
|
+
readme "README"
|
21
|
+
}
|
22
|
+
|
23
|
+
#-----------------------------------------------------------------------
|
24
|
+
# Packaging
|
25
|
+
#-----------------------------------------------------------------------
|
26
|
+
Configuration.for('packaging') {
|
27
|
+
# files in the project
|
28
|
+
proj_conf = Configuration.for('project')
|
29
|
+
files {
|
30
|
+
bin FileList["bin/*"]
|
31
|
+
ext FileList["ext/*.{c,h,rb}"]
|
32
|
+
lib FileList["lib/**/*.rb"]
|
33
|
+
test FileList["spec/**/*.rb", "test/**/*.rb"]
|
34
|
+
data FileList["data/**/*"]
|
35
|
+
tasks FileList["tasks/**/*.r{ake,b}"]
|
36
|
+
rdoc FileList[proj_conf.readme, proj_conf.history,
|
37
|
+
proj_conf.license] + lib
|
38
|
+
all bin + ext + lib + test + data + rdoc + tasks
|
39
|
+
}
|
40
|
+
|
41
|
+
# ways to package the results
|
42
|
+
formats {
|
43
|
+
tgz true
|
44
|
+
zip true
|
45
|
+
rubygem Configuration::Table.has_key?('rubygem')
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
#-----------------------------------------------------------------------
|
50
|
+
# Gem packaging
|
51
|
+
#-----------------------------------------------------------------------
|
52
|
+
Configuration.for("rubygem") {
|
53
|
+
spec "gemspec.rb"
|
54
|
+
Configuration.for('packaging').files.all << spec
|
55
|
+
}
|
56
|
+
|
57
|
+
#-----------------------------------------------------------------------
|
58
|
+
# Testing
|
59
|
+
# - change mode to 'testunit' to use unit testing
|
60
|
+
#-----------------------------------------------------------------------
|
61
|
+
Configuration.for('test') {
|
62
|
+
mode "testunit"
|
63
|
+
files Configuration.for("packaging").files.test
|
64
|
+
#options %w[ --format specdoc --color ]
|
65
|
+
#ruby_opts %w[ ]
|
66
|
+
}
|
67
|
+
|
68
|
+
#-----------------------------------------------------------------------
|
69
|
+
# Rcov
|
70
|
+
#-----------------------------------------------------------------------
|
71
|
+
Configuration.for('rcov') {
|
72
|
+
output_dir "coverage"
|
73
|
+
libs %w[ lib ]
|
74
|
+
rcov_opts %w[ --html ]
|
75
|
+
ruby_opts %w[ ]
|
76
|
+
test_files Configuration.for('packaging').files.test
|
77
|
+
}
|
78
|
+
|
79
|
+
#-----------------------------------------------------------------------
|
80
|
+
# Rdoc
|
81
|
+
#-----------------------------------------------------------------------
|
82
|
+
Configuration.for('rdoc') {
|
83
|
+
files Configuration.for('packaging').files.rdoc
|
84
|
+
main_page files.first
|
85
|
+
title Configuration.for('project').name
|
86
|
+
options %w[ --line-numbers --inline-source ]
|
87
|
+
output_dir "doc"
|
88
|
+
}
|
89
|
+
|
90
|
+
#-----------------------------------------------------------------------
|
91
|
+
# Extensions
|
92
|
+
#-----------------------------------------------------------------------
|
93
|
+
Configuration.for('extension') {
|
94
|
+
configs Configuration.for('packaging').files.ext.find_all { |x|
|
95
|
+
%w[ mkrf_conf.rb extconf.rb ].include?( File.basename(x) )
|
96
|
+
}
|
97
|
+
}
|
98
|
+
#-----------------------------------------------------------------------
|
99
|
+
# Rubyforge
|
100
|
+
#-----------------------------------------------------------------------
|
101
|
+
Configuration.for('rubyforge') {
|
102
|
+
project "copiousfreetime"
|
103
|
+
user "jjh"
|
104
|
+
host "rubyforge.org"
|
105
|
+
rdoc_location "#{user}@#{host}:/var/www/gforge-projects/#{project}/activerecord-amalgalite-adapter"
|
106
|
+
}
|
107
|
+
|
108
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'tasks/config'
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------------
|
4
|
+
# Distribution and Packaging
|
5
|
+
#-------------------------------------------------------------------------------
|
6
|
+
if pkg_config = Configuration.for_if_exist?("packaging") then
|
7
|
+
|
8
|
+
require 'gemspec'
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
require 'rake/contrib/sshpublisher'
|
11
|
+
|
12
|
+
namespace :dist do
|
13
|
+
|
14
|
+
Rake::GemPackageTask.new(ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC) do |pkg|
|
15
|
+
pkg.need_tar = pkg_config.formats.tgz
|
16
|
+
pkg.need_zip = pkg_config.formats.zip
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Install as a gem"
|
20
|
+
task :install => [:clobber, :package] do
|
21
|
+
sh "sudo gem install pkg/#{ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.full_name}.gem"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Uninstall gem"
|
25
|
+
task :uninstall do
|
26
|
+
sh "sudo gem uninstall -x #{ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "dump gemspec"
|
30
|
+
task :gemspec do
|
31
|
+
puts ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.to_ruby
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "reinstall gem"
|
35
|
+
task :reinstall => [:uninstall, :repackage, :install]
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'tasks/config'
|
2
|
+
|
3
|
+
#-----------------------------------------------------------------------
|
4
|
+
# Documentation
|
5
|
+
#-----------------------------------------------------------------------
|
6
|
+
|
7
|
+
if rdoc_config = Configuration.for_if_exist?('rdoc') then
|
8
|
+
|
9
|
+
namespace :doc do
|
10
|
+
|
11
|
+
require 'rdoc'
|
12
|
+
require 'rake/rdoctask'
|
13
|
+
|
14
|
+
# generating documentation locally
|
15
|
+
Rake::RDocTask.new do |rdoc|
|
16
|
+
rdoc.rdoc_dir = rdoc_config.output_dir
|
17
|
+
rdoc.options = rdoc_config.options
|
18
|
+
rdoc.rdoc_files = rdoc_config.files
|
19
|
+
rdoc.title = rdoc_config.title
|
20
|
+
rdoc.main = rdoc_config.main_page
|
21
|
+
end
|
22
|
+
|
23
|
+
if rubyforge_config = Configuration.for_if_exist?('rubyforge') then
|
24
|
+
desc "Deploy the RDoc documentation to #{rubyforge_config.rdoc_location}"
|
25
|
+
task :deploy => :rerdoc do
|
26
|
+
sh "rsync -zav --delete #{rdoc_config.output_dir}/ #{rubyforge_config.rdoc_location}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'tasks/config'
|
2
|
+
require 'activerecord'
|
3
|
+
|
4
|
+
#-----------------------------------------------------------------------
|
5
|
+
# Rubyforge additions to the task library
|
6
|
+
#-----------------------------------------------------------------------
|
7
|
+
if rf_conf = Configuration.for_if_exist?("rubyforge") then
|
8
|
+
|
9
|
+
abort("rubyforge gem not installed 'gem install rubyforge'") unless Utils.try_require('rubyforge')
|
10
|
+
|
11
|
+
proj_conf = Configuration.for('project')
|
12
|
+
|
13
|
+
namespace :dist do
|
14
|
+
desc "Release files to rubyforge"
|
15
|
+
task :rubyforge => [:clean, :package] do
|
16
|
+
|
17
|
+
rubyforge = RubyForge.new
|
18
|
+
|
19
|
+
config = {}
|
20
|
+
config["release_notes"] = proj_conf.description
|
21
|
+
config["release_changes"] = Utils.release_notes_from(proj_conf.history)[ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION]
|
22
|
+
config["Prefomatted"] = true
|
23
|
+
|
24
|
+
rubyforge.configure
|
25
|
+
|
26
|
+
# make sure this release doesn't already exist
|
27
|
+
releases = rubyforge.autoconfig['release_ids']
|
28
|
+
if releases.has_key?(ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.name) and
|
29
|
+
releases[ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.name][ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION] then
|
30
|
+
abort("Release #{ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION} already exists! Unable to release.")
|
31
|
+
end
|
32
|
+
|
33
|
+
puts "Uploading to rubyforge..."
|
34
|
+
files = FileList[File.join("pkg","#{ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.name}-#{ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION}*.*")].to_a
|
35
|
+
rubyforge.login
|
36
|
+
rubyforge.add_release(ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.rubyforge_project,
|
37
|
+
ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::GEM_SPEC.name,
|
38
|
+
ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION, *files)
|
39
|
+
puts "done."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :announce do
|
44
|
+
desc "Post news of #{proj_conf.name} to #{rf_conf.project} on rubyforge"
|
45
|
+
task :rubyforge do
|
46
|
+
info = Utils.announcement
|
47
|
+
rubyforge = RubyForge.new
|
48
|
+
rubyforge.configure
|
49
|
+
rubyforge.login
|
50
|
+
rubyforge.post_news(rf_conf.project, info[:subject], "#{info[:title]}\n\n#{info[:urls]}\n\n#{info[:release_notes]}")
|
51
|
+
puts "Posted to rubyforge"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/tasks/testunit.rake
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'tasks/config'
|
2
|
+
#-------------------------------------------------------------------------------
|
3
|
+
# configuration for running unit tests. This shows up as the test:default task
|
4
|
+
#-------------------------------------------------------------------------------
|
5
|
+
|
6
|
+
if test_config = Configuration.for_if_exist?('test') then
|
7
|
+
if test_config.mode == "testunit" then
|
8
|
+
namespace :test do
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
Rake::TestTask.new do |t|
|
14
|
+
t.test_files = FileList["test/*_test.rb"]
|
15
|
+
t.verbose = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/tasks/utils.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#-------------------------------------------------------------------------------
|
2
|
+
# Additions to the Configuration class that are useful
|
3
|
+
#-------------------------------------------------------------------------------
|
4
|
+
class Configuration
|
5
|
+
class << self
|
6
|
+
def exist?( name )
|
7
|
+
Configuration::Table.has_key?( name )
|
8
|
+
end
|
9
|
+
|
10
|
+
def for_if_exist?( name )
|
11
|
+
if self.exist?( name ) then
|
12
|
+
self.for( name )
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#-------------------------------------------------------------------------------
|
19
|
+
# some useful utilitiy methods for the tasks
|
20
|
+
#-------------------------------------------------------------------------------
|
21
|
+
module Utils
|
22
|
+
class << self
|
23
|
+
|
24
|
+
# Try to load the given _library_ using the built-in require, but do not
|
25
|
+
# raise a LoadError if unsuccessful. Returns +true+ if the _library_ was
|
26
|
+
# successfully loaded; returns +false+ otherwise.
|
27
|
+
#
|
28
|
+
def try_require( lib )
|
29
|
+
require lib
|
30
|
+
true
|
31
|
+
rescue LoadError
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
# partition an rdoc file into sections, and return the text of the section
|
36
|
+
# given.
|
37
|
+
def section_of(file, section_name)
|
38
|
+
File.read(file).split(/^(?==)/).each do |section|
|
39
|
+
lines = section.split("\n")
|
40
|
+
return lines[1..-1].join("\n").strip if lines.first =~ /#{section_name}/i
|
41
|
+
end
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get an array of all the changes in the application for a particular
|
46
|
+
# release. This is done by looking in the history file and grabbing the
|
47
|
+
# information for the most recent release. The history file is assumed to
|
48
|
+
# be in RDoc format and version release are 2nd tier sections separated by
|
49
|
+
# '== Version X.Y.Z'
|
50
|
+
#
|
51
|
+
# returns:: A hash of notes keyed by version number
|
52
|
+
#
|
53
|
+
def release_notes_from(history_file)
|
54
|
+
releases = {}
|
55
|
+
File.read(history_file).split(/^(?==)/).each do |section|
|
56
|
+
lines = section.split("\n")
|
57
|
+
md = %r{Version ((\w+\.)+\w+)}.match(lines.first)
|
58
|
+
next unless md
|
59
|
+
releases[md[1]] = lines[1..-1].join("\n").strip
|
60
|
+
end
|
61
|
+
return releases
|
62
|
+
end
|
63
|
+
|
64
|
+
# return a hash of useful information for the latest release
|
65
|
+
# urls, subject, title, description and latest release notes
|
66
|
+
#
|
67
|
+
def announcement
|
68
|
+
cfg = Configuration.for("project")
|
69
|
+
{
|
70
|
+
:subject => "#{cfg.name} #{::ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION} Released",
|
71
|
+
:title => "#{cfg.name} version #{::ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION} has been released.",
|
72
|
+
:urls => "#{cfg.homepage}",
|
73
|
+
:description => "#{cfg.description.rstrip}",
|
74
|
+
:release_notes => Utils.release_notes_from(cfg.history)[::ActiveRecord::ConnectionAdapters::AmalgaliteAdapter::VERSION].rstrip
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end # << self
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),"test_helper.rb"))
|
2
|
+
|
3
|
+
|
4
|
+
LOCAL_TEST_ROOT = File.dirname( __FILE__ )
|
5
|
+
$: << LOCAL_TEST_ROOT
|
6
|
+
require 'config'
|
7
|
+
|
8
|
+
require 'activerecord'
|
9
|
+
require 'rubygems'
|
10
|
+
require 'activesupport'
|
11
|
+
require 'activerecord-amalgalite-adapter'
|
12
|
+
|
13
|
+
FileUtils.rm_rf Dir.glob( "#{LOCAL_TEST_ROOT}/*.sqlite3" )
|
14
|
+
tests = Dir.glob("#{TEST_ROOT}/cases/*_test.rb").sort
|
15
|
+
puts "There are #{tests.size} test files in #{TEST_ROOT}/cases/"
|
16
|
+
|
17
|
+
tests.each { |f| puts f ; load f }
|
18
|
+
|
19
|
+
|
data/test/config.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
# load up the existing test cases from activerecord
|
3
|
+
# require 'rubygems'
|
4
|
+
#source_index = Gem::SourceIndex.from_gems_in( *Gem::SourceIndex.installed_spec_directories )
|
5
|
+
#ar_spec_list = source_index.find_name( 'activerecord' )
|
6
|
+
#ar_spec = ar_spec_list.sort_by { |x| x.version }.last
|
7
|
+
#ar_dir = ar_spec.full_gem_path
|
8
|
+
#AR_TEST_ROOT = File.join( ar_dir, "test" )
|
9
|
+
AR_ROOT = File.expand_path( "~/repos/git/rails/activerecord" )
|
10
|
+
#AR_ROOT = File.expand_path( "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2" )
|
11
|
+
|
12
|
+
TEST_ROOT = AR_ROOT + "/test"
|
13
|
+
ASSETS_ROOT = TEST_ROOT + "/assets"
|
14
|
+
FIXTURES_ROOT = TEST_ROOT + "/fixtures"
|
15
|
+
MIGRATIONS_ROOT = TEST_ROOT + "/migrations"
|
16
|
+
SCHEMA_ROOT = LOCAL_TEST_ROOT + "/schema"
|
17
|
+
|
18
|
+
$: << TEST_ROOT
|
19
|
+
$: << File.join( AR_ROOT, "lib" )
|
20
|
+
|
data/test/connection.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
print "Using native Amalgalite\n"
|
2
|
+
require_dependency 'models/course'
|
3
|
+
require 'logger'
|
4
|
+
FileUtils.rm_f "debug.log"
|
5
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
+
|
7
|
+
class AmalgaliteError< StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
BASE_DIR = FIXTURES_ROOT
|
11
|
+
|
12
|
+
this_dir = File.dirname( __FILE__ )
|
13
|
+
amalgalite_test_db = File.expand_path( File.join( this_dir, "fixture_database.sqlite3" ) )
|
14
|
+
amalgalite_test_db2 = File.expand_path( File.join( this_dir, "fixture_database_2.sqlite3") )
|
15
|
+
|
16
|
+
def make_connection(clazz, db_file)
|
17
|
+
ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'amalgalite', :database => db_file } }
|
18
|
+
unless File.exist?(db_file)
|
19
|
+
puts "Amalgalite database not found at #{db_file}. Rebuilding it."
|
20
|
+
sqlite_command = %Q{sqlite3 "#{db_file}" "create table a (a integer); drop table a;"}
|
21
|
+
puts "Executing '#{sqlite_command}'"
|
22
|
+
raise AmalgaliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
|
23
|
+
end
|
24
|
+
clazz.establish_connection(clazz.name)
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "File.exist : #{File.exist?( amalgalite_test_db )}"
|
28
|
+
make_connection(ActiveRecord::Base, amalgalite_test_db)
|
29
|
+
make_connection(Course, amalgalite_test_db2)
|