mack 0.4.2.1 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/CHANGELOG +20 -1
  2. data/README +3 -0
  3. data/bin/mack +5 -1
  4. data/bin/mack_ring_server +15 -0
  5. data/bin/templates/Rakefile.template +1 -1
  6. data/bin/templates/config/database.yml.template +28 -16
  7. data/lib/distributed/routing/urls.rb +13 -26
  8. data/lib/distributed/utils/rinda.rb +45 -0
  9. data/lib/errors/errors.rb +9 -0
  10. data/lib/generators/{generator_base.rb → base.rb} +0 -0
  11. data/lib/generators/migration/base.rb +26 -0
  12. data/lib/generators/migration_generator/migration_generator.rb +14 -0
  13. data/lib/generators/migration_generator/templates/migration.rb.template +9 -0
  14. data/lib/generators/plugin_generator/plugin_generator.rb +2 -0
  15. data/lib/generators/scaffold_generator/scaffold_generator.rb +9 -18
  16. data/lib/generators/scaffold_generator/templates/generic/app/controllers/controller.rb.template +10 -10
  17. data/lib/generators/scaffold_generator/templates/generic/app/models/model.rb.template +2 -0
  18. data/lib/generators/scaffold_generator/templates/no_orm/app/controllers/controller.rb.template +8 -8
  19. data/lib/initialization/configuration.rb +1 -13
  20. data/lib/initialization/initializer.rb +3 -0
  21. data/lib/initialization/initializers/orm_support.rb +30 -5
  22. data/lib/routing/route_map.rb +8 -5
  23. data/lib/routing/urls.rb +20 -16
  24. data/lib/sea_level/helpers/view_helpers/orm_helpers.rb +1 -1
  25. data/lib/tasks/db_tasks.rake +94 -0
  26. data/lib/tasks/mack_ring_server_tasks.rake +33 -0
  27. data/lib/tasks/mack_server_tasks.rake +2 -1
  28. data/lib/tasks/mack_tasks.rake +2 -1
  29. data/lib/tasks/test_tasks.rake +16 -1
  30. data/lib/test_extensions/test_helpers.rb +36 -1
  31. metadata +21 -9
  32. data/bin/templates/config/boot.rb.template +0 -6
  33. data/lib/distributed/routing/url_cache.rb +0 -10
  34. data/lib/generators/scaffold_generator/templates/activerecord/app/models/model.rb.template +0 -2
  35. data/lib/generators/scaffold_generator/templates/data_mapper/app/controllers/controller.rb.template +0 -50
  36. data/lib/generators/scaffold_generator/templates/data_mapper/app/models/model.rb.template +0 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,22 @@
1
+ ===0.4.5
2
+ * Removed boot.rb file. It was unnecessary.
3
+ * When a new Mack application is generated the Rakefile that gets generated is stamped with the Mack gem version used to create it. This ties the project to that gem. This can, of course, be upgraded as new Mack gems come out, but it's a good way of tying your app to a specific revision of Mack.
4
+ * Added support for migrations for both ActiveRecord and DataMapper. DataMapper migration support requires DataMapper 0.3.0 gem. Please keep in mind, though, that DataMapper 0.3.0 has a serious bug in it, which may prevent you from using it. Please see http://www.mackframework.com/2008/04/09/horrible-bug-in-datamapper-030/ for more information.
5
+ * Rewrote distributed routing support to use Rinda inside of plain old DRb. This makes for an almost zero configuration usage.
6
+ * Added: mack_ring_server binary to start a Rinda ring server for use with distributed routing.
7
+ * Sqlite3 is now the default database for Mack applications configured with ORM support.
8
+ * Added a test helper method, rake_task, to aid in the testing of Rake tasks.
9
+ * Added: rake db:migrate
10
+ * Added: rake db:abort_if_pending_migrations
11
+ * Added: rake db:rollback
12
+ * Added: rake db:version
13
+ * Added: rake mack:ring_server:start
14
+ * Added: rake mack:ring_server:stop
15
+ * Added: rake mack:ring_server:restart
16
+ * Added: rake mack:ring_server:services:list
17
+ * gem: application_configuration 1.2.2
18
+ * gem: daemons 1.0.10
19
+
1
20
  ===0.4.2.1
2
21
  * Fixed bug with gems:list rake task that was looking in the wrong path for the gems.rb file.
3
22
 
@@ -7,7 +26,7 @@
7
26
  * Added gems:list and gems:install rake tasks. The gems:list task will list any gems being required for the application. The gems:install task will install all the gems being required for the application.
8
27
  * Filters in controllers can now be inherited from parent controller classes.
9
28
  * gem: mack_ruby_core_extensions 0.1.5
10
- * gem: thing 0.7.1
29
+ * gem: thin 0.7.1
11
30
 
12
31
  ===0.4.1
13
32
  * Improved testing support.
