public
Fork of markbates/mack
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/juretta/mack.git
Search Repo:
More testing for distributed routes, as well as a few new exceptions to be 
thrown. If you're using distributed urls and you call droute_url you get 
nil back. If you don't set an application name for your distributed app a 
Mack::Distributed::Errors::ApplicationNameUndefined exception will be 
raised. Moved private rake tasks to the top level of the tree instead of 
buried in a private folder in lib/tasks. This will help prevent the 
accidental release of these tasks.
markbates (author)
Fri Mar 14 14:13:26 -0700 2008
commit  594c836d1551925dfb4eff7154e90a1d8daf705a
tree    fa66d7edc296aaa59611ec81bd7690088bf2c0b5
parent  623c735a7957012fc87d1c9c24238442f6842634
...
3
4
5
 
6
...
3
4
5
6
7
0
@@ -3,5 +3,6 @@
0
 require 'rake/rdoctask'
0
 
0
 require File.join("lib", "tasks", "rake_helpers.rb")
0
+Dir.glob(File.join("tasks", "**/*.rake")).each {|r| load r}
0
 Dir.glob(File.join("lib", "tasks", "**/*.rake")).each {|r| load r}
...
18
19
20
 
 
 
 
21
22
23
...
18
19
20
21
22
23
24
25
26
27
0
@@ -18,6 +18,10 @@
0
         end
0
       end
0
       
0
+ # Raised when an application doesn't declare it's application name for use in a distributed system.
0
+ class ApplicationNameUndefined < StandardError
0
+ end
0
+
0
     end # Errors
0
   end # Distributed
0
 end # Mack
...
1
2
3
 
 
4
5
6
7
8
9
10
11
12
13
14
15
...
1
2
 
3
4
5
 
 
 
 
 
 
 
 
6
7
8
0
@@ -1,15 +1,8 @@
0
 module Mack
0
   module Distributed
0
- module Routes
0
+ module Routes # :nodoc:
0
+ # Used to house the Mack::Distributed::Routes::Urls object for each distributed application.
0
       class UrlCache < Cachetastic::Caches::Base
0
-
0
- # class << self
0
- # def get(app_name)
0
- # super(app_name) do
0
- # set(app_name, Mack::Distributed::Routes::Urls.new)
0
- # end
0
- # end
0
- # end
0
         
0
       end # UrlCache
0
     end # Routes
...
1
2
3
 
 
4
5
6
...
1
2
3
4
5
6
7
8
0
@@ -1,6 +1,8 @@
0
 module Mack
0
   module Distributed
0
     module Routes
0
+ # A class used to house the Mack::Routes::Url module for distributed applications.
0
+ # Functionally this class does nothing, but since you can't cache a module, a class is needed.
0
       class Urls
0
       end # Urls
0
     end # Routes
...
10
11
12
 
13
14
15
...
10
11
12
13
14
15
16
0
@@ -10,6 +10,7 @@
0
       yield Mack::Routes::RouteMap.instance
0
       Mack::Routes::Urls.include_safely_into(Mack::Controller::Base, Mack::ViewBinder, Mack::Distributed::Routes::Urls, Test::Unit::TestCase)
0
       if app_config.mack.use_distributed_routes
0
+ raise Mack::Distributed::Errors::ApplicationNameUndefined.new if app_config.mack.distributed_app_name.nil?
0
         Mack::Distributed::Routes::UrlCache.set(app_config.mack.distributed_app_name.to_sym, Mack::Distributed::Routes::Urls.new)
0
       end
0
       # puts "Finished compiling routes: #{Mack::Routes::RouteMap.instance.routes_list.inspect}"
...
55
56
57
58
59
60
61
62
63
64
 
 
 
 
 
65
66
 
 
 
 
 
67
68
69
70
 
 
 
 
 
71
72
 
73
74
 
75
76
77
...
55
56
57
 
 
 
 
 
 
 
58
59
60
61
62
63
 
64
65
66
67
68
69
 
 
 
70
71
72
73
74
75
 
76
77
 
78
79
80
81
0
@@ -55,23 +55,27 @@
0
       # droute_url(:app_1, :home_page_url)
0
       # droute_url(:registration_app, :signup_url, {:from => :google})
0
       def droute_url(app_name, route_name, options = {})
0
- ivar_cache("droute_url_hash") do
0
- {}
0
- end
0
- d_urls = @droute_url_hash[app_name.to_sym]
0
- if d_urls.nil?
0
- d_urls = Mack::Distributed::Routes::UrlCache.get(app_name.to_sym)
0
- @droute_url_hash[app_name.to_sym] = d_urls
0
+ if app_config.mack.use_distributed_routes
0
+ ivar_cache("droute_url_hash") do
0
+ {}
0
+ end
0
+ d_urls = @droute_url_hash[app_name.to_sym]
0
           if d_urls.nil?
