mack-data_mapper 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,10 +26,10 @@ module Mack
26
26
  end
27
27
  end
28
28
  app_errors.flatten!
29
- File.join(Mack::Configuration.views_directory, "application", "_error_messages.html.erb")
29
+ File.join(MACK_VIEWS, "application", "_error_messages.html.erb")
30
30
  unless app_errors.empty?
31
31
  if view_partial.nil?
32
- if File.exist?(File.join(Mack::Configuration.views_directory, "application", "_error_messages.html.erb"))
32
+ if File.exist?(File.join(MACK_VIEWS, "application", "_error_messages.html.erb"))
33
33
  render :partial => "application/error_messages", :locals => {:errors => app_errors}
34
34
  else
35
35
  render :text => DEFAULT_PARTIAL, :locals => {:errors => app_errors}
@@ -9,33 +9,24 @@ end
9
9
  gem("datamapper", "0.3.2")
10
10
  require 'data_mapper'
11
11
 
12
- module Mack
13
- module Configuration
14
-
15
- def self.load_database_configurations(env = Mack::Configuration.env)
16
- dbs = Mack::Configuration.database_configurations
17
- unless dbs.nil?
18
- settings = dbs[env]
19
- settings.symbolize_keys!
20
- if settings[:default]
21
- settings.each do |k,v|
22
- DataMapper::Database.setup(k, v.symbolize_keys)
23
- end
24
- else
25
- DataMapper::Database.setup(settings)
26
- end
27
- end
28
- end # load_database_configurations
29
-
30
- end # Configuration
31
- end # Mack
32
-
33
-
34
- Mack::Configuration.load_database_configurations
12
+ dbs = YAML::load(Erubis::Eruby.new(IO.read(File.join(MACK_CONFIG, "database.yml"))).result)
13
+
14
+ unless dbs.nil?
15
+ settings = dbs[MACK_ENV]
16
+ settings.symbolize_keys!
17
+ if settings[:default]
18
+ settings.each do |k,v|
19
+ DataMapper::Database.setup(k, v.symbolize_keys)
20
+ end
21
+ else
22
+ DataMapper::Database.setup(settings)
23
+ end
24
+ end
35
25
 
36
26
  class SchemaInfo # :nodoc:
37
27
  include DataMapper::Persistence
38
28
 
29
+ set_table_name "schema_info"
39
30
  property :version, :integer, :default => 0
40
31
  end
41
32
 
@@ -20,7 +20,7 @@ class ScaffoldGenerator < Genosaurus
20
20
 
21
21
  def update_routes_file
22
22
  # update routes.rb
23
- routes = File.join(Mack::Configuration.config_directory, "routes.rb")
23
+ routes = File.join(MACK_CONFIG, "routes.rb")
24
24
  rf = File.open(routes).read
25
25
  unless rf.match(".resource :#{@name_plural}")
26
26
  puts "Updating routes.rb"
@@ -1,4 +1,3 @@
1
- require 'rake'
2
1
  namespace :db do
3
2
 
4
3
  desc "Migrate the database through scripts in db/migrations"
@@ -55,12 +54,8 @@ namespace :db do
55
54
  task :create => "mack:environment" do
56
55
  require 'data_mapper/migration'
57
56
  unless SchemaInfo.table.exists?
58
- class SchemaInfo
59
- include DataMapper::Persistence
60
- property :version, :integer
61
- end
62
- SchemaInfo.auto_migrate!
63
- SchemaInfo.create(:version => 0, :id => 1)
57
+ SchemaInfo.table.create!
58
+ SchemaInfo.create(:version => 0)
64
59
  end
65
60
  @schema_info = SchemaInfo.first
66
61
  end # create
@@ -69,7 +64,7 @@ namespace :db do
69
64
 
70
65
 
71
66
  def migration_files
72
- Dir.glob(File.join(Mack::Configuration.root, "db", "migrations", "*.rb"))
67
+ Dir.glob(File.join(MACK_ROOT, "db", "migrations", "*.rb"))
73
68
  end
74
69
 
75
70
  def migration_number(migration)
@@ -1,3 +1,3 @@
1
1
  test:
2
2
  adapter: sqlite3
3
- database: <%= File.join(Mack::Configuration.root, "mack-data_mapper_test.db") %>
3
+ database: <%= File.join(MACK_ROOT, "mack-data_mapper_test.db") %>
@@ -4,7 +4,7 @@ class ScaffoldGeneratorTest < Test::Unit::TestCase
4
4
 
5
5
  def test_generate_data_mapper
6
6
  sg = ScaffoldGenerator.run("name" => "zoo")