data/README CHANGED
@@ -10,6 +10,9 @@ Mack is also about performance. Because Mack uses technologies like Thin[http://
10
10
  ==Getting Started
11
11
  First things first, let's generate your application:
12
12
  $ mack <app_name>
13
+
14
+ If you'd like to configure your application to use an ORM, then when you generate it, use the following command:
15
+ $ mack <app_name> -o <data_mapper|active_record>
13
16
 
14
17
  To run a Mack application:
15
18
  $ rake script:server
data/bin/mack CHANGED
@@ -24,6 +24,10 @@ opts.parse!(ARGV)
24
24
 
25
25
  include FileUtils
26
26
 
27
+ def mack_version
28
+ "0.4.5"
29
+ end
30
+
27
31
  def create_dir(dir)
28
32
  mkdir_p(dir)
29
33
  puts "Created: #{dir}"
@@ -59,4 +63,4 @@ erb_files.each do |fl|
59
63
  end
60
64
  end
61
65
 
62
- cp(File.join(File.dirname(__FILE__), "templates", "public", "favicon.ico"), File.join(app, "public", "favicon.ico"))
66
+ cp(File.join(File.dirname(__FILE__), "templates", "public", "favicon.ico"), File.join(app, "public", "favicon.ico"))
@@ -0,0 +1,15 @@
1
+ #!/usr/local/bin/ruby
2
+ require 'rubygems'
3
+ require 'daemons'
4
+ require 'rinda/ring'
5
+ require 'rinda/tuplespace'
6
+ require 'fileutils'
7
+
8
+ FileUtils.mkdir_p(File.join("tmp", "pids"))
9
+
10
+ Daemons.run_proc('mack_ring_server', {:dir_mode => :normal, :dir => File.join("tmp", "pids"), :monitor => true, :multiple => false}) do
11
+ puts 'Starting mack_ring_server...'
12
+ DRb.start_service
13
+ Rinda::RingServer.new(Rinda::TupleSpace.new)
14
+ DRb.thread.join
15
+ end
@@ -2,5 +2,5 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
 
5
- gem 'mack'
5
+ gem 'mack', '<%= mack_version %>'
6
6
  require 'mack_tasks'
@@ -1,20 +1,32 @@
1
+ # development:
2
+ # adapter: mysql
3
+ # database: <%= app.downcase %>_development
4
+ # host: localhost
5
+ # username: root
6
+ # password:
7
+ #
8
+ # test:
9
+ # adapter: mysql
10
+ # database: <%= app.downcase %>_test
11
+ # host: localhost
12
+ # username: root
13
+ # password:
14
+ #
15
+ # production:
16
+ # adapter: mysql
17
+ # database: <%= app.downcase %>_production
18
+ # host: localhost
19
+ # username: root
20
+ # password:
21
+
1
22
  development:
2
- adapter: mysql
3
- database: <%= app.downcase %>_development
4
- host: localhost
5
- username: root
6
- password:
7
-
23
+ adapter: sqlite3
24
+ database: db/<%= app.downcase %>_development.db
25
+
8
26
  test:
9
- adapter: mysql
10
- database: <%= app.downcase %>_test
11
- host: localhost
12
- username: root
13
- password:
27
+ adapter: sqlite3
28
+ database: db/<%= app.downcase %>_test.db
14
29
 
15
30
  production:
16
- adapter: mysql
17
- database: <%= app.downcase %>_production
18
- host: localhost
19
- username: root
20
- password:
31
+ adapter: sqlite3
32
+ database: db/<%= app.downcase %>_production.db
@@ -4,45 +4,32 @@ module Mack
4
4
  # A class used to house the Mack::Routes::Url module for distributed applications.
5
5
  # Functionally this class does nothing, but since you can't cache a module, a class is needed.
6
6
  class Urls
7
+ include DRbUndumped
7
8
 
8
9
  def initialize(dsd) # :nodoc:
9
10
  @dsd = dsd
10
- @url_method_list = {}
11
11
  end
12
12
 
13
- # def add_url_method(key, meth)
14
- # @url_method_list[key.to_sym] = meth
15
- # end
13
+ def put
14
+ Mack::Distributed::Utils::Rinda.register_or_renew(:space => app_config.mack.distributed_app_name.to_sym,
15
+ :klass_def => :distributed_routes,
16
+ :object => self)
17
+ end
16
18
 
17
- def []=(key, method)
18
- @url_method_list[key.to_sym] = method
19
- @runner = nil
19
+ def run(meth, options)
20
+ self.send(meth, options)
20
21
  end
21
22
 
22
- def run
23
- if @runner.nil?
24
- klass_name = String.randomize(40).downcase.camelcase
25
- meths = ""
26
- @url_method_list.each_pair {|k,v| meths += v + "\n\n"}
27
- eval %{
28
- class Mack::Distributed::Routes::Temp::M#{klass_name}
29
- include Mack::Routes::Urls
30
- def initialize(dsd)
31
- @dsd = dsd
32
- end
33
- #{meths}
34
- end
35
- }
36
- @runner = "Mack::Distributed::Routes::Temp::M#{klass_name}".constantize.new(@dsd)
23
+ class << self
24
+
25
+ def get(app_name)
26
+ Mack::Distributed::Utils::Rinda.read(:space => app_name.to_sym, :klass_def => :distributed_routes)
37
27
  end
38
- @runner
28
+
39
29
  end
40
30
 
41
31
  end # Urls
42
32
 
43
- module Temp # :nodoc:
44
- end # Temp
45
-
46
33
  end # Routes
47
34
  end # Distributed
48
35
  end # Mack
@@ -0,0 +1,45 @@
1
+ module Mack
2
+ module Distributed
3
+ module Utils
4
+ module Rinda
5
+
6
+ def self.register_or_renew(options = {})
7
+ options = handle_options(options)
8
+ ::DRb.start_service
9
+ begin
10
+ ring_server.take([options[:space], options[:klass_def], nil, nil], options[:timeout])
11
+ rescue Exception => e
12
+ puts e.message
13
+ end
14
+ register(options)
15
+ end
16
+
17
+ def self.register(options = {})
18
+ options = handle_options(options)
19
+ ::DRb.start_service
20
+ ring_server.write([options[:space],
21
+ options[:klass_def],
22
+ options[:object],
23
+ options[:description]],
24
+ ::Rinda::SimpleRenewer.new)
25
+ end
26
+
27
+ def self.ring_server
28
+ rs = ::Rinda::RingFinger.primary
29
+ rs
30
+ end
31
+
32
+ def self.read(options = {})
33
+ options = handle_options(options)
34
+ ring_server.read([options[:space], options[:klass_def], nil, options[:description]], options[:timeout])[2]
35
+ end
36
+
37
+ private
38
+ def self.handle_options(options = {})
39
+ {:space => :name, :klass_def => nil, :object => nil, :description => nil, :timeout => app_config.mack.drb_timeout}.merge(options)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
data/lib/errors/errors.rb CHANGED
@@ -100,5 +100,14 @@ module Mack
100
100
  end
101
101
  end
102
102
 
103
+ # Raised if there are migrations that need to be run before a task is performed.
104
+ class UnrunMigrations < StandardError
105
+ # Taks the number of migrations that need to be run.
106
+ def initialize(number)
107
+ super("You currently have #{number} #{number == 1 ? "migration" : "migrations"} that #{number == 1 ? "needs" : "need"} to be run.")
108
+ end
109
+
110
+ end
111
+
103
112
  end # Errors
104
113
  end # Mack
File without changes
@@ -0,0 +1,26 @@
1
+ module Mack
2
+ module Generator
3
+ module Migration # :nodoc:
4
+ class Base < Mack::Generator::Base
5
+
6
+ attr_reader :db_directory
7
+ attr_reader :migrations_directory
8
+
9
+ def initialize(env = {})
10
+ super(env)
11
+ @db_directory = File.join(MACK_ROOT, "db")
12
+ @migrations_directory = File.join(@db_directory, "migrations")
13
+ end
14
+
15
+ def next_migration_number
16
+ last = Dir.glob(File.join(@migrations_directory, "*.rb")).last
17
+ if last
18
+ return File.basename(last).match(/^\d+/).to_s.succ
19
+ end
20
+ return "001"
21
+ end
22
+
23
+ end # Base
24
+ end # Migration
25
+ end # Generator
26
+ end # Mack
@@ -0,0 +1,14 @@
1
+ class MigrationGenerator < Mack::Generator::Migration::Base
2
+
3
+ require_param :name
4
+
5
+ def generate # :nodoc:
6
+ directory(migrations_directory)
7
+
8
+ template_dir = File.join(File.dirname(__FILE__), "templates")
9
+
10
+ template(File.join(template_dir, "migration.rb.template"), File.join(migrations_directory, "#{next_migration_number}_#{param(:name)}.rb"))
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,9 @@
1
+ class <%= param(:name).camelcase %> < <%= app_config.orm.camelcase %>::Migration
2
+
3
+ def self.up
4
+ end
5
+
6
+ def self.down
7
+ end
8
+
9
+ end
@@ -19,6 +19,8 @@ class PluginGenerator < Mack::Generator::Base
19
19
  directory(plugin_dir)
20
20
  # create vendor/plugins/<name>/lib
21
21
  directory(File.join(plugin_dir, "lib"))
22
+ # create vendor/plugins/<name>/lib/tasks
23
+ directory(File.join(plugin_dir, "lib", "tasks"))
22
24
 
23
25
  # create vendor/plugins/<name>/init.rb
24
26
  template(File.join(template_dir, "init.rb.template"), File.join(plugin_dir, "init.rb"))
@@ -33,31 +33,22 @@ class ScaffoldGenerator < Mack::Generator::Base
33
33
  app_cont_dir = File.join(MACK_APP, "controllers")
34
34
  directory(app_cont_dir)
35
35
 
36
- app_model_dir = File.join(MACK_APP, "models")
37
- directory(app_model_dir)
38
-
39
- app_views_dir = File.join(MACK_APP, "views", @name_plural)
40
- directory(app_views_dir)
41
-
42
36
  temp_dir = File.join(File.dirname(__FILE__), "templates")
43
37
 
44
- case app_config.orm
45
- when "activerecord"
46
- template(File.join(temp_dir, "generic", "app", "controllers", "controller.rb.template"), File.join(app_cont_dir, "#{@name_plural}_controller.rb"), :force => param(:force))
47
- template(File.join(temp_dir, "activerecord", "app", "models", "model.rb.template"), File.join(app_model_dir, "#{@name_singular}.rb"), :force => param(:force))
48
-
49
- template(File.join(temp_dir, "generic", "app", "views", "index.html.erb.template"), File.join(app_views_dir, "index.html.erb"), :force => param(:force))
50
- template(File.join(temp_dir, "generic", "app", "views", "edit.html.erb.template"), File.join(app_views_dir, "edit.html.erb"), :force => param(:force))
51
- template(File.join(temp_dir, "generic", "app", "views", "new.html.erb.template"), File.join(app_views_dir, "new.html.erb"), :force => param(:force))
52
- template(File.join(temp_dir, "generic", "app", "views", "show.html.erb.template"), File.join(app_views_dir, "show.html.erb"), :force => param(:force))
53
- when "data_mapper"
54
- template(File.join(temp_dir, "data_mapper", "app", "controllers", "controller.rb.template"), File.join(app_cont_dir, "#{@name_plural}_controller.rb"), :force => param(:force))
55
- template(File.join(temp_dir, "data_mapper", "app", "models", "model.rb.template"), File.join(app_model_dir, "#{@name_singular}.rb"), :force => param(:force))
38
+ if app_config.orm
39
+ app_model_dir = File.join(MACK_APP, "models")
40
+ directory(app_model_dir)
41
+
42
+ app_views_dir = File.join(MACK_APP, "views", @name_plural)
43
+ directory(app_views_dir)
56
44
 
45
+ template(File.join(temp_dir, "generic", "app", "controllers", "controller.rb.template"), File.join(app_cont_dir, "#{@name_plural}_controller.rb"), :force => param(:force))
46
+ template(File.join(temp_dir, "generic", "app", "models", "model.rb.template"), File.join(app_model_dir, "#{@name_singular}.rb"), :force => param(:force))
57
47
  template(File.join(temp_dir, "generic", "app", "views", "index.html.erb.template"), File.join(app_views_dir, "index.html.erb"), :force => param(:force))
58
48
  template(File.join(temp_dir, "generic", "app", "views", "edit.html.erb.template"), File.join(app_views_dir, "edit.html.erb"), :force => param(:force))
59
49
  template(File.join(temp_dir, "generic", "app", "views", "new.html.erb.template"), File.join(app_views_dir, "new.html.erb"), :force => param(:force))
60
50
  template(File.join(temp_dir, "generic", "app", "views", "show.html.erb.template"), File.join(app_views_dir, "show.html.erb"), :force => param(:force))
51
+ MigrationGenerator.new("NAME" => "create_#{@name_plural}").run
61
52
  else
62
53
  template(File.join(temp_dir, "no_orm", "app", "controllers", "controller.rb.template"), File.join(app_cont_dir, "#{@name_plural}_controller.rb"), :force => param(:force))
63
54
  end
@@ -1,40 +1,40 @@
1
1
  class <%= @name_plural_camel %>Controller < Mack::Controller::Base
2
-
2
+
3
3
  # GET /<%= @name_plural %>
4
4
  def index
5
5
  @<%= @name_plural %> = <%= @name_singular_camel %>.find(:all)
6
6
  end
7
-
7
+
8
8
  # GET /<%= @name_plural %>/1
9
9
  def show
10
10
  @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
11
11
  end
12
-
12
+
13
13
  # GET /<%= @name_plural %>/new
14
14
  def new
15
15
  @<%= @name_singular %> = <%= @name_singular_camel %>.new
16
16
  end
17
-
17
+
18
18
  # GET /<%= @name_plural %>/1/edit
19
19
  def edit
20
20
  @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
21
21
  end
22
-
22
+
23
23
  # POST /<%= @name_plural %>
24
24
  def create
25
25
  @<%= @name_singular %> = <%= @name_singular_camel %>.new(params(:<%= @name_singular %>))
26
26
  if @<%= @name_singular %>.save
27
- redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>))
27
+ redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>.id))
28
28
  else
