mack 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/README +43 -0
  2. data/bin/mack +60 -0
  3. data/bin/templates/Rakefile.template +6 -0
  4. data/bin/templates/app/controllers/default_controller.rb.template +7 -0
  5. data/bin/templates/app/helpers/application_helper.rb.template +2 -0
  6. data/bin/templates/app/views/default/index.html.erb.template +3 -0
  7. data/bin/templates/app/views/layouts/application.html.erb.template +15 -0
  8. data/bin/templates/config/app_config/default.yml.template +7 -0
  9. data/bin/templates/config/app_config/development.yml.template +0 -0
  10. data/bin/templates/config/app_config/production.yml.template +0 -0
  11. data/bin/templates/config/app_config/test.yml.template +0 -0
  12. data/bin/templates/config/boot.rb.template +6 -0
  13. data/bin/templates/config/database.yml.template +20 -0
  14. data/bin/templates/config/routes.rb.template +7 -0
  15. data/bin/templates/config/thin.ru.template +1 -0
  16. data/bin/templates/config/thin.yml.template +8 -0
  17. data/bin/templates/public/favicon.ico +0 -0
  18. data/bin/templates/public/stylesheets/scaffold.css.template +74 -0
  19. data/core_extensions/hash.rb +9 -0
  20. data/core_extensions/module.rb +29 -0
  21. data/core_extensions/nil.rb +8 -0
  22. data/core_extensions/object.rb +9 -0
  23. data/core_extensions/string.rb +28 -0
  24. data/errors/errors.rb +79 -0
  25. data/initialize/configuration.rb +99 -0
  26. data/initialize/configure_logging.rb +24 -0
  27. data/initialize/configure_orm_support.rb +23 -0
  28. data/initialize/console.rb +13 -0
  29. data/initialize/initializer.rb +88 -0
  30. data/initialize/server/simple_server.rb +21 -0
  31. data/lib/utils/html.rb +88 -0
  32. data/lib/utils/server.rb +27 -0
  33. data/mack.rb +124 -0
  34. data/mack_tasks.rb +16 -0
  35. data/routing/route_map.rb +268 -0
  36. data/routing/urls.rb +54 -0
  37. data/sea_level/controller_base.rb +293 -0
  38. data/sea_level/cookie_jar.rb +67 -0
  39. data/sea_level/filter.rb +63 -0
  40. data/sea_level/helpers/view_helpers/html_helpers.rb +33 -0
  41. data/sea_level/helpers/view_helpers/orm_helpers.rb +72 -0
  42. data/sea_level/request.rb +83 -0
  43. data/sea_level/response.rb +6 -0
  44. data/sea_level/session.rb +33 -0
  45. data/sea_level/view_binder.rb +101 -0
  46. data/tasks/cachetastic_tasks.rake +69 -0
  47. data/tasks/log_tasks.rake +9 -0
  48. data/tasks/mack_tasks.rake +15 -0
  49. data/tasks/rake_helpers.rb +24 -0
  50. data/tasks/rake_rules.rake +19 -0
  51. data/tasks/script_tasks.rake +44 -0
  52. data/tasks/test_tasks.rake +7 -0
  53. data/test_extensions/test_assertions.rb +47 -0
  54. data/test_extensions/test_helpers.rb +84 -0
  55. metadata +173 -0