0
- raise Mack::Distributed::Errors::UnknownApplication.new(app_name)
0
+ d_urls = Mack::Distributed::Routes::UrlCache.get(app_name.to_sym)
0
+ @droute_url_hash[app_name.to_sym] = d_urls
0
+ if d_urls.nil?
0
+ raise Mack::Distributed::Errors::UnknownApplication.new(app_name)
0
+ end
0
           end
0
- end
0
- if d_urls.respond_to?(route_name)
0
- return d_urls.send(route_name, options)
0
+ if d_urls.respond_to?(route_name)
0
+ return d_urls.send(route_name, options)
0
+ else
0
+ raise Mack::Distributed::Errors::UnknownRouteName.new(app_name, route_name)
0
+ end
0
         else
0
- raise Mack::Distributed::Errors::UnknownRouteName.new(app_name, route_name)
0
+ return nil
0
         end
0
- end
0
+ end # droute_url
0
     
0
     end # Urls
0
   end # Routes
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,52 +1 @@
0
-class GemHelper # :nodoc:
0
- include Singleton
0
-
0
- attr_accessor :project
0
- attr_accessor :package
0
- attr_accessor :gem_name
0
- attr_accessor :version
0
-
0
- def initialize
0
- self.project = "magrathea"
0
- self.package = "mack"
0
- self.gem_name = GEM_NAME
0
- self.version = GEM_VERSION
0
- end
0
-
0
- def gem_name_with_version
0
- "#{self.gem_name}-#{self.version}"
0
- end
0
-
0
- def full_gem_name
0
- "#{self.gem_name_with_version}.gem"
0
- end
0
-
0
- def release
0
- begin
0
- rf = RubyForge.new
0
- rf.login
0
- begin
0
- rf.add_release(self.project, self.package, self.version, File.join("pkg", full_gem_name))
0
- rescue Exception => e
0
- if e.message.match("Invalid package_id") || e.message.match("no <package_id> configured for")
0
- puts "You need to create the package!"
0
- rf.create_package(self.project, self.package)
0
- rf.add_release(self.project, self.package, self.version, File.join("pkg", full_gem_name))
0
- else
0
- raise e
0
- end
0
- end
0
- rescue Exception => e
0
- puts e
0
- end
0
- end
0
-
0
- def install
0
- `sudo gem install #{File.join("pkg", full_gem_name)}`
0
- # require 'rubygems'
0
- # Gem.manage_gems
0
- # Gem::GemRunner.new.run(["install", File.join("pkg", full_gem_name)])
0
- end
0
-
0
-end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,89 +1 @@
0
-require 'rake'
0
-require 'rake/gempackagetask'
0
-require 'rake/clean'
0
-require 'rake/testtask'
0
-require 'find'
0
-require 'fileutils'
0
-
0
-require 'rubyforge'
0
-require 'rubygems'
0
-require 'rubygems/gem_runner'
0
-require 'singleton'
0
-
0
-GEM_NAME = "mack"
0
-GEM_VERSION = "0.3.0"
0
-
0
-require 'lib/tasks/private/gem_helper'
0
-
0
-namespace :gem do
0
-
0
- namespace :package do
0
-
0
- desc "Package up the mack gem."
0
- task :mack do |t|
0
- pwd = FileUtils.pwd
0
- gh = GemHelper.instance
0
- FileUtils.rm_rf("#{pwd}/pkg", :verbose => true)
0
- gem_spec = Gem::Specification.new do |s|
0
- s.name = gh.gem_name
0
- s.version = gh.version
0
- s.summary = gh.gem_name
0
- s.description = %{#{gh.gem_name} was developed by: markbates}
0
- s.author = "markbates"
0
- s.email = "mark@mackframework.com"
0
- s.homepage = "http://www.mackframework.com"
0
- s.has_rdoc = true
0
- s.extra_rdoc_files = ["README", "CHANGELOG"]
0
- s.files = FileList["README", "**/*.*"].exclude("pkg/").exclude("test/").exclude("tasks/private").exclude("doc")
0
- s.require_paths << '.'
0
- s.require_paths << 'bin'
0
- s.require_paths << 'lib'
0
-
0
- s.bindir = "bin"
0
- s.executables << "mack"
0
-
0
- s.rdoc_options << '--title' << 'Mack' << '--main' << 'README' << '--line-numbers' << "--inline-source"
0
-
0
- s.add_dependency("rack", "0.3.0")
0
- s.add_dependency("ruby_extensions", "1.0.11")
0
- s.add_dependency("application_configuration", "1.2.1")
0
- s.add_dependency("cachetastic", "1.4.0")
0
- s.add_dependency("log4r", "1.0.5")
0
- s.add_dependency("thin", "0.7.0")
0
-
0
- s.rubyforge_project = gh.project
0
- end
0
- Rake::GemPackageTask.new(gem_spec) do |pkg|
0
- pkg.package_dir = "#{pwd}/pkg"
0
- pkg.need_zip = false
0
- pkg.need_tar = false
0
- end
0
- Rake::Task["package"].invoke
0
- end
0
-
0
- end
0
-
0
- namespace :install do
0
-
0
- desc "Package up and install the mack gem."
0
- task :mack => "gem:package:mack" do |t|
0
- GemHelper.instance.install
0
- end
0
-
0
- end
0
-
0
- namespace :release do
0
-
0
- desc "Package up, install, and release the mack gem."
0
- task :mack => ["gem:install:mack"] do |t|
0
- GemHelper.instance.release
0
- end
0
-
0
- end
0
-
0
-end
0
-
0
-alias_task :pack, "gem:package:mack"
0
-alias_task :install, "gem:install:mack"
0
-alias_task :release, "gem:release:mack"
...
1
2
3
4
5
6
7
8
9
10
11
12
...
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,13 +1 @@
0
-Rake::RDocTask.new do |rd|
0
- rd.main = "README"
0
- files = Dir.glob("**/*.rb")
0
- files = files.collect {|f| f unless f.match("test/") || f.match("doc/") || f.match("private/") }.compact
0
- files << "README"
0
- files << "CHANGELOG"
0
- rd.rdoc_files = files
0
- rd.rdoc_dir = "doc"
0
- rd.options << "--line-numbers"
0
- rd.options << "--inline-source"
0
- rd.title = "Mack Framework"
0
-end
...
4
5
6
 
 
 
 
 
 
7
8
9
...
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -4,6 +4,12 @@
0
   
0
   module TestHelpers
0
     
0
+ def temp_app_config(options = {})
0
+ app_config.load_hash(options, String.randomize)
0
+ yield
0
+ app_config.revert
0
+ end
0
+
0
     def remote_test
0
       if (app_config.run_remote_tests)
0
         yield
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
0
@@ -1 +1,52 @@
0
+class GemHelper # :nodoc:
0
+ include Singleton
0
+
0
+ attr_accessor :project
0
+ attr_accessor :package
0
+ attr_accessor :gem_name
0
+ attr_accessor :version
0
+
0
+ def initialize
0
+ self.project = "magrathea"
0
+ self.package = "mack"
0
+ self.gem_name = GEM_NAME
0
+ self.version = GEM_VERSION
0
+ end
0
+
0
+ def gem_name_with_version
0
+ "#{self.gem_name}-#{self.version}"
0
+ end
0
+
0
+ def full_gem_name
0
+ "#{self.gem_name_with_version}.gem"
0
+ end
0
+
0
+ def release
0
+ begin
0
+ rf = RubyForge.new
0
+ rf.login
0
+ begin
0
+ rf.add_release(self.project, self.package, self.version, File.join("pkg", full_gem_name))
0
+ rescue Exception => e
0
+ if e.message.match("Invalid package_id") || e.message.match("no <package_id> configured for")
0
+ puts "You need to create the package!"
0
+ rf.create_package(self.project, self.package)
0
+ rf.add_release(self.project, self.package, self.version, File.join("pkg", full_gem_name))
0
+ else
0
+ raise e
0
+ end
0
+ end
0
+ rescue Exception => e
0
+ puts e
0
+ end
0
+ end
0
+
0
+ def install
0
+ `sudo gem install #{File.join("pkg", full_gem_name)}`
0
+ # require 'rubygems'
0
+ # Gem.manage_gems
0
+ # Gem::GemRunner.new.run(["install", File.join("pkg", full_gem_name)])
0
+ end
0
+
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
0
@@ -1 +1,89 @@
0
+require 'rake'
0
+require 'rake/gempackagetask'
0
+require 'rake/clean'
0
+require 'rake/testtask'
0
+require 'find'
0
+require 'fileutils'
0
+
0
+require 'rubyforge'
0
+require 'rubygems'
0
+require 'rubygems/gem_runner'
0
+require 'singleton'
0
+
0
+GEM_NAME = "mack"
0
+GEM_VERSION = "0.3.0"
0
+
0
+require 'tasks/gem_helper'
0
+
0
+namespace :gem do
0
+
0
+ namespace :package do
0
+
0
+ desc "Package up the mack gem."
0
+ task :mack do |t|
0
+ pwd = FileUtils.pwd
0
+ gh = GemHelper.instance
0
+ FileUtils.rm_rf("#{pwd}/pkg", :verbose => true)
0
+ gem_spec = Gem::Specification.new do |s|
0
+ s.name = gh.gem_name
0
+ s.version = gh.version
0
+ s.summary = gh.gem_name
0
+ s.description = %{#{gh.gem_name} was developed by: markbates}
0
+ s.author = "markbates"
0
+ s.email = "mark@mackframework.com"
0
+ s.homepage = "http://www.mackframework.com"
0
+ s.has_rdoc = true
0
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
0
+ s.files = FileList["README", "**/*.*"].exclude("pkg/").exclude("test/").exclude("tasks/private").exclude("doc")
0
+ s.require_paths << '.'
0
+ s.require_paths << 'bin'
0
+ s.require_paths << 'lib'
0
+
0
+ s.bindir = "bin"
0
+ s.executables << "mack"
0
+
0
+ s.rdoc_options << '--title' << 'Mack' << '--main' << 'README' << '--line-numbers' << "--inline-source"
0
+
0
+ s.add_dependency("rack", "0.3.0")
0
+ s.add_dependency("ruby_extensions", "1.0.11")
0
+ s.add_dependency("application_configuration", "1.2.1")
0
+ s.add_dependency("cachetastic", "1.4.0")
0
+ s.add_dependency("log4r", "1.0.5")
0
+ s.add_dependency("thin", "0.7.0")
0
+
0
+ s.rubyforge_project = gh.project
0
+ end
0
+ Rake::GemPackageTask.new(gem_spec) do |pkg|
0
+ pkg.package_dir = "#{pwd}/pkg"
0
+ pkg.need_zip = false
0
+ pkg.need_tar = false
0
+ end
0
+ Rake::Task["package"].invoke
0
+ end
0
+
0
+ end
0
+
0
+ namespace :install do
0
+
0
+ desc "Package up and install the mack gem."
0
+ task :mack => "gem:package:mack" do |t|
0
+ GemHelper.instance.install
0
+ end
0
+
0
+ end
0
+
0
+ namespace :release do
0
+
0
+ desc "Package up, install, and release the mack gem."
0
+ task :mack => ["gem:install:mack"] do |t|
0
+ GemHelper.instance.release
0
+ end
0
+
0
+ end
0
+
0
+end
0
+
0
+alias_task :pack, "gem:package:mack"
0
+alias_task :install, "gem:install:mack"
0
+alias_task :release, "gem:release:mack"
...
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -1 +1,13 @@
0
+Rake::RDocTask.new do |rd|
0
+ rd.main = "README"
0
+ files = Dir.glob("**/*.rb")
0
+ files = files.collect {|f| f unless f.match("test/") || f.match("doc/") || f.match("private/") }.compact
0
+ files << "README"
0
+ files << "CHANGELOG"
0
+ rd.rdoc_files = files
0
+ rd.rdoc_dir = "doc"
0
+ rd.options << "--line-numbers"
0
+ rd.options << "--inline-source"
0
+ rd.title = "Mack Framework"
0
+end
...
17
18
19
20
 
21
22
23
...
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
53
54
55
...
17
18
19
 
20
21
22
23
...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
0
@@ -17,7 +17,7 @@
0
       sleep(1)
0
     end
0
     app_config.load_hash({"mack::use_distributed_routes" => true, "mack::distributed_app_name" => :known_app}, :distributed_route_test)
0
- app_config.reload
0
+ # app_config.reload
0
     Mack::Routes.build do |r| # force the routes to go the DRb server
0
       r.known "/my_known_app/my_known_url", :controller => :foo, :action => :bar
0
       r.known_w_opts "/my_known_app/my_known_url_w_opts/:id", :controller => :foo, :action => :bar
0
@@ -50,6 +50,18 @@
0
   
0
   def test_droute_url_with_options
0
     assert_equal "/my_known_app/my_known_url_w_opts/1", droute_url(:known_app, :known_w_opts_url, :id => 1)
0
+ end
0
+
0
+ def test_nil_app_when_registering
0
+ temp_app_config("mack::distributed_app_name" => nil) do
0
+ assert_raise(Mack::Distributed::Errors::ApplicationNameUndefined) { Mack::Routes.build {|r|} }
0
+ end
0
+ end
0
+
0
+ def test_using_droute_url_when_not_configured_to_do_so
0
+ temp_app_config("mack::use_distributed_routes" => false) do
0
+ assert_equal nil, droute_url(:known_app, :known_url)
0
+ end
0
   end
0
   
0
 end

Comments

    No one has commented yet.