29
29
  render(:action => "new")
30
30
  end
31
31
  end
32
-
32
+
33
33
  # PUT /<%= @name_plural %>/1
34
34
  def update
35
35
  @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
36
36
  if @<%= @name_singular %>.update_attributes(params(:<%= @name_singular %>))
37
- redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>))
37
+ redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>.id))
38
38
  else
39
39
  render(:action => "edit")
40
40
  end
@@ -43,8 +43,8 @@ class <%= @name_plural_camel %>Controller < Mack::Controller::Base
43
43
  # DELETE /<%= @name_plural %>/1
44
44
  def delete
45
45
  @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
46
- @<%= @name_singular %>.destroy
46
+ @<%= @name_singular %>.destroy<%= app_config.orm == "data_mapper" ? "!" : "" %>
47
47
  redirect_to(<%= @name_plural %>_index_url)
48
48
  end
49
-
49
+
50
50
  end
@@ -0,0 +1,2 @@
1
+ class <%= @name_singular_camel %> < <%= app_config.orm.camelcase %>::Base
2
+ end
@@ -1,38 +1,38 @@
1
1
  class <%= @name_plural_camel %>Controller < Mack::Controller::Base
2
-
2
+
3
3
  # GET /<%= @name_plural %>
4
4
  def index
5
5
  "<%= @name_plural_camel %>#index"
