waves 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/bin/waves +4 -3
  2. data/doc/VERSION +1 -1
  3. data/lib/waves.rb +52 -40
  4. data/lib/{caches → waves/caches}/file.rb +3 -1
  5. data/lib/waves/caches/memcached.rb +56 -0
  6. data/lib/{caches → waves/caches}/simple.rb +6 -7
  7. data/lib/{caches → waves/caches}/synchronized.rb +15 -1
  8. data/lib/{commands → waves/commands}/console.rb +4 -4
  9. data/lib/{commands → waves/commands}/generate.rb +6 -5
  10. data/lib/{commands → waves/commands}/help.rb +0 -0
  11. data/lib/{commands → waves/commands}/server.rb +1 -1
  12. data/lib/{dispatchers → waves/dispatchers}/base.rb +17 -31
  13. data/lib/waves/dispatchers/default.rb +19 -0
  14. data/lib/{ext → waves/ext}/float.rb +0 -0
  15. data/lib/{ext → waves/ext}/hash.rb +0 -0
  16. data/lib/{ext → waves/ext}/integer.rb +16 -1
  17. data/lib/{ext → waves/ext}/kernel.rb +3 -7
  18. data/lib/{ext → waves/ext}/module.rb +3 -3
  19. data/lib/{ext → waves/ext}/object.rb +2 -0
  20. data/lib/waves/ext/string.rb +73 -0
  21. data/lib/{ext → waves/ext}/symbol.rb +0 -1
  22. data/lib/{ext → waves/ext}/tempfile.rb +0 -0
  23. data/lib/waves/ext/time.rb +5 -0
  24. data/lib/{foundations → waves/foundations}/classic.rb +9 -21
  25. data/lib/{foundations → waves/foundations}/compact.rb +15 -20
  26. data/lib/waves/foundations/rest.rb +311 -0
  27. data/lib/waves/helpers/basic.rb +13 -0
  28. data/lib/{helpers → waves/helpers}/doc_type.rb +3 -0
  29. data/lib/waves/helpers/form.rb +94 -0
  30. data/lib/waves/helpers/formatting.rb +14 -0
  31. data/lib/waves/layers/mvc.rb +65 -0
  32. data/lib/{layers → waves/layers}/mvc/controllers.rb +0 -0
  33. data/lib/{layers → waves/layers}/mvc/extensions.rb +23 -11
  34. data/lib/{layers → waves/layers}/orm/migration.rb +0 -0
  35. data/lib/{layers → waves/layers}/orm/providers/active_record.rb +2 -5
  36. data/lib/{layers → waves/layers}/orm/providers/active_record/migrations/empty.rb.erb +0 -0
  37. data/lib/{layers → waves/layers}/orm/providers/active_record/tasks/generate.rb +1 -1
  38. data/lib/{layers → waves/layers}/orm/providers/active_record/tasks/schema.rb +1 -1
  39. data/lib/{layers → waves/layers}/orm/providers/data_mapper.rb +0 -0
  40. data/lib/{layers → waves/layers}/orm/providers/filebase.rb +0 -0
  41. data/lib/{layers → waves/layers}/orm/providers/sequel.rb +28 -29
  42. data/lib/{layers → waves/layers}/orm/providers/sequel/migrations/empty.rb.erb +0 -0
  43. data/lib/{layers → waves/layers}/orm/providers/sequel/tasks/generate.rb +1 -1
  44. data/lib/{layers → waves/layers}/orm/providers/sequel/tasks/schema.rb +2 -0
  45. data/lib/waves/layers/rack/rack_cache.rb +32 -0
  46. data/lib/waves/layers/renderers/erubis.rb +52 -0
  47. data/lib/waves/layers/renderers/haml.rb +67 -0
  48. data/lib/waves/layers/renderers/markaby.rb +41 -0
  49. data/lib/waves/layers/text/inflect/english.rb +42 -0
  50. data/lib/waves/matchers/accept.rb +47 -0
  51. data/lib/waves/matchers/ext.rb +27 -0
  52. data/lib/waves/matchers/path.rb +72 -0
  53. data/lib/waves/matchers/query.rb +43 -0
  54. data/lib/waves/matchers/request.rb +86 -0
  55. data/lib/waves/matchers/requested.rb +31 -0
  56. data/lib/{matchers → waves/matchers}/resource.rb +8 -1
  57. data/lib/waves/matchers/traits.rb +30 -0
  58. data/lib/waves/matchers/uri.rb +69 -0
  59. data/lib/waves/media/mime_types.rb +542 -0
  60. data/lib/waves/renderers/mixin.rb +9 -0
  61. data/lib/waves/request/accept.rb +92 -0
  62. data/lib/{runtime → waves/request}/request.rb +77 -61
  63. data/lib/waves/resources/file_mixin.rb +11 -0
  64. data/lib/{resources → waves/resources}/mixin.rb +42 -44
  65. data/lib/waves/resources/paths.rb +132 -0
  66. data/lib/waves/response/client_errors.rb +10 -0
  67. data/lib/waves/response/packaged.rb +19 -0
  68. data/lib/waves/response/redirects.rb +35 -0
  69. data/lib/{runtime → waves/response}/response.rb +29 -11
  70. data/lib/{runtime → waves/response}/response_mixin.rb +30 -17
  71. data/lib/waves/runtime/applications.rb +18 -0
  72. data/lib/{runtime → waves/runtime}/configuration.rb +31 -25
  73. data/lib/waves/runtime/console.rb +24 -0
  74. data/lib/{runtime → waves/runtime}/logger.rb +3 -3
  75. data/lib/{runtime → waves/runtime}/mocks.rb +2 -2
  76. data/lib/waves/runtime/rackup.rb +37 -0
  77. data/lib/waves/runtime/runtime.rb +48 -0
  78. data/lib/waves/runtime/server.rb +33 -0
  79. data/lib/{servers → waves/servers}/base.rb +0 -0
  80. data/lib/{servers → waves/servers}/mongrel.rb +0 -0
  81. data/lib/{servers → waves/servers}/webrick.rb +0 -0
  82. data/lib/{tasks → waves/tasks}/gem.rb +0 -0
  83. data/lib/{tasks → waves/tasks}/generate.rb +0 -0
  84. data/lib/waves/views/cassy.rb +173 -0
  85. data/lib/{views → waves/views}/errors.rb +8 -7
  86. data/lib/waves/views/mixin.rb +23 -0
  87. data/lib/waves/views/templated.rb +40 -0
  88. data/samples/basic/basic_startup.rb +70 -0
  89. data/samples/basic/config.ru +9 -0
  90. data/samples/blog/configurations/development.rb +17 -16
  91. data/samples/blog/configurations/production.rb +0 -11
  92. data/samples/blog/resources/entry.rb +3 -3
  93. data/samples/blog/resources/map.rb +10 -3
  94. data/samples/blog/startup.rb +4 -3
  95. data/templates/classic/Rakefile +28 -29
  96. data/templates/classic/configurations/default.rb.erb +8 -3
  97. data/templates/classic/configurations/development.rb.erb +1 -20
  98. data/templates/classic/configurations/production.rb.erb +2 -16
  99. data/templates/classic/public/images/favicon.ico +0 -0
  100. data/templates/classic/resources/server.rb.erb +9 -0
  101. data/templates/classic/startup.rb.erb +3 -3
  102. data/templates/classic/views/css.rb.erb +14 -0
  103. data/templates/classic/views/default.rb.erb +17 -0
  104. data/templates/classic/views/errors.rb.erb +10 -0
  105. data/templates/classic/views/pages.rb.erb +14 -0
  106. data/templates/compact/startup.rb.erb +8 -3
  107. data/test/ext/object.rb +55 -0
  108. data/test/ext/shortcuts.rb +73 -0
  109. data/test/helpers.rb +17 -0
  110. data/test/match/accept.rb +78 -0
  111. data/test/match/ext.rb +156 -0
  112. data/test/match/methods.rb +22 -0
  113. data/test/match/params.rb +33 -0
  114. data/test/match/path.rb +106 -0
  115. data/test/match/query.rb +60 -0
  116. data/test/match/request.rb +91 -0
  117. data/test/match/requested.rb +149 -0
  118. data/test/match/uri.rb +136 -0
  119. data/test/process/request.rb +75 -0
  120. data/test/process/resource.rb +53 -0
  121. data/test/resources/path.rb +166 -0
  122. data/test/runtime/configurations.rb +19 -0
  123. data/test/runtime/request.rb +63 -0
  124. data/test/runtime/response.rb +85 -0
  125. data/test/views/views.rb +40 -0
  126. metadata +243 -157
  127. data/lib/caches/memcached.rb +0 -40
  128. data/lib/dispatchers/default.rb +0 -25
  129. data/lib/ext/string.rb +0 -20
  130. data/lib/helpers/basic.rb +0 -11
  131. data/lib/helpers/extended.rb +0 -21
  132. data/lib/helpers/form.rb +0 -42
  133. data/lib/helpers/formatting.rb +0 -30
  134. data/lib/helpers/layouts.rb +0 -37
  135. data/lib/helpers/model.rb +0 -37
  136. data/lib/helpers/view.rb +0 -22
  137. data/lib/layers/inflect/english.rb +0 -67
  138. data/lib/layers/mvc.rb +0 -54
  139. data/lib/layers/renderers/erubis.rb +0 -60
  140. data/lib/layers/renderers/haml.rb +0 -47
  141. data/lib/layers/renderers/markaby.rb +0 -29
  142. data/lib/matchers/accept.rb +0 -21
  143. data/lib/matchers/base.rb +0 -30
  144. data/lib/matchers/content_type.rb +0 -17
  145. data/lib/matchers/path.rb +0 -67
  146. data/lib/matchers/query.rb +0 -21
  147. data/lib/matchers/request.rb +0 -27
  148. data/lib/matchers/traits.rb +0 -19
  149. data/lib/matchers/uri.rb +0 -20
  150. data/lib/renderers/mixin.rb +0 -36
  151. data/lib/resources/paths.rb +0 -34
  152. data/lib/runtime/console.rb +0 -23
  153. data/lib/runtime/mime_types.rb +0 -536
  154. data/lib/runtime/monitor.rb +0 -32
  155. data/lib/runtime/runtime.rb +0 -67
  156. data/lib/runtime/server.rb +0 -20
  157. data/lib/runtime/session.rb +0 -27
  158. data/lib/runtime/worker.rb +0 -86
  159. data/lib/views/mixin.rb +0 -62
  160. data/samples/blog/blog.db +0 -0
  161. data/samples/blog/log/waves.production +0 -3
  162. data/templates/classic/resources/map.rb.erb +0 -8
  163. data/templates/classic/templates/errors/not_found_404.mab +0 -7
  164. data/templates/classic/templates/errors/server_error_500.mab +0 -7
  165. data/templates/classic/templates/layouts/default.mab +0 -14
  166. data/templates/classic/tmp/sessions/.gitignore +0 -0
