mack-active_record 0.5.1 → 0.5.5

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.
@@ -55,16 +55,16 @@ module Mack
55
55
  end
56
56
  end
57
57
  end
58
- File.join(MACK_VIEWS, "application", "_error_messages.html.erb")
58
+ File.join(Mack::Configuration.views_directory, "application", "_error_messages.html.erb")
59
59
  unless app_errors.empty?
60
60
  if view_partial.nil?
61
- if File.exist?(File.join(MACK_VIEWS, "application", "_error_messages.html.erb"))
62
- render :partial => "application/error_messages", :locals => {:errors => app_errors}
61
+ if File.exist?(File.join(Mack::Configuration.views_directory, "application", "_error_messages.html.erb"))
62
+ render(:partial, "application/error_messages", :locals => {:errors => app_errors})
63
63
  else
64
- render :text => DEFAULT_PARTIAL, :locals => {:errors => app_errors}
64
+ render(:text, DEFAULT_PARTIAL, :locals => {:errors => app_errors})
65
65
  end
66
66
  else
67
- render :partial => view_partial, :locals => {:errors => app_errors}
67
+ render(:partial, view_partial, :locals => {:errors => app_errors})
68
68
  end
69
69
  else
70
70
  ""
@@ -4,14 +4,15 @@ require 'erubis'
4
4
  begin
5
5
  require 'mack-orm_common'
6
6
  rescue Exception => e
7
+ puts e
7
8
  end
8
9
 
9
10
  require 'activerecord'
10
11
 
11
- dbs = YAML::load(Erubis::Eruby.new(IO.read(File.join(MACK_CONFIG, "database.yml"))).result)
12
+ dbs = Mack::Configuration.database_configurations
12
13
 
13
14
  unless dbs.nil?
14
- ActiveRecord::Base.establish_connection(dbs[MACK_ENV])
15
+ ActiveRecord::Base.establish_connection(dbs[Mack::Configuration.env])
15
16
  class SchemaInfo < ActiveRecord::Base # :nodoc:
16
17
  set_table_name 'schema_info'
17
18
  end
@@ -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_CONFIG, "routes.rb")
23
+ routes = File.join(Mack::Configuration.config_directory, "routes.rb")
24
24
  rf = File.open(routes).read
25
25
  unless rf.match(".resource :#{@name_plural}")
26
26
  puts "Updating routes.rb"
@@ -26,7 +26,7 @@ class <%= @name_plural_camel %>Controller < Mack::Controller::Base
26
26
  if @<%= @name_singular %>.save
27
27
  redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>.id))
28
28
  else
29
- render(:action => "new")
29
+ render(:action, "new")
30
30
  end
31
31
  end
32
32
 
@@ -36,7 +36,7 @@ class <%= @name_plural_camel %>Controller < Mack::Controller::Base
36
36
  if @<%= @name_singular %>.update_attributes(params(:<%= @name_singular %>))
37
37
  redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>.id))
38
38
  else
39
- render(:action => "edit")
39
+ render(:action, "edit")
40
40
  end
41
41
  end
42
42
 
@@ -0,0 +1,70 @@
1
+ require 'rake'
2
+ namespace :db do
3
+
4
+ desc "Create the database for your environment."
5
+ task :create => :environment do
6
+ drop_create_database
7
+ end
8
+
9
+ namespace :create do
10
+
11
+ desc "Creates your Full environment. Does NOT create your production database!"
12
+ task :all => :environment do
13
+ drop_create_database("development")
14
+ drop_create_database("test")
15
+ ActiveRecord::Base.establish_connection(Mack::Configuration.database_configurations["development"])
16
+ Rake::Task["db:migrate"].invoke
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+ private
24
+ def drop_create_database(env = Mack::Configuration.env)
25
+ abcs = Mack::Configuration.database_configurations
26
+ db_settings = abcs[env]
27
+ case db_settings["adapter"]
28
+ when "mysql"
29
+ ActiveRecord::Base.establish_connection(
30
+ :adapter => "mysql",
31
+ :host => "localhost",
32
+ :database => "mysql",
33
+ :username => ENV["DB_USERNAME"] || "root",
34
+ :password => ENV["DB_PASSWORD"] || ""
35
+ )
36
+ puts "Dropping (MySQL): #{db_settings["database"]}"
37
+ ActiveRecord::Base.connection.execute "DROP DATABASE IF EXISTS `#{db_settings["database"]}`"
38
+
39
+ if db_settings["collation"]
40
+ puts "Dropping (MySQL): #{db_settings["database"]}"
41
+ ActiveRecord::Base.connection.execute "CREATE DATABASE `#{db_settings["database"]}` DEFAULT CHARACTER SET `#{db_settings["charset"] || 'utf8'}` COLLATE `#{db_settings["collation"]}`"
42
+ else
43
+ puts "Creating (MySQL): #{db_settings["database"]}"
44
+ ActiveRecord::Base.connection.execute "CREATE DATABASE `#{db_settings["database"]}` DEFAULT CHARACTER SET `#{db_settings["charset"] || 'utf8'}`"
45
+ end
46
+ when "postgresql"
47
+ ENV['PGHOST'] = db_settings["host"] if db_settings["host"]
48
+ ENV['PGPORT'] = db_settings["port"].to_s if db_settings["port"]
49
+ ENV['PGPASSWORD'] = db_settings["password"].to_s if db_settings["password"]
50
+ enc_option = "-E #{db_settings["encoding"]}" if db_settings["encoding"]
51
+
52
+ ActiveRecord::Base.clear_active_connections!
53
+ begin
54
+ puts "Dropping (PostgreSQL): #{db_settings["database"]}"
55
+ `dropdb -U "#{db_settings["username"]}" #{db_settings["database"]}`
56
+ rescue Exception => e
57
+ end
58
+
59
+ begin
60
+ puts "Creating (PostgreSQL): #{db_settings["database"]}"
61
+ `createdb #{enc_option} -U "#{db_settings["username"]}" #{db_settings["database"]}`
62
+ rescue Exception => e
63
+ end
64
+ when 'sqlite3'
65
+ ActiveRecord::Base.clear_active_connections!
66
+ FileUtils.rm_rf(db_settings["database"])
67
+ else
68
+ raise "Task not supported by '#{db_settings["adapter"]}'"
69
+ end
70
+ end
@@ -1,3 +1,4 @@
1
+ require 'rake'
1
2
  namespace :db do