@@ -0,0 +1,69 @@
1
+ require 'find'
2
+ namespace :cachetastic do
3
+
4
+ task :manipulate_caches => :environment do
5
+ cache_name = ENV['cache_name']
6
+ cache_name = cache_name.camelcase
7
+ action = ENV['cache_action']
8
+ running_time("#{cache_name}.#{action}") do
9
+ case cache_name
10
+ when "All"
11
+ puts "About to work on ALL caches!"
12
+ # force all caches to register themselves:
13
+ ["#{MACK_ROOT}/lib/caches"].each do |dir|
14
+ Find.find(dir) do |f|
15
+ # puts f
16
+ if FileTest.directory?(f) and !f.match(/.svn/)
17
+ else
18
+ if FileTest.file?(f)
19
+ m = f.match(/\/[a-zA-Z\-_]*.rb$/)
20
+ if m
21
+ model = m.to_s
22
+ unless model.match("test_")
23
+ x = model.gsub('/', '').gsub('.rb', '')
24
+ # puts "x: #{x}"
25
+ require x
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ caches = Cachetastic::Caches::Base.all_registered_caches.dup
33
+ caches.sort!
34
+ caches.reverse!
35
+ caches.each do |cache|
36
+ do_work(cache, action)
37
+ end
38
+ else
39
+ do_work(cache_name, action)
40
+ end
41
+ end
42
+ end
43
+
44
+ def do_work(cache, action)
45
+ begin
46
+ puts "Calling: #{cache}.#{action}"
47
+ cache.constantize.send(action)
48
+ rescue MethodNotImplemented => e
49
+ msg = "Cachetastic.rake Warning: cache #{cache} does not implement #{action}. This is probably an error."
50
+ puts msg
51
+ MACK_DEFAULT_LOGGER.warning(msg)
52
+ rescue NoMethodError => e
53
+ rescue Exception => e
54
+ raise e
55
+ end
56
+ end
57
+
58
+ namespace :page_cache do
59
+
60
+ desc "Expires the page cache."
61
+ task :expire_all => :environment do
62
+ running_time do("Cachetastic::Caches::PageCache.expire_all")
63
+ Cachetastic::Caches::PageCache.expire_all
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,9 @@
1
+ namespace :log do
2
+ desc "Truncates all *.log files in log/ to zero bytes"
3
+ task :clear do
4
+ FileList["log/*.log"].each do |log_file|
5
+ f = File.open(log_file, "w")
6
+ f.close
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ desc "Loads the Mack environment. Default is development."
2
+ task :environment do
3
+ MACK_ENV = ENV["MACK_ENV"] ||= "development" unless Object.const_defined?("MACK_ENV")
4
+ MACK_ROOT = FileUtils.pwd unless Object.const_defined?("MACK_ROOT")
5
+ require File.join(MACK_ROOT, "config", "boot.rb")
6
+ end
7
+
8
+ desc "Loads an irb console allow you full access to the application w/o a browser."
9
+ task :console do
10
+ libs = []
11
+ libs << "-r irb/completion"
12
+ libs << "-r #{File.join(File.dirname(__FILE__), '..', 'mack')}"
13
+ libs << "-r #{File.join(File.dirname(__FILE__), '..', 'initialize', 'console')}"
14
+ exec "irb #{libs.join(" ")} --simple-prompt"
15
+ end
@@ -0,0 +1,24 @@
1
+ module Mack
2
+ module RakeHelpers
3
+
4
+ # Allows the aliasing and chaining of Rake tasks.
5
+ #
6
+ # Examples:
7
+ # alias_task :server, "log:clear", "script:server"
8
+ # alias_task "server:start", "log:clear", "script:server"
9
+ def alias_task(name, *args)
10
+ ts = [args].flatten
11
+ ts = ts.collect {|x| "'#{x}'"}.join(", ")
12
+ ts = "[#{ts}]"
13
+ n_task = %{
14
+ desc "Alias: #{name} => #{ts}"
15
+ task "#{name}" => #{ts} do |t|
16
+ end
17
+ }
18
+ eval(n_task)
19
+ end
20
+
21
+ end # RakeHelpers
22
+ end # Mack
23
+
24
+ self.send(:include, Mack::RakeHelpers)
@@ -0,0 +1,19 @@
1
+ rule /\#.*/ do |t|
2
+ env = t.name.match(/\#.*/).to_s.gsub("#", "")
3
+ Object::MACK_ENV = env
4
+ ENV["MACK_ENV"] = env
5
+ name = t.name.gsub("##{env}", "")
6
+ Rake::Task[name].invoke
7
+ end
8
+
9
+ rule /^cachetastic:/ do |t|
10
+ x = t.name.gsub("cachetastic:", '')
11
+ x = x.split(":")
12
+ cache_name = x.first
13
+ cache_action = x.last
14
+ puts "cache_name: #{cache_name}"
15
+ puts "cache_action: #{cache_action}"
16
+ ENV['cache_name'] = cache_name
17
+ ENV['cache_action'] = cache_action
18
+ Rake::Task["cachetastic:manipulate_caches"].invoke
19
+ end
@@ -0,0 +1,44 @@
1
+ namespace :server do
2
+
3
+ desc "Starts the webserver."
4
+ task :start do |t|
5
+
6
+ require 'rubygems'
7
+ require 'optparse'
8
+ require 'optparse/time'
9
+ require 'ostruct'
10
+ require 'fileutils'
11
+
12
+ d_handler = "WEBrick"
13
+ begin
14
+ require 'mongrel'
15
+ d_handler = "mongrel"
16
+ rescue Exception => e
17
+ end
18
+ begin
19
+ require 'thin'
20
+ d_handler = "thin"
21
+ rescue Exception => e
22
+ end
23
+
24
+ MACK_ROOT = FileUtils.pwd unless Object.const_defined?("MACK_ROOT")
25
+
26
+ options = OpenStruct.new
27
+ options.port = (ENV["PORT"] ||= "3000") # Does NOT work with Thin!! You must edit the thin.yml file!
28
+ options.handler = (ENV["HANDLER"] ||= d_handler)
29
+
30
+
31
+ require File.join(MACK_ROOT, "config", "boot.rb")
32
+
33
+ if options.handler == "thin"
34
+ # thin_opts = ["start", "-r", "config/thin.ru"]
35
+ thin_opts = ["start", "-C", "config/thin.yml"]
36
+ Thin::Runner.new(thin_opts.flatten).run!
37
+ else
38
+ Mack::SimpleServer.run(options)
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ alias_task :server, "log:clear", "server:start"
@@ -0,0 +1,7 @@
1
+ desc "Run test code."
2
+ Rake::TestTask.new(:default) do |t|
3
+ Rake::Task["log:clear"].invoke
4
+ t.libs << "test"
5
+ t.pattern = 'test/**/*_test.rb'
6
+ t.verbose = true
7
+ end
@@ -0,0 +1,47 @@
1
+ require 'test/unit'
2
+ module Mack
3
+
4
+ module TestAssertions
5
+
6
+ # Takes either a Symbol or a Fixnum and assert the response matches it.
7
+ # The symbols it will match are :success, :redirect, :not_found, :error.
8
+ # If a Fixnum is passed it will assert the response status equals that Fixnum
9
+ def assert_response(status)
10
+ if status.is_a?(Symbol)
11
+ case status
12
+ when :success
13
+ assert(responses.first.successful?)
14
+ when :redirect
15
+ assert(responses.first.redirect?)
16
+ when :not_found
17
+ assert(responses.first.not_found?)
18
+ when :error
19
+ assert(responses.first.server_error?)
20
+ else
21
+ assert(false)
22
+ end
23
+ elsif status.is_a?(Fixnum)
24
+ assert_equal(status, responses.first.status)
25
+ end
26
+ end
27
+
28
+ # Asserts that the request has been redirected to the specified url.
29
+ def assert_redirected_to(url)
30
+ assert_equal(url, responses.first.location)
31
+ end
32
+
33
+ # Asserts that the specified cookie has been set to the specified value.
34
+ def assert_cookie(name, value)
35
+ assert cookies[name.to_s]
36
+ end
37
+
38
+ # Asserts that there is no cookie set for the specified cookie
39
+ def assert_no_cookie(name)
40
+ assert !cookies[name.to_s]
41
+ end
42
+
43
+ end # TestAssertions
44
+
45
+ end # Mack
46
+
47
+ Test::Unit::TestCase.send(:include, Mack::TestAssertions)
@@ -0,0 +1,84 @@
1
+ require "test/unit"
2
+
3
+ module Mack
4
+
5
+ module TestHelpers
6
+
7
+ # Performs a 'get' request for the specified uri.
8
+ def get(uri, options = {})
9
+ build_response(request.get(uri, options))
10
+ end
11
+
12
+ # Performs a 'put' request for the specified uri.
13
+ def put(uri, options = {})
14
+ build_response(request.put(uri, options))
15
+ end
16
+
17
+ # Performs a 'post' request for the specified uri.
18
+ def post(uri, options = {})
19
+ opts = {}
20
+ options.each_pair do |k,v|
21
+ if v.is_a?(String)
22
+ opts[k] = Rack::Utils.escape(v)
23
+ elsif v.is_a?(Hash)
24
+ v.each_pair do |sk, sv|
25
+ opts["#{k}[#{sk}]"] = Rack::Utils.escape(sv)
26
+ end
27
+ else
28
+ opts[k] = v
29
+ end
30
+ end
31
+ build_response(request.post(uri, :input => opts.join("%s=%s", "&")))
32
+ end
33
+
34
+ # Performs a 'delete' request for the specified uri.
35
+ def delete(uri, options = {})
36
+ build_response(request.delete(uri, options))
37
+ end
38
+
39
+ # Returns a Rack::MockRequest. If there isn't one, a new one is created.
40
+ def request
41
+ @request ||= Rack::MockRequest.new(Rack::Recursive.new(Mack::Runner.new))
42
+ end
43
+
44
+ # Returns the last Rack::MockResponse that got generated by a call.
45
+ def response
46
+ responses.last
47
+ end
48
+
49
+ # Returns all the Rack::MockResponse objects that get generated by a call.
50
+ def responses
51
+ @responses
52
+ end
53
+
54
+ # Returns a Mack::Session from the request.
55
+ def session # :nodoc:
56
+ Cachetastic::Caches::MackSessionCache.get(cookies[app_config.mack.session_id])
57
+ end
58
+
59
+ # Returns a Hash of cookies from the response.
60
+ def cookies
61
+ cooks = {}
62
+ responses.each do |res|
63
+ res.original_headers["Set-Cookie"].each do |ck|
64
+ spt = ck.split("=")
65
+ cooks[spt.first] = spt.last
66
+ end
67
+ end
68
+ cooks
69
+ end
70
+
71
+ private
72
+ def build_response(res)
73
+ @responses = [res]
74
+ until res.successful?
75
+ res = request.get(res["Location"])
76
+ @responses << res
77
+ end
78
+ end
79
+
80
+ end # TestHelpers
81
+
82
+ end # Mack
83
+
84
+ Test::Unit::TestCase.send(:include, Mack::TestHelpers)
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - markbates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-26 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.0
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: ruby_extensions
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.0.10
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: application_configuration
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: cachetastic
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.3.0
50
+ version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: log4r
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.0.5
59
+ version:
60
+ - !ruby/object:Gem::Dependency
61
+ name: thin
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
67
+ version: 0.6.4
68
+ version:
69
+ description: "mack was developed by: markbates"
70
+ email: mark@markbates.com
71
+ executables:
72
+ - mack
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - README
77
+ files:
78
+ - README
79
+ - bin/templates/app/controllers/default_controller.rb.template
80
+ - bin/templates/app/helpers/application_helper.rb.template
81
+ - bin/templates/app/views/default/index.html.erb.template
82
+ - bin/templates/app/views/layouts/application.html.erb.template
83
+ - bin/templates/config/app_config/default.yml.template
84
+ - bin/templates/config/app_config/development.yml.template
85
+ - bin/templates/config/app_config/production.yml.template
86
+ - bin/templates/config/app_config/test.yml.template
87
+ - bin/templates/config/boot.rb.template
88
+ - bin/templates/config/database.yml.template
89
+ - bin/templates/config/routes.rb.template
90
+ - bin/templates/config/thin.ru.template
91
+ - bin/templates/config/thin.yml.template
92
+ - bin/templates/public/favicon.ico
93
+ - bin/templates/public/stylesheets/scaffold.css.template
94
+ - bin/templates/Rakefile.template
95
+ - core_extensions/hash.rb
96
+ - core_extensions/module.rb
97
+ - core_extensions/nil.rb
98
+ - core_extensions/object.rb
99
+ - core_extensions/string.rb
100
+ - errors/errors.rb
101
+ - initialize/configuration.rb
102
+ - initialize/configure_logging.rb
103
+ - initialize/configure_orm_support.rb
104
+ - initialize/console.rb
105
+ - initialize/initializer.rb
106
+ - initialize/server/simple_server.rb
107
+ - lib/utils/html.rb
108
+ - lib/utils/server.rb
109
+ - mack.rb
110
+ - mack_tasks.rb
111
+ - routing/route_map.rb
112
+ - routing/urls.rb
113
+ - sea_level/controller_base.rb
114
+ - sea_level/cookie_jar.rb
115
+ - sea_level/filter.rb
116
+ - sea_level/helpers/view_helpers/html_helpers.rb
117
+ - sea_level/helpers/view_helpers/orm_helpers.rb
118
+ - sea_level/request.rb
119
+ - sea_level/response.rb
120
+ - sea_level/session.rb
121
+ - sea_level/view_binder.rb
122
+ - tasks/cachetastic_tasks.rake
123
+ - tasks/log_tasks.rake
124
+ - tasks/mack_tasks.rake
125
+ - tasks/rake_helpers.rb
126
+ - tasks/rake_rules.rake
127
+ - tasks/script_tasks.rake
128
+ - tasks/test_tasks.rake
129
+ - test_extensions/test_assertions.rb
130
+ - test_extensions/test_helpers.rb
131
+ has_rdoc: true
132
+ homepage:
133
+ post_install_message:
134
+ rdoc_options:
135
+ - --title
136
+ - Mack
137
+ - --main
138
+ - README
139
+ - --line-numbers
140
+ - --inline-source
141
+ require_paths:
142
+ - lib
143
+ - .
144
+ - bin
145
+ - core_extensions
146
+ - errors
147
+ - initialize
148
+ - lib
149
+ - routing
150
+ - sea_level
151
+ - tasks
152
+ - test_extensions
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: "0"
158
+ version:
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: "0"
164
+ version:
165
+ requirements: []
166
+
167
+ rubyforge_project: magrathea
168
+ rubygems_version: 1.0.1
169
+ signing_key:
170
+ specification_version: 2
171
+ summary: mack
172
+ test_files: []
173
+