mack 0.7.0.1 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/CHANGELOG +34 -0
  2. data/README +6 -13
  3. data/bin/env_handler.rb +10 -0
  4. data/bin/gem_load_path.rb +25 -0
  5. data/bin/mack +1 -0
  6. data/bin/mackery +22 -0
  7. data/bin/mackery-console +16 -0
  8. data/bin/mackery-server +41 -0
  9. data/lib/mack.rb +7 -1
  10. data/lib/mack/controller/controller.rb +5 -4
  11. data/lib/mack/controller/request.rb +19 -1
  12. data/lib/mack/errors/errors.rb +8 -8
  13. data/lib/mack/generators/controller_generator/controller_generator.rb +1 -1
  14. data/lib/mack/generators/mack_application_generator/templates/app/views/layouts/application.html.erb.template +1 -2
  15. data/lib/mack/generators/mack_application_generator/templates/config/app_config/default.yml.template +2 -0
  16. data/lib/mack/generators/mack_application_generator/templates/config/database.yml.template +6 -6
  17. data/lib/mack/generators/passenger_generator/passenger_generator.rb +2 -0
  18. data/lib/mack/generators/passenger_generator/templates/config.ru.template +5 -0
  19. data/lib/mack/generators/passenger_generator/templates/tmp/README.template +2 -0
  20. data/lib/mack/initialization/application.rb +39 -36
  21. data/lib/mack/initialization/boot_loader.rb +174 -0
  22. data/lib/mack/initialization/configuration.rb +83 -95
  23. data/lib/mack/initialization/console.rb +11 -0
  24. data/lib/mack/initialization/environment.rb +16 -0
  25. data/lib/mack/initialization/helpers.rb +26 -24
  26. data/lib/mack/initialization/logging.rb +81 -81
  27. data/lib/mack/initialization/plugins.rb +14 -11
  28. data/lib/mack/initialization/server/simple_server.rb +3 -3
  29. data/lib/mack/rendering/type/base.rb +1 -1
  30. data/lib/mack/rendering/type/layout.rb +1 -1
  31. data/lib/mack/rendering/type/partial.rb +1 -1
  32. data/lib/mack/rendering/type/public.rb +1 -1
  33. data/lib/mack/rendering/type/template.rb +1 -1
  34. data/lib/mack/runner.rb +2 -2
  35. data/lib/mack/runner_helpers/session.rb +3 -3
  36. data/lib/mack/sessions/cookie_session_store.rb +44 -0
  37. data/lib/mack/{controller → sessions}/session.rb +0 -0
  38. data/lib/mack/sessions/session_store_base.rb +62 -0
  39. data/lib/mack/sessions/test_session_store.rb +38 -0
  40. data/lib/mack/tasks/mack_server_tasks.rake +8 -21
  41. data/lib/mack/tasks/mack_tasks.rake +33 -6
  42. data/lib/mack/tasks/rake_rules.rake +8 -0
  43. data/lib/mack/tasks/test_tasks.rake +39 -15
  44. data/lib/mack/testing/helpers.rb +6 -39
  45. data/lib/mack/utils/content_length_handler.rb +45 -0
  46. data/lib/mack/utils/forgery_detector.rb +152 -0
  47. data/lib/mack/utils/gem_manager.rb +22 -1
  48. data/lib/mack/utils/paths.rb +154 -0
  49. data/lib/mack/utils/server.rb +8 -6
  50. data/lib/mack/version.rb +1 -1
  51. data/lib/mack/view_helpers/asset_helpers.rb +50 -0
  52. data/lib/mack/view_helpers/form_helpers.rb +52 -6
  53. data/lib/mack/view_helpers/link_helpers.rb +6 -3
  54. data/lib/mack_app.rb +12 -14
  55. data/lib/mack_core.rb +35 -14
  56. data/lib/mack_tasks.rb +35 -20
  57. metadata +23 -27
  58. data/lib/mack/tasks/cachetastic_tasks.rake +0 -58
@@ -1,113 +1,113 @@
1
- #--
2
- # Configure logging
3
- #++
4
- require File.join(File.dirname(__FILE__), "..", "utils", "ansi", "ansi_color")
5
- module Mack
1
+ boot_load(:logging, :configuration) do
2
+ require 'log4r'
3
+ require File.join(File.dirname(__FILE__), "..", "utils", "ansi", "ansi_color")
4
+ module Mack
6
5
 