7
- File.open(File.join(Mack::Configuration.config_directory, "routes.rb")) do |f|
7
+ File.open(File.join(MACK_CONFIG, "routes.rb")) do |f|
8
8
  assert_match "r.resource :zoos # Added by rake generate:scaffold name=zoo", f.read
9
9
  end
10
10
 
@@ -24,7 +24,7 @@ class ScaffoldGeneratorTest < Test::Unit::TestCase
24
24
 
25
25
  def test_generate_data_mapper_with_columns
26
26
  sg = ScaffoldGenerator.run("name" => "zoo", "cols" => "name:string,description:text,created_at:datetime,updated_at:datetime")
27
- File.open(File.join(Mack::Configuration.config_directory, "routes.rb")) do |f|
27
+ File.open(File.join(MACK_CONFIG, "routes.rb")) do |f|
28
28
  assert_match "r.resource :zoos # Added by rake generate:scaffold name=zoo", f.read
29
29
  end
30
30
  assert File.exists?(views_directory)
@@ -43,15 +43,15 @@ class ScaffoldGeneratorTest < Test::Unit::TestCase
43
43
  end
44
44
 
45
45
  def views_directory
46
- File.join(Mack::Configuration.views_directory, "zoos")
46
+ File.join(MACK_VIEWS, "zoos")
47
47
  end
48
48
 
49
49
  def model_file
50
- File.join(Mack::Configuration.app_directory, "models", "zoo.rb")
50
+ File.join(MACK_APP, "models", "zoo.rb")
51
51
  end
52
52
 
53
53
  def controller_file
54
- File.join(Mack::Configuration.app_directory, "controllers", "zoos_controller.rb")
54
+ File.join(MACK_APP, "controllers", "zoos_controller.rb")
55
55
  end
56
56
 
57
57
  def migration_file
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
- class DbMigrationTasksTest < Test::Unit::TestCase
3
+ class DbTasksTest < Test::Unit::TestCase
4
4
 
5
- $current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "db_migration_tasks.rake")
5
+ $current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "db_tasks.rake")
6
6
 
7
7
  def test_db_rollback
8
8
  test_db_migrate
@@ -1,30 +1,18 @@
1
1
  require "test/unit"
2
2
  require File.join(File.dirname(__FILE__), "..", "..", "test_helpers")
3
3
 
4
- module Mack
5
- module Configuration
6
- def self.method_missing(sym, *args)
7
- ev = "_mack_#{sym}".downcase
8
- return ENV[ev]
9
- end
10
-
11
- def self.set(name, value)
12
- ENV["_mack_#{name.to_s.downcase}"] = value
13
- end
14
- end
15
- end
16
-
17
4
  $genosaurus_output_directory = File.join(File.dirname(__FILE__), "..", "tmp")
18
5
 
19
- ENV["_mack_config_directory"] = File.dirname(__FILE__)
20
- ENV["_mack_root"] = $genosaurus_output_directory
21
- ENV["_mack_app_directory"] = File.join($genosaurus_output_directory, "app")
22
- ENV["_mack_env"] = "test"
23
- ENV["_mack_views_directory"] = File.join(ENV["_mack_app_directory"], "views")
6
+ Object::MACK_CONFIG = File.dirname(__FILE__) unless Object.const_defined?("MACK_CONFIG")
7
+ Object::MACK_ROOT = $genosaurus_output_directory unless Object.const_defined?("MACK_ROOT")
8
+ Object::MACK_APP = File.join($genosaurus_output_directory, "app") unless Object.const_defined?("MACK_APP")
9
+ Object::MACK_ENV = "test" unless Object.const_defined?("MACK_ENV")
10
+ Object::MACK_VIEWS = File.join(MACK_APP, "views") unless Object.const_defined?("MACK_VIEWS")
24
11
 
25
12
  require File.join(File.dirname(__FILE__), "..", "lib", "mack-data_mapper")
26
13
  require File.join(File.dirname(__FILE__), "..", "..", "mack-orm_common", "lib", "mack-orm_common")
27
14
 
15
+
28
16
  load File.join(File.dirname(__FILE__), "lib", "user.rb")
29
17
 
30
18
  class Test::Unit::TestCase
@@ -35,7 +23,7 @@ class Test::Unit::TestCase
35
23
  def cleanup
36
24
  database.adapter.flush_connections!
37
25
  FileUtils.rm_rf($genosaurus_output_directory)
38
- FileUtils.rm_rf(File.join(Mack::Configuration.config_directory, "routes.rb"))
26
+ FileUtils.rm_rf(File.join(MACK_CONFIG, "routes.rb"))
39
27
  end
40
28
 
41
29
  def teardown
