dm-constraints 0.9.4
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/History.txt +1 -0
- data/LICENSE +20 -0
- data/Manifest.txt +20 -0
- data/README.txt +4 -0
- data/Rakefile +26 -0
- data/TODO +3 -0
- data/lib/dm-constraints/data_objects_adapter.rb +90 -0
- data/lib/dm-constraints/mysql_adapter.rb +28 -0
- data/lib/dm-constraints/postgres_adapter.rb +20 -0
- data/lib/dm-constraints/version.rb +5 -0
- data/lib/dm-constraints.rb +33 -0
- data/spec/integration/constraints_spec.rb +68 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +27 -0
- data/tasks/ci.rb +68 -0
- data/tasks/dm.rb +63 -0
- data/tasks/doc.rb +20 -0
- data/tasks/gemspec.rb +23 -0
- data/tasks/hoe.rb +46 -0
- data/tasks/install.rb +20 -0
- metadata +85 -0
data/History.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Dirkjan Bussink
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
History.txt
|
2
|
+
LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
TODO
|
7
|
+
lib/dm-constraints.rb
|
8
|
+
lib/dm-constraints/data_objects_adapter.rb
|
9
|
+
lib/dm-constraints/mysql_adapter.rb
|
10
|
+
lib/dm-constraints/postgres_adapter.rb
|
11
|
+
lib/dm-constraints/version.rb
|
12
|
+
spec/integration/constraints_spec.rb
|
13
|
+
spec/spec.opts
|
14
|
+
spec/spec_helper.rb
|
15
|
+
tasks/ci.rb
|
16
|
+
tasks/dm.rb
|
17
|
+
tasks/doc.rb
|
18
|
+
tasks/gemspec.rb
|
19
|
+
tasks/hoe.rb
|
20
|
+
tasks/install.rb
|
data/README.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
ROOT = Pathname(__FILE__).dirname.expand_path
|
7
|
+
require ROOT + 'lib/dm-constraints/version'
|
8
|
+
|
9
|
+
AUTHOR = "Dirkjan Bussink"
|
10
|
+
EMAIL = "d.bussink@gmail.com"
|
11
|
+
GEM_NAME = "dm-constraints"
|
12
|
+
GEM_VERSION = DataMapper::Constraints::VERSION
|
13
|
+
GEM_DEPENDENCIES = [["dm-core", GEM_VERSION]]
|
14
|
+
GEM_CLEAN = ["log", "pkg", "coverage"]
|
15
|
+
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO ] }
|
16
|
+
|
17
|
+
PROJECT_NAME = "datamapper"
|
18
|
+
PROJECT_URL = "http://github.com/sam/dm-more/tree/master/dm-constraints"
|
19
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY = "DataMapper plugin for performing validations on data models"
|
20
|
+
|
21
|
+
require ROOT + 'tasks/hoe'
|
22
|
+
require ROOT + 'tasks/gemspec'
|
23
|
+
require ROOT + 'tasks/install'
|
24
|
+
require ROOT + 'tasks/dm'
|
25
|
+
require ROOT + 'tasks/doc'
|
26
|
+
require ROOT + 'tasks/ci'
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Constraints
|
3
|
+
module DataObjectsAdapter
|
4
|
+
module SQL
|
5
|
+
def create_constraints_statements(repository_name, model)
|
6
|
+
model.many_to_one_relationships.map do |relationship|
|
7
|
+
table_name = model.storage_name(repository_name)
|
8
|
+
constraint_name = constraint_name(table_name, relationship.name)
|
9
|
+
next if constraint_exists?(table_name, constraint_name)
|
10
|
+
|
11
|
+
keys = relationship.child_key.map { |key| property_to_column_name(model.repository(repository_name), key, false) }
|
12
|
+
parent = relationship.parent_model
|
13
|
+
foreign_table = parent.storage_name(repository_name)
|
14
|
+
foreign_keys = parent.key.map { |key| property_to_column_name(parent.repository(repository_name), key, false) }
|
15
|
+
|
16
|
+
create_constraints_statement(table_name, constraint_name, keys, foreign_table, foreign_keys)
|
17
|
+
end.compact
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy_constraints_statements(repository_name, model)
|
21
|
+
model.many_to_one_relationships.map do |relationship|
|
22
|
+
table_name = model.storage_name(repository_name)
|
23
|
+
constraint_name = constraint_name(table_name, relationship.name)
|
24
|
+
next unless constraint_exists?(table_name, constraint_name)
|
25
|
+
|
26
|
+
destroy_constraints_statement(table_name, constraint_name)
|
27
|
+
end.compact
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def create_constraints_statement(table_name, constraint_name, keys, foreign_table, foreign_keys)
|
33
|
+
<<-EOS.compress_lines
|
34
|
+
ALTER TABLE #{quote_table_name(table_name)}
|
35
|
+
ADD CONSTRAINT #{quote_constraint_name(constraint_name)}
|
36
|
+
FOREIGN KEY (#{keys * ', '})
|
37
|
+
REFERENCES #{quote_table_name(foreign_table)} (#{foreign_keys * ', '})
|
38
|
+
ON DELETE NO ACTION
|
39
|
+
ON UPDATE NO ACTION
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy_constraints_statement(table_name, constraint_name)
|
44
|
+
<<-EOS.compress_lines
|
45
|
+
ALTER TABLE #{quote_table_name(table_name)}
|
46
|
+
DROP CONSTRAINT #{quote_constraint_name(constraint_name)}
|
47
|
+
EOS
|
48
|
+
end
|
49
|
+
|
50
|
+
def constraint_name(table_name, relationship_name)
|
51
|
+
"#{table_name}_#{relationship_name}_fk"
|
52
|
+
end
|
53
|
+
|
54
|
+
def quote_constraint_name(foreign_key)
|
55
|
+
quote_table_name(foreign_key)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module Migration
|
60
|
+
def self.included(migrator)
|
61
|
+
migrator.extend(ClassMethods)
|
62
|
+
migrator.before_class_method :auto_migrate_down, :auto_migrate_constraints_down
|
63
|
+
migrator.after_class_method :auto_migrate_up, :auto_migrate_constraints_up
|
64
|
+
end
|
65
|
+
|
66
|
+
module ClassMethods
|
67
|
+
def auto_migrate_constraints_down(repository_name, *descendants)
|
68
|
+
descendants = DataMapper::Resource.descendants.to_a if descendants.empty?
|
69
|
+
descendants.each do |model|
|
70
|
+
if model.storage_exists?(repository_name)
|
71
|
+
adapter = model.repository(repository_name).adapter
|
72
|
+
statements = adapter.destroy_constraints_statements(repository_name, model)
|
73
|
+
statements.each {|stmt| adapter.execute(stmt) }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def auto_migrate_constraints_up(retval, repository_name, *descendants)
|
79
|
+
descendants = DataMapper::Resource.descendants.to_a if descendants.empty?
|
80
|
+
descendants.each do |model|
|
81
|
+
adapter = model.repository(repository_name).adapter
|
82
|
+
statements = adapter.create_constraints_statements(repository_name, model)
|
83
|
+
statements.each {|stmt| adapter.execute(stmt) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Constraints
|
3
|
+
module MysqlAdapter
|
4
|
+
module SQL
|
5
|
+
private
|
6
|
+
|
7
|
+
def destroy_constraints_statement(table_name, constraint_name)
|
8
|
+
<<-EOS.compress_lines
|
9
|
+
ALTER TABLE #{quote_table_name(table_name)}
|
10
|
+
DROP FOREIGN KEY #{quote_constraint_name(constraint_name)}
|
11
|
+
EOS
|
12
|
+
end
|
13
|
+
|
14
|
+
def constraint_exists?(storage_name, constraint_name)
|
15
|
+
statement = <<-EOS.compress_lines
|
16
|
+
SELECT COUNT(*)
|
17
|
+
FROM `information_schema`.`table_constraints`
|
18
|
+
WHERE `constraint_type` = 'FOREIGN KEY'
|
19
|
+
AND `table_schema` = ?
|
20
|
+
AND `table_name` = ?
|
21
|
+
AND `constraint_name` = ?
|
22
|
+
EOS
|
23
|
+
query(statement, db_name, storage_name, constraint_name).first > 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Constraints
|
3
|
+
module PostgresAdapter
|
4
|
+
module SQL
|
5
|
+
private
|
6
|
+
|
7
|
+
def constraint_exists?(storage_name, constraint_name)
|
8
|
+
statement = <<-EOS.compress_lines
|
9
|
+
SELECT COUNT(*)
|
10
|
+
FROM "information_schema"."table_constraints"
|
11
|
+
WHERE "table_schema" = current_schema()
|
12
|
+
AND "table_name" = ?
|
13
|
+
AND "constraint_name" = ?
|
14
|
+
EOS
|
15
|
+
query(statement, storage_name, constraint_name).first > 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Needed to import datamapper and other gems
|
2
|
+
require 'rubygems'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# Add all external dependencies for the plugin here
|
6
|
+
gem 'dm-core', '=0.9.4'
|
7
|
+
require 'dm-core'
|
8
|
+
|
9
|
+
# Require plugin-files
|
10
|
+
require Pathname(__FILE__).dirname.expand_path / 'dm-constraints' / 'data_objects_adapter'
|
11
|
+
require Pathname(__FILE__).dirname.expand_path / 'dm-constraints' / 'postgres_adapter'
|
12
|
+
require Pathname(__FILE__).dirname.expand_path / 'dm-constraints' / 'mysql_adapter'
|
13
|
+
|
14
|
+
module DataMapper
|
15
|
+
class AutoMigrator
|
16
|
+
include Extlib::Hook
|
17
|
+
include DataMapper::Constraints::DataObjectsAdapter::Migration
|
18
|
+
end
|
19
|
+
|
20
|
+
module Adapters
|
21
|
+
class DataObjectsAdapter
|
22
|
+
include DataMapper::Constraints::DataObjectsAdapter::SQL
|
23
|
+
end
|
24
|
+
|
25
|
+
class MysqlAdapter
|
26
|
+
include DataMapper::Constraints::MysqlAdapter::SQL
|
27
|
+
end
|
28
|
+
|
29
|
+
class PostgresAdapter
|
30
|
+
include DataMapper::Constraints::PostgresAdapter::SQL
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
|
+
|
4
|
+
[HAS_MYSQL, HAS_POSTGRES].each do |adapter|
|
5
|
+
|
6
|
+
describe 'DataMapper::Constraints' do
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[adapter]
|
10
|
+
|
11
|
+
class Stable
|
12
|
+
include DataMapper::Resource
|
13
|
+
|
14
|
+
property :id, Serial
|
15
|
+
property :location, String
|
16
|
+
property :size, Integer
|
17
|
+
end
|
18
|
+
|
19
|
+
class Farmer
|
20
|
+
include DataMapper::Resource
|
21
|
+
|
22
|
+
property :first_name, String, :key => true
|
23
|
+
property :last_name, String, :key => true
|
24
|
+
end
|
25
|
+
|
26
|
+
class Cow
|
27
|
+
include DataMapper::Resource
|
28
|
+
include DataMapper::Constraints
|
29
|
+
|
30
|
+
property :id, Serial
|
31
|
+
property :name, String
|
32
|
+
property :breed, String
|
33
|
+
belongs_to :stable
|
34
|
+
belongs_to :farmer
|
35
|
+
end
|
36
|
+
|
37
|
+
class Stable
|
38
|
+
has n, :cows
|
39
|
+
end
|
40
|
+
|
41
|
+
class Farmer
|
42
|
+
has n, :cows
|
43
|
+
end
|
44
|
+
|
45
|
+
DataMapper.auto_migrate!
|
46
|
+
end
|
47
|
+
|
48
|
+
it "is included when DataMapper::Searchable is loaded" do
|
49
|
+
Cow.new.should be_kind_of(DataMapper::Constraints)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to create related objects with a foreign key constraint" do
|
53
|
+
@s = Stable.create(:location => "Hometown")
|
54
|
+
@c1 = Cow.create(:name => "Bea", :stable => @s)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to create related objects with a composite foreign key constraint" do
|
58
|
+
@f = Farmer.create(:first_name => "John", :last_name => "Doe")
|
59
|
+
@c1 = Cow.create(:name => "Bea", :farmer => @f)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not be able to create related objects with a failing foreign key constraint" do
|
63
|
+
s = Stable.first(:order => [:id.desc])
|
64
|
+
lambda { @c1 = Cow.create(:name => "Bea", :stable_id => s.id + 1) }.should raise_error
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec', '>=1.1.3'
|
3
|
+
require 'spec'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
gem 'dm-core', '>=0.9.4'
|
7
|
+
require 'dm-core'
|
8
|
+
|
9
|
+
def load_driver(name, default_uri)
|
10
|
+
|
11
|
+
lib = "do_#{name}"
|
12
|
+
begin
|
13
|
+
gem lib, '>=0.9.4'
|
14
|
+
require lib
|
15
|
+
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
16
|
+
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
17
|
+
name
|
18
|
+
rescue Gem::LoadError => e
|
19
|
+
warn "Could not load #{lib}: #{e}"
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test')
|
25
|
+
HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test')
|
26
|
+
|
27
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/dm-constraints'
|
data/tasks/ci.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
task 'ci:doc' => :doc
|
2
|
+
|
3
|
+
namespace :ci do
|
4
|
+
|
5
|
+
task :prepare do
|
6
|
+
rm_rf ROOT + "ci"
|
7
|
+
mkdir_p ROOT + "ci"
|
8
|
+
mkdir_p ROOT + "ci/doc"
|
9
|
+
mkdir_p ROOT + "ci/cyclomatic"
|
10
|
+
mkdir_p ROOT + "ci/token"
|
11
|
+
end
|
12
|
+
|
13
|
+
Spec::Rake::SpecTask.new("spec:unit" => :prepare) do |t|
|
14
|
+
t.spec_opts = ["--format", "specdoc", "--format", "html:#{ROOT}/ci/unit_rspec_report.html", "--diff"]
|
15
|
+
t.spec_files = Pathname.glob(ROOT + "spec/unit/**/*_spec.rb")
|
16
|
+
unless ENV['NO_RCOV']
|
17
|
+
t.rcov = true
|
18
|
+
t.rcov_opts << '--exclude' << "spec,gems"
|
19
|
+
t.rcov_opts << '--text-summary'
|
20
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
21
|
+
t.rcov_opts << '--only-uncovered'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new("spec:integration" => :prepare) do |t|
|
26
|
+
t.spec_opts = ["--format", "specdoc", "--format", "html:#{ROOT}/ci/integration_rspec_report.html", "--diff"]
|
27
|
+
t.spec_files = Pathname.glob(ROOT + "spec/integration/**/*_spec.rb")
|
28
|
+
unless ENV['NO_RCOV']
|
29
|
+
t.rcov = true
|
30
|
+
t.rcov_opts << '--exclude' << "spec,gems"
|
31
|
+
t.rcov_opts << '--text-summary'
|
32
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
33
|
+
t.rcov_opts << '--only-uncovered'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
task :spec do
|
38
|
+
Rake::Task["ci:spec:unit"].invoke
|
39
|
+
mv ROOT + "coverage", ROOT + "ci/unit_coverage"
|
40
|
+
|
41
|
+
Rake::Task["ci:spec:integration"].invoke
|
42
|
+
mv ROOT + "coverage", ROOT + "ci/integration_coverage"
|
43
|
+
end
|
44
|
+
|
45
|
+
task :saikuro => :prepare do
|
46
|
+
system "saikuro -c -i lib -y 0 -w 10 -e 15 -o ci/cyclomatic"
|
47
|
+
mv 'ci/cyclomatic/index_cyclo.html', 'ci/cyclomatic/index.html'
|
48
|
+
|
49
|
+
system "saikuro -t -i lib -y 0 -w 20 -e 30 -o ci/token"
|
50
|
+
mv 'ci/token/index_token.html', 'ci/token/index.html'
|
51
|
+
end
|
52
|
+
|
53
|
+
task :publish do
|
54
|
+
out = ENV['CC_BUILD_ARTIFACTS'] || "out"
|
55
|
+
mkdir_p out unless File.directory? out
|
56
|
+
|
57
|
+
mv "ci/unit_rspec_report.html", "#{out}/unit_rspec_report.html"
|
58
|
+
mv "ci/unit_coverage", "#{out}/unit_coverage"
|
59
|
+
mv "ci/integration_rspec_report.html", "#{out}/integration_rspec_report.html"
|
60
|
+
mv "ci/integration_coverage", "#{out}/integration_coverage"
|
61
|
+
mv "ci/doc", "#{out}/doc"
|
62
|
+
mv "ci/cyclomatic", "#{out}/cyclomatic_complexity"
|
63
|
+
mv "ci/token", "#{out}/token_complexity"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#task :ci => %w[ ci:spec ci:doc ci:saikuro install ci:publish ] # yard-related tasks do not work yet
|
68
|
+
task :ci => %w[ ci:spec ci:saikuro install ]
|
data/tasks/dm.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
task :default => 'dm:spec'
|
2
|
+
task :spec => 'dm:spec'
|
3
|
+
task :rcov => 'dm:rcov'
|
4
|
+
|
5
|
+
namespace :spec do
|
6
|
+
task :unit => 'dm:spec:unit'
|
7
|
+
task :integration => 'dm:spec:integration'
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :rcov do
|
11
|
+
task :unit => 'dm:rcov:unit'
|
12
|
+
task :integration => 'dm:rcov:integration'
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :dm do
|
16
|
+
def run_spec(name, files, rcov)
|
17
|
+
Spec::Rake::SpecTask.new(name) do |t|
|
18
|
+
t.spec_opts << '--colour' << '--loadby' << 'random'
|
19
|
+
t.spec_files = Pathname.glob(ENV['FILES'] || files)
|
20
|
+
t.rcov = rcov
|
21
|
+
t.rcov_opts << '--exclude' << 'spec,environment.rb'
|
22
|
+
t.rcov_opts << '--text-summary'
|
23
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
24
|
+
t.rcov_opts << '--only-uncovered'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
unit_specs = ROOT + 'spec/unit/**/*_spec.rb'
|
29
|
+
integration_specs = ROOT + 'spec/integration/**/*_spec.rb'
|
30
|
+
all_specs = ROOT + 'spec/**/*_spec.rb'
|
31
|
+
|
32
|
+
desc "Run all specifications"
|
33
|
+
run_spec('spec', all_specs, false)
|
34
|
+
|
35
|
+
desc "Run all specifications with rcov"
|
36
|
+
run_spec('rcov', all_specs, true)
|
37
|
+
|
38
|
+
namespace :spec do
|
39
|
+
desc "Run unit specifications"
|
40
|
+
run_spec('unit', unit_specs, false)
|
41
|
+
|
42
|
+
desc "Run integration specifications"
|
43
|
+
run_spec('integration', integration_specs, false)
|
44
|
+
end
|
45
|
+
|
46
|
+
namespace :rcov do
|
47
|
+
desc "Run unit specifications with rcov"
|
48
|
+
run_spec('unit', unit_specs, true)
|
49
|
+
|
50
|
+
desc "Run integration specifications with rcov"
|
51
|
+
run_spec('integration', integration_specs, true)
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Run all comparisons with ActiveRecord"
|
55
|
+
task :perf do
|
56
|
+
sh ROOT + 'script/performance.rb'
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Profile DataMapper"
|
60
|
+
task :profile do
|
61
|
+
sh ROOT + 'script/profile.rb'
|
62
|
+
end
|
63
|
+
end
|
data/tasks/doc.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# when yard's ready, it'll have to come back, but for now...
|
2
|
+
Rake::RDocTask.new("doc") do |t|
|
3
|
+
t.rdoc_dir = 'doc'
|
4
|
+
t.title = "DataMapper - Ruby Object Relational Mapper"
|
5
|
+
t.options = ['--line-numbers', '--inline-source', '--all']
|
6
|
+
t.rdoc_files.include("README.txt", "QUICKLINKS", "FAQ", "lib/**/**/*.rb")
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
gem 'yard', '>=0.2.1'
|
11
|
+
require 'yard'
|
12
|
+
|
13
|
+
YARD::Rake::YardocTask.new("yardoc") do |t|
|
14
|
+
t.options << '--protected'
|
15
|
+
# t.options << '-q'
|
16
|
+
# t.files << '...anyglobshere...'
|
17
|
+
end
|
18
|
+
rescue Exception
|
19
|
+
# yard not installed
|
20
|
+
end
|
data/tasks/gemspec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
desc "Generate gemspec"
|
2
|
+
task :gemspec do |x|
|
3
|
+
# Clean up extraneous files before checking manifest
|
4
|
+
%x[rake clean]
|
5
|
+
|
6
|
+
# Check the manifest before generating the gemspec
|
7
|
+
manifest = %x[rake check_manifest]
|
8
|
+
manifest.gsub!("(in /usr/local/projects/dm/dm-core)\n", "")
|
9
|
+
|
10
|
+
unless manifest.empty?
|
11
|
+
print "\n", "#"*68, "\n"
|
12
|
+
print <<-EOS
|
13
|
+
Manifest.txt is not up-to-date. Please review the changes below.
|
14
|
+
If the changes are correct, run 'rake check_manifest | patch'
|
15
|
+
and then run this command again.
|
16
|
+
EOS
|
17
|
+
print "#"*68, "\n\n"
|
18
|
+
puts manifest
|
19
|
+
else
|
20
|
+
%x[rake debug_gem > #{GEM_NAME}.gemspec]
|
21
|
+
puts "Successfully created gemspec for #{GEM_NAME}!"
|
22
|
+
end
|
23
|
+
end
|
data/tasks/hoe.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
|
3
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
4
|
+
@config = nil
|
5
|
+
RUBYFORGE_USERNAME = "unknown"
|
6
|
+
def rubyforge_username
|
7
|
+
unless @config
|
8
|
+
begin
|
9
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
10
|
+
rescue
|
11
|
+
puts <<-EOS
|
12
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
13
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
14
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
15
|
+
EOS
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Remove hoe dependency
|
23
|
+
class Hoe
|
24
|
+
def extra_dev_deps
|
25
|
+
@extra_dev_deps.reject! { |dep| dep[0] == "hoe" }
|
26
|
+
@extra_dev_deps
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
hoe = Hoe.new(GEM_NAME, GEM_VERSION) do |p|
|
31
|
+
|
32
|
+
p.developer(AUTHOR, EMAIL)
|
33
|
+
|
34
|
+
p.description = PROJECT_DESCRIPTION
|
35
|
+
p.summary = PROJECT_SUMMARY
|
36
|
+
p.url = PROJECT_URL
|
37
|
+
|
38
|
+
p.rubyforge_name = PROJECT_NAME if PROJECT_NAME
|
39
|
+
|
40
|
+
p.clean_globs |= ["{coverage,doc,log,tmp}", "**/*.{log,db}", "profile_results.*", "**/.DS_Store"]
|
41
|
+
|
42
|
+
GEM_DEPENDENCIES.each do |dep|
|
43
|
+
p.extra_deps << dep
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/tasks/install.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
WIN32 = (RUBY_PLATFORM =~ /win32|mingw|bccwin|cygwin/) rescue nil
|
2
|
+
SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
|
3
|
+
|
4
|
+
desc "Install #{GEM_NAME}"
|
5
|
+
if WIN32
|
6
|
+
task :install => :gem do
|
7
|
+
system %{gem install --no-rdoc --no-ri -l pkg/#{GEM_NAME}-#{GEM_VERSION}.gem}
|
8
|
+
end
|
9
|
+
namespace :dev do
|
10
|
+
desc 'Install for development (for windows)'
|
11
|
+
task :winstall => :gem do
|
12
|
+
warn "You can now call 'rake install' instead of 'rake dev:winstall'."
|
13
|
+
system %{gem install --no-rdoc --no-ri -l pkg/#{GEM_NAME}-#{GEM_VERSION}.gem}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
task :install => :package do
|
18
|
+
sh %{#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION}.gem}
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-constraints
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dirkjan Bussink
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-21 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.4
|
24
|
+
version:
|
25
|
+
description: DataMapper plugin for performing validations on data models
|
26
|
+
email:
|
27
|
+
- d.bussink@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- LICENSE
|
39
|
+
- Manifest.txt
|
40
|
+
- README.txt
|
41
|
+
- Rakefile
|
42
|
+
- TODO
|
43
|
+
- lib/dm-constraints.rb
|
44
|
+
- lib/dm-constraints/data_objects_adapter.rb
|
45
|
+
- lib/dm-constraints/mysql_adapter.rb
|
46
|
+
- lib/dm-constraints/postgres_adapter.rb
|
47
|
+
- lib/dm-constraints/version.rb
|
48
|
+
- spec/integration/constraints_spec.rb
|
49
|
+
- spec/spec.opts
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
- tasks/ci.rb
|
52
|
+
- tasks/dm.rb
|
53
|
+
- tasks/doc.rb
|
54
|
+
- tasks/gemspec.rb
|
55
|
+
- tasks/hoe.rb
|
56
|
+
- tasks/install.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/sam/dm-more/tree/master/dm-constraints
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --main
|
62
|
+
- README.txt
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: datamapper
|
80
|
+
rubygems_version: 1.2.0
|
81
|
+
signing_key:
|
82
|
+
specification_version: 2
|
83
|
+
summary: DataMapper plugin for performing validations on data models
|
84
|
+
test_files: []
|
85
|
+
|