6
6
  end
7
-
7
+
8
8
  # POST /<%= @name_plural %>
9
9
  def create
10
10
  "<%= @name_plural_camel %>#create"
11
11
  end
12
-
12
+
13
13
  # GET /<%= @name_plural %>/new
14
14
  def new
15
15
  "<%= @name_plural_camel %>#new"
16
16
  end
17
-
17
+
18
18
  # GET /<%= @name_plural %>/1
19
19
  def show
20
20
  "<%= @name_plural_camel %>#show id: #{params(:id)}"
21
21
  end
22
-
22
+
23
23
  # GET /<%= @name_plural %>/1/edit
24
24
  def edit
25
25
  "<%= @name_plural_camel %>#edit id: #{params(:id)}"
26
26
  end
27
-
27
+
28
28
  # PUT /<%= @name_plural %>/1
29
29
  def update
30
30
  "<%= @name_plural_camel %>#update id: #{params(:id)}"
31
31
  end
32
-
32
+
33
33
  # DELETE /<%= @name_plural %>/1
34
34
  def delete
35
35
  "<%= @name_plural_camel %>#delete"
36
36
  end
37
-
37
+
38
38
  end
@@ -61,23 +61,11 @@ module Mack
61
61
  }
62
62
  }
63
63
  },
64
- "mack_distributed_routes_url_cache_options" => {
65
- "debug" => false,
66
- "adapter" => "drb",
67
- "store_options" => {
68
- "host" => "druby://127.0.0.1:61676"
69
- },
70
- "logging" => {
71
- "logger_1" => {
72
- "type" => "file",
73
- "file" => File.join(MACK_ROOT, "log", "mack_distributed_routes_url_cache.log")
74
- }
75
- }
76
- },
77
64
  "mack::site_domain" => "http://localhost:3000",