7
- def self.logger
8
- $mack_default_logger
9
- end
10
-
11
- def self.logger=(log)
12
- $mack_default_logger = log
13
- end
6
+ def self.logger
7
+ $mack_default_logger
8
+ end
14
9
 
15
- def self.reset_logger!
16
- log_directory = app_config.log_root || File.join(Mack.root, "log")
17
- begin
18
- FileUtils.mkdir_p(log_directory)
19
- rescue Exception => e
10
+ def self.logger=(log)
11
+ $mack_default_logger = log
20
12
  end
13
+
14
+ def self.reset_logger!
15
+ log_directory = app_config.log_root || Mack::Paths.log
16
+ begin
17
+ FileUtils.mkdir_p(log_directory)
18
+ rescue Exception => e
19
+ end
21
20
 
22
- Mack.logger = Log4r::Logger.new('')
23
- Mack.logger.level = Module.instance_eval("Log4r::#{(app_config.log_level || :info).to_s.upcase}")
21
+ Mack.logger = Log4r::Logger.new('')
22
+ Mack.logger.level = Module.instance_eval("Log4r::#{(app_config.log_level || :info).to_s.upcase}")
24
23
 
25
- format = Log4r::PatternFormatter.new(:pattern => "%l:\t[%d]\t%M")
24
+ format = Log4r::PatternFormatter.new(:pattern => "%l:\t[%d]\t%M")
26
25
 
27
- if Mack.env == "development"
28
- # console:
29
- Mack.logger.add(Log4r::StdoutOutputter.new('console', :formatter => format))
30
- end
26
+ if Mack.env == "development"
27
+ # console:
28
+ Mack.logger.add(Log4r::StdoutOutputter.new('console', :formatter => format))
29
+ end
31
30
 
32
- # file:
33
- Mack.logger.add(Log4r::FileOutputter.new('fileOutputter', :filename => File.join(log_directory, "#{Mack.env}.log"), :trunc => false, :formatter => format))
34
- end
31
+ # file:
32
+ Mack.logger.add(Log4r::FileOutputter.new('fileOutputter', :filename => File.join(log_directory, "#{Mack.env}.log"), :trunc => false, :formatter => format))
33
+ end
35
34
 
36
- end
35
+ end
37
36
 
38
- unless Mack.logger
39
- module Log4r # :nodoc:
40
- class IOOutputter # :nodoc:
37
+ unless Mack.logger
38
+ module Log4r # :nodoc:
39
+ class IOOutputter # :nodoc:
41
40
 
42
- # let's not do this more than once. :)
43
- unless Log4r::IOOutputter.private_instance_methods.include?("old_write")
41
+ # let's not do this more than once. :)
42
+ unless Log4r::IOOutputter.private_instance_methods.include?("old_write")
44
43
 
45
- alias_method :old_write, :write
44
+ alias_method :old_write, :write
46
45
 
47
- def write(data)
48
- case data
49
- when /^(DEBUG:|INFO:|WARN:|ERROR:|FATAL:)\s\[.*\]\s(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP)/
50
- old_write(Mack::Utils::Ansi::Color.wrap(app_config.log.db_color, data))
51
- else
52
- level = data.match(/^\w+/).to_s
53
- color = app_config.log.send("#{level.downcase}_color")
54
- if color
55
- old_write(Mack::Utils::Ansi::Color.wrap(color, data))
46
+ def write(data)
47
+ case data
48
+ when /^(DEBUG:|INFO:|WARN:|ERROR:|FATAL:)\s\[.*\]\s(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP)/
49
+ old_write(Mack::Utils::Ansi::Color.wrap(app_config.log.db_color, data))
56
50
  else
57
- old_write(data)
51
+ level = data.match(/^\w+/).to_s
52
+ color = app_config.log.send("#{level.downcase}_color")
53
+ if color
54
+ old_write(Mack::Utils::Ansi::Color.wrap(color, data))
55
+ else
56
+ old_write(data)
57
+ end
58
58
  end
59
59
  end
60
- end
61
60
 
62
- end
61
+ end
63
62
 