@@ -47,7 +35,7 @@ class Test::Unit::TestCase
47
35
  [$genosaurus_output_directory, migrations_directory, models_directory].each do |d|
48
36
  FileUtils.mkdir_p(d)
49
37
  end
50
- FileUtils.cp(fixture_path("routes.rb"), File.join(Mack::Configuration.config_directory, "routes.rb"))
38
+ FileUtils.cp(fixture_path("routes.rb"), File.join(MACK_CONFIG, "routes.rb"))
51
39
  end
52
40
 
53
41
  def migrations_directory
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack-data_mapper
3
3
  version: &id001 !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-06 00:00:00 -04:00
12
+ date: 2008-05-04 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,8 +55,7 @@ files:
55
55
  - lib/scaffold_generator/templates/app/views/new.html.erb.template
56
56
  - lib/scaffold_generator/templates/app/views/show.html.erb.template
57
57
  - lib/scaffold_generator/templates/test.rb.template
58
- - lib/tasks/db_create_drop_tasks.rake
59
- - lib/tasks/db_migration_tasks.rake
58
+ - lib/tasks/db_tasks.rake
60
59
  - README
61
60
  has_rdoc: true
62
61
  homepage:
@@ -81,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
80
  requirements: []
82
81
 
83
82
  rubyforge_project: magrathea
84
- rubygems_version: 1.0.1
83
+ rubygems_version: 1.1.1
85
84
  signing_key:
86
85
  specification_version: 2
87
86
  summary: DataMapper ORM support for Mack
@@ -113,5 +112,5 @@ test_files:
113
112
  - test/lib
114
113
  - test/lib/user.rb
115
114
  - test/tasks
116
- - test/tasks/db_migration_tasks_test.rb
115
+ - test/tasks/db_tasks_test.rb
117
116
  - test/test_helper.rb
@@ -1,76 +0,0 @@
1
- require 'rake'
2
- namespace :db do
3
-
4
- desc "Create the database for your environment."
5
- task :create => :environment do
6
- Mack::Configuration.load_database_configurations(Mack::Configuration.env)
7
- database(:default) do
8
- drop_create_database
9
- end
10
- end
11
-
12
- namespace :create do
13
-
14
- desc "Creates your Full environment. Does NOT create your production database!"
15
- task :all => :environment do
16
- Mack::Configuration.load_database_configurations("test")
17
- database(:default) do
18
- drop_create_database
19
- end
20
- Mack::Configuration.load_database_configurations("development")
21
- database(:default) do
22
- drop_create_database
23
- end
24
- Rake::Task["db:migrate"].invoke
25
- end
26
-
27
- end
28
-
29
- end
30
-
31
- private
32
- def drop_create_database
33
- configuration = database.adapter.instance_variable_get('@configuration')
34
- case database.adapter.class.name
35
- when "DataMapper::Adapters::MysqlAdapter"
36
- DataMapper::Database.setup(:tmp, {
37
- :adapter => "mysql",
38
- :host => "localhost",
39
- :database => "mysql",
40
- :username => ENV["DB_USERNAME"] || "root",
41
- :password => ENV["DB_PASSWORD"] || ""
42
- })
43
- database(:tmp) do
44
- puts "Dropping (MySQL): #{configuration.database}"
45
- database.execute "DROP DATABASE IF EXISTS `#{configuration.database}`"
46
- puts "Creating (MySQL): #{configuration.database}"
47
- database.execute "CREATE DATABASE `#{configuration.database}` DEFAULT CHARACTER SET `utf8`"
48
- begin
49
- database.adapter.flush_connections!
50
- rescue Exception => e
51
- end
52
- end
53
- when "DataMapper::Adapters::PostgresqlAdapter"
54
- ENV['PGHOST'] = configuration.host if configuration.host
55
- ENV['PGPORT'] = configuration.port.to_s if configuration.port
56
- ENV['PGPASSWORD'] = configuration.password.to_s if configuration.password
57
-
58
- database.adapter.flush_connections!
59
- begin
60
- puts "Dropping (PostgreSQL): #{configuration.database}"
61
- `dropdb -U "#{configuration.username}" #{configuration.database}`
62
- rescue Exception => e
63
- end
64
-
65
- begin
66
- puts "Creating (PostgreSQL): #{configuration.database}"
67
- `createdb -U "#{configuration.username}" #{configuration.database}`
68
- rescue Exception => e
69
- end
70
- when 'DataMapper::Adapters::Sqlite3Adapter'
71
- puts "Dropping (SQLite3): #{configuration.database}"
72
- FileUtils.rm_rf(configuration.database)
73
- else
74
- raise "Task not supported for '#{database.adapter}'"
75
- end
76
- end