78
65
  "mack::use_distributed_routes" => false,
79
66
  "mack::distributed_app_name" => nil,
80
67
  "mack::distributed_site_domain" => "http://localhost:3000",
68
+ "mack::drb_timeout" => 1,
81
69
  "log::detailed_requests" => true,
82
70
  "log::level" => "info",
83
71
  "log::console" => false,
@@ -9,6 +9,9 @@ require 'log4r'
9
9
  require 'crypt/rijndael'
10
10
  require 'singleton'
11
11
  require 'uri'
12
+ require 'drb'
13
+ require 'rinda/ring'
14
+ require 'rinda/tuplespace'
12
15
 
13
16
  # Set up Mack constants, if they haven't already been set up.
14
17
  unless Object.const_defined?("MACK_ENV")
@@ -1,20 +1,45 @@
1
+ #--
1
2
  # setup ORM:
3
+ #++
2
4
 
3
- [:activerecord, :data_mapper].each do |orm|
4
- eval("def using_#{orm}?; false; end")
5
+ $using_active_record = false
6
+ $using_data_mapper = false
7
+
8
+ # Returns true if the system is setup to use ActiveRecord
9
+ def using_active_record?
10
+ $using_active_record
11
+ end
12
+
13
+ # Returns true if the system is setup to use DataMapper
14
+ def using_data_mapper?
15
+ $using_data_mapper
16
+ end
17
+
18
+ module ActiveRecord # :nodoc:
19
+ end
20
+ module DataMapper # :nodoc:
5
21
  end
6
22
 
7
23
  unless app_config.orm.nil?
8
24
  dbs = YAML::load(ERB.new(IO.read(File.join(MACK_CONFIG, "database.yml"))).result)
9
25
  case app_config.orm
10
- when 'activerecord'
26
+ when 'active_record'
11
27
  require 'activerecord'
12
28
  ActiveRecord::Base.establish_connection(dbs[MACK_ENV])
13
- eval("def using_activerecord?; true; end")
29
+ class ArSchemaInfo < ActiveRecord::Base # :nodoc:
30
+ set_table_name :schema_info
31
+ end
32
+ $using_active_record = true
33
+ $using_data_mapper = false # set to false, in case we're flipping back and forth
14
34
  when 'data_mapper'
15
35
  require 'data_mapper'
16
36
  DataMapper::Database.setup(dbs[MACK_ENV])
17
- eval("def using_data_mapper?; true; end")
37
+ class DmSchemaInfo < DataMapper::Base # :nodoc:
38
+ set_table_name "schema_info"
39
+ property :version, :integer, :default => 0
40
+ end
41
+ $using_data_mapper = true
42
+ $using_active_record = false # set to false, in case we're flipping back and forth
18
43
  else
19
44
  MACK_DEFAULT_LOGGER.warn("Attempted to configure an unknown ORM: #{app_config.orm}")
20
45
  end
@@ -7,12 +7,16 @@ module Mack
7
7
  #
8
8
  # See Mack::Routes::RouteMap for more information.
9
9
  def self.build
10
- $distributed_urls = Mack::Distributed::Routes::Urls.new(app_config.mack.distributed_site_domain) if $distributed_urls.nil?
11
10
  yield Mack::Routes::RouteMap.instance
12
- Mack::Routes::Urls.include_safely_into(Mack::Controller::Base, Mack::ViewBinder, Test::Unit::TestCase)
11
+ Mack::Routes::Urls.include_safely_into(Mack::Controller::Base,
12
+ Mack::ViewBinder,
13
+ Test::Unit::TestCase,
14
+ Mack::Distributed::Routes::Urls)
13
15
  if app_config.mack.use_distributed_routes
14
16
  raise Mack::Distributed::Errors::ApplicationNameUndefined.new if app_config.mack.distributed_app_name.nil?
15
- Mack::Distributed::Routes::UrlCache.set(app_config.mack.distributed_app_name.to_sym, $distributed_urls)
17
+
18
+ d_urls = Mack::Distributed::Routes::Urls.new(app_config.mack.distributed_site_domain)
19
+ d_urls.put
16
20
  end
17
21
  # puts "Finished compiling routes: #{Mack::Routes::RouteMap.instance.routes_list.inspect}"
18
22
  end
@@ -218,9 +222,8 @@ module Mack
218
222
  Mack::Routes::Urls.class_eval(url)
219
223
 
220
224
  if app_config.mack.use_distributed_routes
221
- $distributed_urls["#{n_route}_url"] = url
222
225
 