64
- end # IOOutputter
65
- end # Log4r
63
+ end # IOOutputter
64
+ end # Log4r
66
65
 
67
- Mack.reset_logger!
68
- end
66
+ Mack.reset_logger!
67
+ end
69
68
 
70
- module Mack
71
- module Logging # :nodoc:
72
- # Used to house a list of filters for parameter logging. The initial list
73
- # includes password and password_confirmation
74
- class Filter
75
- include Singleton
69
+ module Mack
70
+ module Logging # :nodoc:
71
+ # Used to house a list of filters for parameter logging. The initial list
72
+ # includes password and password_confirmation
73
+ class Filter
74
+ include Singleton
76
75
 
77
- # The list of parameters you want filtered for logging.
78
- attr_reader :list
79
-
80
- def initialize
81
- @list = [:password, :password_confirmation]
82
- end
76
+ # The list of parameters you want filtered for logging.
77
+ attr_reader :list
83
78
 
84
- # Adds 'n' number of parameter names to the list
85
- def add(*args)
86
- @list << args
87
- @list.flatten!
88
- end
79
+ def initialize
80
+ @list = [:password, :password_confirmation]
81
+ end
89
82
 
90
- # Removes 'n' number of parameter names from the list
91
- def remove(*args)
92
- @list.delete_values(*args)
93
- end
83
+ # Adds 'n' number of parameter names to the list
84
+ def add(*args)
85
+ @list << args
86
+ @list.flatten!
87
+ end
94
88
 
95
- class << self
96
-
89
+ # Removes 'n' number of parameter names from the list
97
90
  def remove(*args)
98
- Mack::Logging::Filter.instance.remove(*args)
91
+ @list.delete_values(*args)
99
92
  end
93
+
94
+ class << self
100
95
 
101
- def add(*args)
102
- Mack::Logging::Filter.instance.add(*args)
103
- end
96
+ def remove(*args)
97
+ Mack::Logging::Filter.instance.remove(*args)
98
+ end
104
99
 
105
- def list
106
- Mack::Logging::Filter.instance.list
107
- end
100
+ def add(*args)
101
+ Mack::Logging::Filter.instance.add(*args)
102
+ end
108
103
 
109
- end
104
+ def list
105
+ Mack::Logging::Filter.instance.list
106
+ end
107
+
108
+ end
110
109
 
110
+ end
111
111
  end
112
112
  end
113
113
  end
@@ -1,13 +1,16 @@
1
- plugins = [] # a list of all plugins
2
- Dir.glob(File.join(Mack.root, "vendor", "plugins", "*")).each do |d|
3
- plugins << d
4
- $: << File.join(d, "lib") # add the lib for this plugin to the global load path
5
- end
6
- plugins.sort.each do |plug|
7
- begin
8
- require File.join(plug, "init.rb") # load the init.rb for each plugin.
9
- rescue Exception => e
10
- puts e.message
1
+ boot_load(:plugins, :initializers) do
2
+ Mack.logger.debug "Initializing plugins..." unless app_config.log.disable_initialization_logging
3
+ plugins = [] # a list of all plugins
4
+ Dir.glob(Mack::Paths.plugins("*")).each do |d|
5
+ plugins << d
6
+ $: << File.join(d, "lib") # add the lib for this plugin to the global load path
7
+ end
8
+ plugins.sort.each do |plug|
9
+ begin
10
+ require File.join(plug, "init.rb") # load the init.rb for each plugin.
11
+ rescue Exception => e
12
+ puts e.message
13
+ end
14
+ $:.delete(File.join(plug, "lib")) # remove the plugins lib directory from the global load path.
11
15
  end
12
- $:.delete(File.join(plug, "lib")) # remove the plugins lib directory from the global load path.
13
16
  end
@@ -8,9 +8,9 @@ module Mack
8
8
  class << self
9
9
 
10
10
  def run(options)
11
- r = "Rack::Handler::#{options.handler.camelcase}"
12
- puts "Starting app using: #{r} in #{options.environment} mode on port: #{options.port}"
13
- eval(r).run(Mack::Utils::Server.build_app, :Port => options.port)
11
+ r = "Rack::Handler::#{options[:handler].camelcase}"
12
+ puts "Starting app using: #{r} in #{options[:environment]} mode on port: #{options[:port]}"
13
+ eval(r).run(Mack::Utils::Server.build_app, :Port => options[:port])
14
14
  end