@@ -1,32 +0,0 @@
1
- module Waves
2
-
3
- class Monitor
4
-
5
- def initialize( options ) ; @options = options ; end
6
-
7
- def start( manager )
8
- @manager = manager
9
- @pid = fork do
10
- safe_trap('INT','TERM') do
11
- Waves::Logger.info "Monitor stopped ..."
12
- exit
13
- end
14
- loop { fix unless check ; sleep interval }
15
- end
16
- end
17
-
18
- def fix
19
- @manager.restart
20
- end
21
-
22
- # you need to implement this
23
- def check ; true ; end
24
-
25
- # defaults to every 60 seconds
26
- def interval ; @options[ :interval ] ; end
27
-
28
- def stop ; Process.kill( 'INT', @pid ) ; end
29
-
30
- end
31
-
32
- end
@@ -1,67 +0,0 @@
1
- module Waves
2
-
3
- # A temporary measure until the applications "array" becomes a hash.
4
- # Currently used to keep track of all loaded Waves applications.
5
- class Applications < Array
6
- def []( name ) ; self.find { |app| app == name.to_s.camel_case } ; end
7
- end
8
-
9
- def self.config; instance.config ; end
10
-
11
- # The list of all loaded applications
12
- def self.applications ; @applications ||= Applications.new ; end
13
-
14
- # Access the principal Waves application.
15
- def self.main ; applications.first ; end
16
-
17
- # Register a module as a Waves application.
18
- def self.<< ( app )
19
- applications << app if Module === app
20
- end
21
-
22
- # Returns the most recently created instance of Waves::Runtime.
23
- def self.instance ; Waves::Runtime.instance ; end
24
-
25
- def self.version ; File.read( File.expand_path( "#{File.dirname(__FILE__)}/../../doc/VERSION" ) ) ; end
26
- def self.license ; File.read( File.expand_path( "#{File.dirname(__FILE__)}/../../doc/LICENSE" ) ) ; end
27
-
28
- def self.method_missing(name,*args,&block) ; instance.send(name,*args,&block) ; end
29
-
30
- # A Waves::Runtime takes an inert application module and gives it concrete, pokeable form.
31
- # Waves::Server and Waves::Console are types of runtime.
32
- class Runtime
33
-
34
- class << self; attr_accessor :instance; end
35
-
36
- # Accessor for options passed to the runtime.
37
- attr_reader :options
38
-
39
- # Create a new Waves application instance.
40
- def initialize( options={} )
41
- @options = options
42
- Dir.chdir options[:directory] if options[:directory]
43
- Runtime.instance = self
44
- end
45
-
46
- # The 'mode' of the runtime determines which configuration it will run under.
47
- def mode ; options[:mode]||:development ; end
48
-
49
- # Returns true if debug was set to true in the current configuration.
50
- def debug? ; options[:debugger] or config.debug ; end
51
-
52
- # Returns the current configuration.
53
- def config ; Waves.main::Configurations[ mode ] ; end
54
-
55
- # Reload the modules specified in the current configuration.
56
- def reload ; config.reloadable.each { |mod| mod.reload } ; end
57
-
58
- # Start and / or access the Waves::Logger instance.
59
- def log ; @log ||= Waves::Logger.start ; end
60
-
61
- # Provides access to the server mutex for thread-safe operation.
62
- def synchronize( &block ) ; ( @mutex ||= Mutex.new ).synchronize( &block ) ; end
63
- def synchronize? ; !options[ :turbo ] ; end
64
-
65
- end
66
-
67
- end
@@ -1,20 +0,0 @@
1
- module Waves
2
-
3
- class Server < Worker
4
-
5
- def start_tasks
6
- @server = config.server.new( application, host, port )
7
- @server.start
8
- end
9
-
10
- def stop_tasks ; @server.stop ; end
11
-
12
- private
13
-
14
- def application ; @app ||= config.application.to_app ; end
15
- def port ; @port ||= options[:port] or config.port ; end
16
- def host ; @host ||= options[:host] or config.host ; end
17
-
18
- end
19
-
20
- end
@@ -1,27 +0,0 @@
1
- module Waves
2
-
3
- # Encapsulates the session associated with a given request. A session has an expiration
4
- # and path, which must be provided in a Waves::Configuration. Sensible defaults are defined
5
- # in Waves::Configurations::Default
6
-
7
- class Session
8
-
9
- # Create a new session object using the given request. This is not necessarily the
10
- # same as constructing a new session. See Rack::Sesssion for more info.
11
- def initialize( request )
12
- @data = request.rack_request.env['rack.session']
13
- end
14
-
15
- # Return the session data as a hash
16
- def to_hash ; @data ; end
17
-
18
- # Access a given data element of the session using the given key.
19
- def [](key) ; @data[key] ; end
20
- # Set the given data element of the session using the given key and value.
21
- def []=(key,val) ; @data[key] = val ; end
22
-
23
-
24
- end
25
-
26
- end
27
-
@@ -1,86 +0,0 @@
1
- require 'drb'
2
- module Waves
3
-
4
- # "Workers" are just dedicated processes. Managers, Servers, and Monitors are all
5
- # examples of Workers. This class just encapsulates the common features across all
6
- # Workers: daemonization, signal traps, console support, logging, only-ness, etc.
7
-
8
- class Worker < Runtime
9
-
10
- def self.run( options )
11
- @instance ||= new( options )
12
- Kernel.load( options[:startup] || 'startup.rb' )
13
- @instance.start
14
- end
15
-
16
- # make this the one-and-only
17
- def self.instance ; @instance ; end
18
- class << self ; private :new, :allocate ; end
19
- private :dup, :clone
20
-
21
- # returns the PID of the new process
22
- def start
23
- pid = daemonize if options[ :daemon ]
24
- return pid if pid
25
- # from here on in, we're in the daemon
26
- start_logger ; Waves::Logger.info "#{self.class} starting ..."
27
- start_debugger if debug? unless Kernel.engine == 'jruby'
28
- # various ways to talk to a worker
29
- set_traps ; start_console ; start_drb
30
- start_tasks.join
31
- end
32
-
33
- def stop
34
- Waves::Logger.info "#{self.class} shutting down ..."
35
- @console.stop if @console
36
- stop_tasks
37
- end
38
-
39
- def restart ; stop ; start ; end
40
-
41
- def daemonize
42
- pwd = Dir.pwd ; pid = fork ; return pid if pid ; Dir.chdir( pwd )
43
- File.umask 0000 ; STDIN.reopen( '/dev/null') ;
44
- STDOUT.reopen( '/dev/null', 'a' ) ; STDERR.reopen( STDOUT )
45
- nil # return nil for child process, just like fork does
46
- end
47
-
48
- def set_traps
49
- safe_trap( 'HUP' ) { restart }
50
- safe_trap( 'TERM','INT' ) { stop }
51
- end
52
-
53
- def start_logger
54
- Waves::Logger.start
55
- Waves::Logger.info "Logger started."
56
- end
57
-
58
- def start_console
59
- if config.console
60
- @console = config.console ; @console.start
61
- Waves::Logger.info "Console started on port #{config.console.port}"
62
- end
63
- end
64
-
65
- def start_debugger
66
- require 'ruby-debug' ; Debugger.start
67
- Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
68
- Waves::Logger.info "ruby-debug enabled"
69
- end
70
-
71
- protected
72
-
73
- # workers should override these methods
74
- def start_tasks
75
- end
76
-
77
- def stop_tasks
78
- end
79
-
80
- # for management, monitoring
81
- def start_drb
82
- end
83
-
84
- end
85
-
86
- end
data/lib/views/mixin.rb DELETED
@@ -1,62 +0,0 @@
1
- module Waves
2
-
3
- module Views
4
-
5
- # A class method that returns the known Renderers, which is any module that is defined within Waves::Renderers and includes the Renderers::Mixin.
6
- # You can define new Renderers simply be reopening Waves::Renderers and defining a module that mixes in Renderers::Mixin.
7
- def self.renderers ; @renderers ||= [] ; end
8
-
9
- def self.renderer_for(path)
10
- @renderers.find do |renderer|
11
- File.extname( path ) == ".#{renderer::Extension}" or File.exists?( renderer.filename( path ) )
12
- end
13
- end
14
-
15
- def self.render( path, assigns = {} )
16
- template = Views.renderer_for(path)
17
- raise NoTemplateError.new( path ) if template.nil?
18
- template.render( path, assigns )
19
- end
20
-
21
- class NoTemplateError < Exception # :nodoc:
22
- end
23
-
24
- # The View mixin simply sets up the machinery for invoking a template, along with methods for accessing
25
- # the request assigns and the standard interface for invoking a view method.
26
- module Mixin
27
-
28
- attr_reader :request
29
-
30
- include Waves::ResponseMixin
31
-
32
- def self.included( target )
33
- def target.process( request, *args, &block )
34
- self.new( request ).instance_exec( *args, &block )
35
- end
36
- end
37
-
38
- def initialize( request ) ; @request = request ; @layout = :default ; end
39
-
40
- # Return the first renderer for which a template file can be found.
41
- # Uses Renderers::Mixin.filename to construct the filename for each renderer.
42
- def renderer(path) ; Views.renderer_for( :templates / path) ; end
43
-
44
- # Render the template found in the directory named after this view (snake cased, of course)
45
- # E.g. App::Views::Gnome.new.render( "stink" ) would look for templates/gnome/stink.<ext>
46
- def render( path, assigns = {} )
47
- qpath = "#{self.class.basename.snake_case}/#{path}"
48
- Waves.log.debug "Rendering template: #{qpath}"
49
- Views.render( :templates / qpath, assigns.merge!( :request => request ))
50
- end
51
-
52
- # Render the template with the name of the missing method.
53
- def method_missing(name,*args) ; render( name, *args ) ; end
54
-
55
- end
56
-
57
- class Base ; include Mixin ; end
58
-
59
- end
60
-
61
-
62
- end
data/samples/blog/blog.db DELETED
Binary file
@@ -1,3 +0,0 @@
1
- # Logfile created on Fri Oct 31 09:30:49 -0700 2008 by /
2
- W, [2008-10-31 09:33:02 #2368] WARN -- : http://localhost:4000/ not found.
3
- W, [2008-10-31 09:51:17 #2403] WARN -- : http://localhost:4000/ not found.
@@ -1,8 +0,0 @@
1
- module <%= @name %>
2
- module Resources
3
- class Map
4
- include Waves::Resources::Mixin
5
-
6
- end
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- style <<-STYLE
2
- body { background: #933; padding: 20px; font-family: verdana, sans-serif; }
3
- h1 { font-size: 60px; font-weight: bold; margin: 0px; }
4
- p { font-size: 24px; margin: 0px; }
5
- STYLE
6
- h1 '404'
7
- p { 'That URL does not exist on this server.' }
@@ -1,7 +0,0 @@
1
- style <<-STYLE
2
- body { background: #c93; padding: 20px; font-family: verdana, sans-serif; }
3
- h1 { font-size: 60px; font-weight: bold; margin: 0px; }
4
- p { font-size: 24px; margin: 0px; }
5
- STYLE
6
- h1 '500'
7
- p %q( Internal server error. Sorry, but your request could not be processed. )
@@ -1,14 +0,0 @@
1
- doctype :html4_strict
2
-
3
- html do
4
-
5
- head do
6
- title @title
7
- end
8
-
9
- body do
10
- layout_content
11
- end
12
-
13
- end
14
-
File without changes