2
3
 
3
4
  desc "Migrate the database through scripts in db/migrations"
@@ -71,7 +72,7 @@ namespace :db do
71
72
 
72
73
 
73
74
  def migration_files
74
- Dir.glob(File.join(MACK_ROOT, "db", "migrations", "*.rb"))
75
+ Dir.glob(File.join(Mack::Configuration.root, "db", "migrations", "*.rb"))
75
76
  end
76
77
 
77
78
  def migration_number(migration)
data/test/database.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  test:
2
2
  adapter: sqlite3
3
- database: <%= File.join(MACK_ROOT, "mack-active_record_test.db") %>
3
+ database: <%= File.join(Mack::Configuration.root, "mack-active_record_test.db") %>
@@ -26,7 +26,7 @@ class ZoosController < Mack::Controller::Base
26
26
  if @zoo.save
27
27
  redirect_to(zoos_show_url(:id => @zoo.id))
28
28
  else
29
- render(:action => "new")
29
+ render(:action, "new")
30
30
  end
31
31
  end
32
32
 
@@ -36,7 +36,7 @@ class ZoosController < Mack::Controller::Base
36
36
  if @zoo.update_attributes(params(:zoo))
37
37
  redirect_to(zoos_show_url(:id => @zoo.id))
38
38
  else
39
- render(:action => "edit")
39
+ render(:action, "edit")
40
40
  end
41
41
  end
42
42
 
@@ -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_CONFIG, "routes.rb")) do |f|
7
+ File.open(File.join(Mack::Configuration.config_directory, "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_CONFIG, "routes.rb")) do |f|
27
+ File.open(File.join(Mack::Configuration.config_directory, "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_VIEWS, "zoos")
46
+ File.join(Mack::Configuration.views_directory, "zoos")
47
47
  end
48
48
 
49
49
  def model_file
50
- File.join(MACK_APP, "models", "zoo.rb")
50
+ File.join(Mack::Configuration.app_directory, "models", "zoo.rb")
51
51
  end
52
52
 
53
53
  def controller_file
54
- File.join(MACK_APP, "controllers", "zoos_controller.rb")
54
+ File.join(Mack::Configuration.app_directory, "controllers", "zoos_controller.rb")
55
55
  end
56
56
 
57
57
  def migration_file
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class DbTasksTest < Test::Unit::TestCase
4
4
 
5
- $current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "db_tasks.rake")
5
+ $current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "db_migration_tasks.rake")
6
6
 
7
7
  def test_db_rollback
8
8
  test_db_migrate
data/test/test_helper.rb CHANGED
@@ -1,13 +1,26 @@
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
+
4
17
  $genosaurus_output_directory = File.join(File.dirname(__FILE__), "..", "tmp")
5
18
 
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")
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")
11
24
 
12
25
  require File.join(File.dirname(__FILE__), "..", "lib", "mack-active_record")
13
26
  require File.join(File.dirname(__FILE__), "..", "..", "mack-orm_common", "lib", "mack-orm_common")
@@ -23,7 +36,7 @@ class Test::Unit::TestCase
23
36
  def cleanup
24
37
  ActiveRecord::Base.clear_active_connections!
25
38
  FileUtils.rm_rf($genosaurus_output_directory)
26
- FileUtils.rm_rf(File.join(MACK_CONFIG, "routes.rb"))
39
+ FileUtils.rm_rf(File.join(Mack::Configuration.config_directory, "routes.rb"))
27
40
  end
28
41
 
29
42
  def teardown
@@ -35,7 +48,7 @@ class Test::Unit::TestCase
35
48
  [$genosaurus_output_directory, migrations_directory, models_directory].each do |d|
36
49
  FileUtils.mkdir_p(d)
37
50
  end
38
- FileUtils.cp(fixture_path("routes.rb"), File.join(MACK_CONFIG, "routes.rb"))
51
+ FileUtils.cp(fixture_path("routes.rb"), File.join(Mack::Configuration.config_directory, "routes.rb"))
39
52
  end
40
53
 
41
54
  def migrations_directory
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack-active_record
3
3
  version: &id001 !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.5
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-04 00:00:00 -04:00
12
+ date: 2008-05-21 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,7 +55,8 @@ 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_tasks.rake
58
+ - lib/tasks/db_create_drop_tasks.rake
59
+ - lib/tasks/db_migration_tasks.rake
59
60
  - README
60
61
  has_rdoc: true
61
62
  homepage:
@@ -111,5 +112,5 @@ test_files:
111
112
  - test/lib
112
113
  - test/lib/user.rb
113
114
  - test/tasks
114
- - test/tasks/db_tasks_test.rb
115
+ - test/tasks/db_migration_tasks_test.rb
115
116
  - test/test_helper.rb