15
15
 
16
16
  end
@@ -49,7 +49,7 @@ module Mack
49
49
  # Returns the directory path for the current controller.
50
50
  def controller_view_path
51
51
  ivar_cache do
52
- File.join(Mack.root, "app", "views", self.controller.controller_name)
52
+ Mack::Paths.views(self.controller.controller_name)
53
53
  end
54
54
  end
55
55
 
@@ -12,7 +12,7 @@ module Mack
12
12
  # Example:
13
13
  # app/views/layouts/application.html.erb
14
14
  def render
15
- l_file = File.join(Mack.root, "app", "views", 'layouts', "#{self.options[:layout]}.#{self.options[:format]}")
15
+ l_file = Mack::Paths.layouts("#{self.options[:layout]}.#{self.options[:format]}")
16
16
  begin
17
17
  render_file(l_file, :layout)
18
18
  rescue Mack::Errors::ResourceNotFound => e
@@ -24,7 +24,7 @@ module Mack
24
24
  else
25
25
  # it's elsewhere
26
26
  parts[parts.size - 1] = "_" << parts.last
27
- partial = File.join(Mack.root, "app", "views", parts)
27
+ partial = Mack::Paths.views(parts)
28
28
  end
29
29
  partial = "#{partial}.#{self.options[:format]}"
30
30
  render_file(partial, :partial)
@@ -13,7 +13,7 @@ module Mack
13
13
  if File.extname(p_file).blank?
14
14
  p_file = "#{p_file}.#{self.options[:format]}"
15
15
  end
16
- find_file(Mack.root, "public", p_file) do |f|
16
+ find_file(Mack::Paths.public(p_file)) do |f|
17
17
  return File.open(f).read
18
18
  end
19
19
  raise Mack::Errors::ResourceNotFound.new(p_file)
@@ -13,7 +13,7 @@ module Mack
13
13
  # Example:
14
14
  # <%= render(:template, "users/show") %> # => app/views/users/show.html.erb
15
15
  def render
16
- t_file = File.join(Mack.root, "app", "views", "#{self.render_value}.#{self.options[:format]}")
16
+ t_file = Mack::Paths.views("#{self.render_value}.#{self.options[:format]}")
17
17
  render_file(t_file, :template)
18
18
  end
19
19
 
@@ -100,8 +100,8 @@ module Mack
100
100
  if File.extname(env["PATH_INFO"]).blank?
101
101
  env["PATH_INFO"] << ".html"
102
102
  end
103
- if File.exists?(File.join(Mack.root, "public", env["PATH_INFO"]))
104
- return Rack::File.new(File.join(Mack.root, "public")).call(env)
103
+ if File.exists?(Mack::Paths.public(env["PATH_INFO"]))
104
+ return Rack::File.new(Mack::Paths.public).call(env)
105
105
  else
106
106
  raise exception
107
107
  end
@@ -11,7 +11,7 @@ module Mack
11
11
  unless self.sess_id
12
12
  self.sess_id = create_new_session(request, response, cookies)
13
13
  else
14
- sess = Cachetastic::Caches::MackSessionCache.get(self.sess_id)
14
+ sess = Mack::SessionStore.get(self.sess_id, request, response, cookies)
15
15
  if sess
16
16
  request.session = sess
17
17
  else
@@ -26,7 +26,7 @@ module Mack
26
26
  unless response.redirection?
27
27
  request.session.delete(:tell)
28
28
  end
29
- Cachetastic::Caches::MackSessionCache.set(request.session.id, request.session) if app_config.mack.use_sessions
29
+ Mack::SessionStore.set(request.session.id, request, response, cookies) if app_config.mack.use_sessions
30
30
  end
31
31
 
32
32
  private
@@ -39,7 +39,7 @@ module Mack
39
39
  cookies[app_config.mack.session_id] = {:value => id, :expires => nil}
40
40
  sess = Mack::Session.new(id)
41
41
  request.session = sess
42
- Cachetastic::Caches::MackSessionCache.set(id, sess)
42
+ Mack::SessionStore.set(request.session.id, request, response, cookies)
43
43
  id
44
44
  end