223
- $distributed_urls["#{n_route}_distributed_url"] = %{
226
+ Mack::Routes::Urls.class_eval %{
224
227
  def #{n_route}_distributed_url(options = {})
225
228
  (@dsd || app_config.mack.distributed_site_domain) + #{n_route}_url(options)
226
229
  end
data/lib/routing/urls.rb CHANGED
@@ -64,17 +64,19 @@ module Mack
64
64
  # droute_url(:registration_app, :signup_url, {:from => :google})
65
65
  def droute_url(app_name, route_name, options = {})
66
66
  if app_config.mack.use_distributed_routes
67
- ivar_cache("droute_url_hash") do
68
- {}
69
- end
70
- d_urls = @droute_url_hash[app_name.to_sym]
71
- if d_urls.nil?
72
- d_urls = Mack::Distributed::Routes::UrlCache.get(app_name.to_sym)
73
- @droute_url_hash[app_name.to_sym] = d_urls
74
- if d_urls.nil?
75
- raise Mack::Distributed::Errors::UnknownApplication.new(app_name)
76
- end
77
- end
67
+ d_urls = Mack::Distributed::Routes::Urls.get(app_name)
68
+ # return d_urls.send(route_name, options)
69
+ # ivar_cache("droute_url_hash") do
70
+ # {}
71
+ # end
72
+ # d_urls = @droute_url_hash[app_name.to_sym]
73
+ # if d_urls.nil?
74
+ # d_urls = Mack::Distributed::Routes::UrlCache.get(app_name.to_sym)
75
+ # @droute_url_hash[app_name.to_sym] = d_urls
76
+ # if d_urls.nil?
77
+ # raise Mack::Distributed::Errors::UnknownApplication.new(app_name)
78
+ # end
79
+ # end
78
80
  route_name = route_name.to_s
79
81
  if route_name.match(/_url$/)
80
82
  unless route_name.match(/_distributed_url$/)
@@ -83,11 +85,13 @@ module Mack
83
85
  else
84
86
  route_name << "_distributed_url"
85
87
  end
86
- if d_urls.run.respond_to?(route_name)
87
- return d_urls.run.send(route_name, options)
88
- else
89
- raise Mack::Distributed::Errors::UnknownRouteName.new(app_name, route_name)
90
- end
88
+ raise Mack::Distributed::Errors::UnknownRouteName.new(app_name, route_name) unless d_urls.respond_to?(route_name)
89
+ return d_urls.run(route_name, options)
90
+ # if d_urls.run.respond_to?(route_name)
91
+ # return d_urls.run.send(route_name, options)
92
+ # else
93
+ # raise Mack::Distributed::Errors::UnknownRouteName.new(app_name, route_name)
94
+ # end
91
95
  else
92
96
  return nil
93
97
  end
@@ -1,4 +1,4 @@
1
- if using_activerecord?
1
+ if using_active_record?
2
2
  class ActiveRecord::Base # :nodoc:
3
3
  def business_display_name
4
4
  self.class.name#.titlecase
@@ -0,0 +1,94 @@
1
+ namespace :db do
2
+
3
+ desc "Migrate the database through scripts in db/migrations"
4
+ task :migrate => "db:schema:create" do
5
+ migration_files.each do |migration|
6
+ require migration
7
+ migration = File.basename(migration, ".rb")
8
+ m_number = migration_number(migration)
9
+ if m_number > @schema_info.version
10
+ migration_name(migration).camelcase.constantize.up
11
+ @schema_info.version += 1
12
+ @schema_info.save
13
+ end
14
+ end # each
15
+ end # migrate
16
+
17
+ desc "Rolls the schema back to the previous version. Specify the number of steps with STEP=n"
18
+ task :rollback => ["db:schema:create", "db:abort_if_pending_migrations"] do
19
+ migrations = migration_files.reverse
20
+ (ENV["STEP"] || 1).to_i.times do |step|
21
+ migration = migrations[step]
22
+ require migration
23
+ migration = File.basename(migration, ".rb")
24
+ m_number = migration_number(migration)
25
+ if m_number == @schema_info.version
26
+ migration_name(migration).camelcase.constantize.down
27
+ @schema_info.version -= 1
28
+ @schema_info.save
29
+ end
30
+ end
31
+
32
+ end # rollback
33
+
34
+ desc "Raises an error if there are pending migrations"
35
+ task :abort_if_pending_migrations do
36
+ migrations = migration_files.reverse
37
+ return if migrations.empty?
38
+ migration = migrations.first
39
+ migration = File.basename(migration, ".rb")
40
+ m_number = migration_number(migration)
41
+ if m_number > @schema_info.version
42
+ raise Mack::Errors::UnrunMigrations.new(m_number - @schema_info.version)
43
+ end
44
+ end
45
+
46
+ desc "Displays the current schema version of your database"
47
+ task :version => "db:schema:create" do
48
+ puts "\nYour database is currently at version: #{@schema_info.version}\n"
49
+ end
50
+
51
+ private
52
+ namespace :schema do
53
+
54
+ task :create => "mack:environment" do
55
+ if using_data_mapper?
56
+ require 'data_mapper/migration'
57
+ unless DmSchemaInfo.table.exists?
58
+ DmSchemaInfo.table.create!
59
+ DmSchemaInfo.create(:version => 0)
60
+ end
61
+ @schema_info = DmSchemaInfo.first
62
+ elsif using_active_record?
63
+ require 'active_record/migration'
64
+ class CreateArSchemaInfo < ActiveRecord::Migration # :nodoc:
65
+ def self.up
66
+ create_table :schema_info do |t|
67
+ t.column :version, :integer, :default => 0
68
+ end
69
+ end # up
70
+ end # CreateArSchemaInfo
71
+ unless ArSchemaInfo.table_exists?
72
+ CreateArSchemaInfo.up
73
+ ArSchemaInfo.create(:version => 0)
74
+ end
75
+ @schema_info = ArSchemaInfo.find(:first)
76
+ end
77
+ end # create
78
+
79
+ end # schema
80
+
81
+
82
+ def migration_files
83
+ Dir.glob(File.join(MACK_ROOT, "db", "migrations", "*.rb"))
84
+ end
85
+
86
+ def migration_number(migration)
87
+ migration.match(/(^\d+)/).captures.last.to_i
88
+ end
89
+
90
+ def migration_name(migration)
91
+ migration.match(/^\d+_(.+)/).captures.last
92
+ end
93
+
94
+ end # db
@@ -0,0 +1,33 @@
1
+ require 'rinda/ring'
2
+ namespace :mack do
3
+ namespace :ring_server do
4
+
5
+ desc "Start the Rinda ring server"
6
+ task :start do
7
+ `mack_ring_server start`
8
+ end
9
+
10
+ desc "Stop the Rinda ring server"
11
+ task :stop do
12
+ `mack_ring_server stop`
13
+ end
14
+
15
+ namespace :services do
16
+
17
+ desc "Lists all services on the ring server"
18
+ task :list do
19
+ DRb.start_service
20
+ ring_server = Rinda::RingFinger.primary
21
+ services = ring_server.read_all([nil, nil, nil, nil])
22
+ puts "Services on #{ring_server.__drburi}"
23
+ services.each do |service|
24
+ puts "#{service[0]}: #{service[1]} on #{service[2].__drburi} - #{service[3]}"
25
+ end
26
+ end
27
+
28
+ end # services
29
+
30
+ end # ring_server
31
+ end # mack
32
+
33
+ alias_task "mack:ring_server:restart", "mack:ring_server:stop", "mack:ring_server:start"
@@ -30,7 +30,8 @@ namespace :mack do
30
30
  options.handler = (ENV["HANDLER"] ||= d_handler)
31
31
 
32
32
 
33
- require File.join(MACK_ROOT, "config", "boot.rb")
33
+ # require File.join(MACK_ROOT, "config", "boot.rb")
34
+ require 'mack'
34
35
 
35
36
  if options.handler == "thin"
36
37
  # thin_opts = ["start", "-r", "config/thin.ru"]
@@ -4,7 +4,8 @@ namespace :mack do
4
4
  task :environment do
5
5
  MACK_ENV = ENV["MACK_ENV"] ||= "development" unless Object.const_defined?("MACK_ENV")
6
6
  MACK_ROOT = FileUtils.pwd unless Object.const_defined?("MACK_ROOT")
7
- require File.join(MACK_ROOT, "config", "boot.rb")
7
+ require 'mack'
8
+ # require File.join(MACK_ROOT, "config", "boot.rb")
8
9
  end # environment
9
10
 
10
11
  desc "Loads an irb console allow you full access to the application w/o a browser."
@@ -1,7 +1,22 @@
1
1
  desc "Run test code."
2
2
  Rake::TestTask.new(:default) do |t|
3
- Rake::Task["log:clear"].invoke
3
+ # Rake::Task["log:clear"].invoke
4
4
  t.libs << "test"
5
5
  t.pattern = 'test/**/*_test.rb'
6
6
  t.verbose = true
7
7
  end
8
+
9
+ namespace :test do
10
+
11
+ task :empty do |t|
12
+ ENV["TEST:EMPTY"] = "true"
13
+ puts ENV["TEST:EMPTY"]
14
+ end
15
+
16
+ task :raise_exception do |t|
17
+ raise "Oh No!"
18
+ end
19
+
20
+ end
21
+
22
+ alias_task :test, :default
@@ -4,13 +4,48 @@ module Mack
4
4
 
5
5
  module TestHelpers
6
6
 
7
+ # Runs the given rake task. Takes an optional hash that mimics command line parameters.
8
+ def rake_task(name, env = {}, tasks = File.join(File.dirname(__FILE__), "..", "mack_tasks.rb"))
9
+ # set up the Rake application
10
+ rake = Rake::Application.new
11
+ Rake.application = rake
12
+
13
+ load(tasks)
14
+
15
+ # save the old ENV so we can revert it
16
+ old_env = ENV.to_hash
17
+ # add in the new ENV stuff
18
+ env.each_pair {|k,v| ENV[k.to_s] = v}
19
+
20
+ begin
21
+ # run the rake task
22
+ rake[name].invoke
23
+
24
+ # yield for the tests
25
+ yield if block_given?
26
+
27
+ rescue Exception => e
28
+ raise e
29
+ ensure
30
+ # empty out the ENV
31
+ ENV.clear
32
+ # revert to the ENV before the test started
33
+ old_env.to_hash.each_pair {|k,v| ENV[k] = v}
34
+
35
+ # get rid of the Rake application
36
+ Rake.application = nil
37
+ end
38
+ end
39
+
40
+ # Temporarily changes the application configuration. Changes are reverted after
41
+ # the yield returns.
7
42
  def temp_app_config(options = {})
8
43
  app_config.load_hash(options, String.randomize)
9
44
  yield
10
45
  app_config.revert
11
46
  end
12
47
 
13
- def remote_test
48
+ def remote_test # :nodoc:
14
49
  if (app_config.run_remote_tests)
15
50
  yield
16
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2.1
4
+ version: 0.4.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-04-02 00:00:00 -04:00
12
+ date: 2008-04-14 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,7 +37,7 @@ dependencies:
37
37
  requirements:
38
38
  - - "="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.1
40
+ version: 1.2.2
41
41
  version:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: cachetastic
@@ -84,10 +84,20 @@ dependencies:
84
84
  - !ruby/object:Gem::Version
85
85
  version: 1.1.4
86
86
  version:
87
+ - !ruby/object:Gem::Dependency
88
+ name: daemons
89
+ version_requirement:
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.0.10
95
+ version:
87
96
  description: Mack is a powerful, yet simple, web application framework. It takes some cues from the likes of Rails and Merb, so it's not entirely unfamiliar. Mack hopes to provide developers a great framework for building, and deploying, portal and distributed applications.
88
97
  email: mark@mackframework.com
89
98
  executables:
90
99
  - mack
100
+ - mack_ring_server
91
101
  extensions: []
92
102
 
93
103
  extra_rdoc_files:
@@ -98,18 +108,19 @@ files:
98
108
  - lib/core_extensions/kernel.rb
99
109
  - lib/core_extensions/string.rb
100
110
  - lib/distributed/errors/errors.rb
101
- - lib/distributed/routing/url_cache.rb
102
111
  - lib/distributed/routing/urls.rb
112
+ - lib/distributed/utils/rinda.rb
103
113
  - lib/errors/errors.rb
104
- - lib/generators/generator_base.rb
114
+ - lib/generators/base.rb
115
+ - lib/generators/migration/base.rb
116
+ - lib/generators/migration_generator/migration_generator.rb
117
+ - lib/generators/migration_generator/templates/migration.rb.template
105
118
  - lib/generators/plugin_generator/plugin_generator.rb
106
119
  - lib/generators/plugin_generator/templates/init.rb.template
107
120
  - lib/generators/plugin_generator/templates/lib/plugin.rb.template
108
121
  - lib/generators/scaffold_generator/scaffold_generator.rb
109
- - lib/generators/scaffold_generator/templates/activerecord/app/models/model.rb.template
110
- - lib/generators/scaffold_generator/templates/data_mapper/app/controllers/controller.rb.template
111
- - lib/generators/scaffold_generator/templates/data_mapper/app/models/model.rb.template
112
122
  - lib/generators/scaffold_generator/templates/generic/app/controllers/controller.rb.template
123
+ - lib/generators/scaffold_generator/templates/generic/app/models/model.rb.template
113
124
  - lib/generators/scaffold_generator/templates/generic/app/views/edit.html.erb.template
114
125
  - lib/generators/scaffold_generator/templates/generic/app/views/index.html.erb.template
115
126
  - lib/generators/scaffold_generator/templates/generic/app/views/new.html.erb.template
@@ -143,9 +154,11 @@ files:
143
154
  - lib/sea_level/session.rb
144
155
  - lib/sea_level/view_binder.rb
145
156
  - lib/tasks/cachetastic_tasks.rake
157
+ - lib/tasks/db_tasks.rake
146
158
  - lib/tasks/gem_tasks.rake
147
159
  - lib/tasks/log_tasks.rake
148
160
  - lib/tasks/mack_dump_tasks.rake
161
+ - lib/tasks/mack_ring_server_tasks.rake
149
162
  - lib/tasks/mack_server_tasks.rake
150
163
  - lib/tasks/mack_tasks.rake
151
164
  - lib/tasks/rake_helpers.rb
@@ -166,7 +179,6 @@ files:
166
179
  - bin/templates/config/app_config/development.yml.template
167
180
  - bin/templates/config/app_config/production.yml.template
168
181
  - bin/templates/config/app_config/test.yml.template
169
- - bin/templates/config/boot.rb.template
170
182
  - bin/templates/config/database.yml.template
171
183
  - bin/templates/config/initializers/gems.rb.template
172
184
  - bin/templates/config/routes.rb.template
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- require 'rack'
3
- require 'fileutils'
4
-
5
- gem 'mack'
6
- require 'mack'
@@ -1,10 +0,0 @@
1
- module Mack
2
- module Distributed
3
- module Routes # :nodoc:
4
- # Used to house the Mack::Distributed::Routes::Urls object for each distributed application.
5
- class UrlCache < Cachetastic::Caches::Base
6
-
7
- end # UrlCache
8
- end # Routes
9
- end # Distributed
10
- end # Mack
@@ -1,2 +0,0 @@
1
- class <%= @name_singular_camel %> < ActiveRecord::Base
2
- end
@@ -1,50 +0,0 @@
1
- class <%= @name_plural_camel %>Controller < Mack::Controller::Base
2
-
3
- # GET /<%= @name_plural %>
4
- def index
5
- @<%= @name_plural %> = <%= @name_singular_camel %>.find(:all)
6
- end
7
-
8
- # GET /<%= @name_plural %>/1
9
- def show
10
- @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
11
- end
12
-
13
- # GET /<%= @name_plural %>/new
14
- def new
15
- @<%= @name_singular %> = <%= @name_singular_camel %>.new
16
- end
17
-
18
- # GET /<%= @name_plural %>/1/edit
19
- def edit
20
- @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
21
- end
22
-
23
- # POST /<%= @name_plural %>
24
- def create
25
- @<%= @name_singular %> = <%= @name_singular_camel %>.new(params(:<%= @name_singular %>))
26
- if @<%= @name_singular %>.save
27
- redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>.id))
28
- else
29
- render(:action => "new")
30
- end
31
- end
32
-
33
- # PUT /<%= @name_plural %>/1
34
- def update
35
- @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
36
- if @<%= @name_singular %>.update_attributes(params(:<%= @name_singular %>))
37
- redirect_to(<%= @name_plural %>_show_url(:id => @<%= @name_singular %>.id))
38
- else
39
- render(:action => "edit")
40
- end
41
- end
42
-
43
- # DELETE /<%= @name_plural %>/1
44
- def delete
45
- @<%= @name_singular %> = <%= @name_singular_camel %>.find(params(:id))
46
- @<%= @name_singular %>.destroy!
47
- redirect_to(<%= @name_plural %>_index_url)
48
- end
49
-
50
- end
@@ -1,2 +0,0 @@
1
- class <%= @name_singular_camel %> < DataMapper::Base
2
- end