45
45
 
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), "session_store_base")
2
+ module Mack
3
+ module SessionStore
4
+ # Stores session information in the user's cookie.
5
+ # The session information is encrypted using the mack-encryption library.
6
+ # This is the default session store for Mack applications.
7
+ # To set the expiry time for this session store use the following app_config setting:
8
+ # cookie_session_store::expiry_time: <%= 4.hours %>
9
+ # It is recommend that you set the app_config setting 'default_secret_key' to
10
+ # something, otherwise it will generate a random one each time you start your application,
11
+ # which could make decrypting cookies a bit of a pain. :)
12
+ class Cookie < Mack::SessionStore::Base
13
+
14
+ class << self
15
+
16
+ # Returns a decrypted session from the cookie or nil.
17
+ def get(id, request, response, cookies)
18
+ c = cookies[id]
19
+ return nil if c.nil?
20
+ begin
21
+ sess = YAML.load(c.decrypt)
22
+ return sess
23
+ rescue Exception => e
24
+ # The cookie was bad, delete it and start a new session.
25
+ c.delete(id)
26
+ return nil
27
+ end
28
+ end
29
+
30
+ # Encrypts the session and places it into the cookie.
31
+ def set(id, request, response, cookies)
32
+ cookies[id] = {:value => YAML.dump(request.session).encrypt, :expires => (Time.now + app_config.cookie_session_store.expiry_time)}
33
+ end
34
+
35
+ # Deletes the cookie.
36
+ def expire(id, request, response, cookies)
37
+ cookies.delete(id)
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,62 @@
1
+ module Mack
2
+ module SessionStore
3
+
4
+ class << self
5
+
6
+ def store # :nodoc:
7
+ ivar_cache do
8
+ "Mack::SessionStore::#{app_config.mack.session_store.camelcase}".constantize
9
+ end
10
+ end
11
+
12
+ # Calls the get method on the specified session store.
13
+ def get(*args)
14
+ self.store.get(*args)
15
+ end
16
+
17
+ # Calls the set method on the specified session store.
18
+ def set(*args)
19
+ self.store.set(*args)
20
+ end
21
+
22
+ # Calls the expire method on the specified session store.
23
+ def expire(*args)
24
+ self.store.expire(*args)
25
+ end
26
+
27
+ # Calls the expire_all method on the specified session store.
28
+ def expire_all(*args)
29
+ self.store.expire_all(*args)
30
+ end
31
+
32
+ end
33
+
34
+ class Base
35
+
36
+ class << self
37
+
38
+ # Needs to be defined by the subclass. Raises NoMethodError.
39
+ def get(id, request, response, cookies)
40
+ raise NoMethodError.new("get")
41
+ end
42
+
43
+ # Needs to be defined by the subclass. Raises NoMethodError.
44
+ def set(id, request, response, cookies)
45
+ raise NoMethodError.new("set")
46
+ end
47
+
48
+ # Needs to be defined by the subclass. Raises NoMethodError.
49
+ def expire(id, request, response, cookies)
50
+ raise NoMethodError.new("expire")
51
+ end
52
+
53
+ # Needs to be defined by the subclass. Raises NoMethodError.
54
+ def expire_all(request, response, cookies)
55
+ raise NoMethodError.new("expire_all")
56
+ end
57
+
58
+ end
59
+
60
+ end # Base
61
+ end # SessionStore
62
+ end # Mack
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), "session_store_base")
2
+ module Mack
3
+ module SessionStore
4
+ # A simple Hash based session store for testing.
5
+ class Test < Mack::SessionStore::Base
6
+
7
+ class << self
8
+
9
+ def get(id, *args) # :nodoc:
10
+ store[id]
11
+ end
12
+
13
+ def set(id, request, *args) # :nodoc:
14
+ store[id] = request.session
15
+ end
16
+
17
+ def direct_set(id, session) # :nodoc:
18
+ store[id] = session
19
+ end
20
+
21
+ def expire(id, *args) # :nodoc:
22
+ store.delete(id)
23
+ end
24
+
25
+ def expire_all # :nodoc:
26
+ @store = {}
27
+ end
28
+
29
+ private
30
+ def store
31
+ @store ||= {}
32
+ end
33
+
34
+ end
35
+
36
+ end # Test
37
+ end # SessionStore
38
+ end # Mack