ramaze 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. data/Rakefile +4 -12
  2. data/bin/ramaze +95 -171
  3. data/doc/CHANGELOG +387 -4
  4. data/doc/README +81 -13
  5. data/doc/meta/announcement.txt +51 -8
  6. data/doc/meta/configuration.txt +17 -34
  7. data/doc/meta/internals.txt +34 -4
  8. data/doc/migrate/1110_to_1111.txt +131 -0
  9. data/doc/readme_chunks/features.txt +81 -12
  10. data/doc/readme_chunks/installing.txt +0 -1
  11. data/doc/tutorial/todolist.html +293 -65
  12. data/doc/tutorial/{todolist.txt → todolist.mkd} +251 -51
  13. data/examples/blog/main.rb +1 -1
  14. data/examples/blog/src/model.rb +0 -1
  15. data/examples/hello.rb +2 -5
  16. data/examples/templates/template/external.haml +5 -5
  17. data/examples/templates/template/external.liquid +1 -1
  18. data/examples/templates/template/external.mab +8 -8
  19. data/examples/templates/template/external.rem +30 -0
  20. data/examples/templates/template/external.rhtml +6 -7
  21. data/examples/templates/template/external.zmr +13 -9
  22. data/examples/templates/template_amrita2.rb +8 -8
  23. data/examples/templates/template_erubis.rb +11 -11
  24. data/examples/templates/template_ezamar.rb +9 -11
  25. data/examples/templates/template_haml.rb +13 -13
  26. data/examples/templates/template_liquid.rb +10 -10
  27. data/examples/templates/template_markaby.rb +13 -10
  28. data/examples/templates/template_remarkably.rb +59 -0
  29. data/examples/todolist/main.rb +1 -7
  30. data/examples/todolist/src/controller/main.rb +26 -13
  31. data/examples/todolist/src/element/page.rb +5 -0
  32. data/examples/whywiki/main.rb +1 -1
  33. data/lib/proto/main.rb +0 -8
  34. data/lib/proto/public/css/ramaze_error.css +12 -4
  35. data/lib/proto/public/error.zmr +6 -25
  36. data/lib/ramaze.rb +35 -245
  37. data/lib/ramaze/action.rb +21 -0
  38. data/lib/ramaze/adapter.rb +94 -29
  39. data/lib/ramaze/adapter/base.rb +57 -0
  40. data/lib/ramaze/adapter/mongrel.rb +12 -19
  41. data/lib/ramaze/adapter/webrick.rb +21 -20
  42. data/lib/ramaze/cache.rb +47 -3
  43. data/lib/ramaze/cache/memcached.rb +22 -0
  44. data/lib/ramaze/cache/yaml_store.rb +19 -0
  45. data/lib/ramaze/controller.rb +47 -271
  46. data/lib/ramaze/controller/error.rb +43 -0
  47. data/lib/ramaze/controller/render.rb +90 -0
  48. data/lib/ramaze/controller/resolve.rb +147 -0
  49. data/lib/ramaze/dispatcher.rb +41 -9
  50. data/lib/ramaze/dispatcher/file.rb +1 -1
  51. data/lib/ramaze/global.rb +73 -158
  52. data/lib/ramaze/global/dsl.rb +29 -0
  53. data/lib/ramaze/global/globalstruct.rb +90 -0
  54. data/lib/ramaze/helper.rb +1 -1
  55. data/lib/ramaze/helper/aspect.rb +39 -179
  56. data/lib/ramaze/helper/cache.rb +8 -9
  57. data/lib/ramaze/helper/cgi.rb +23 -0
  58. data/lib/ramaze/helper/file.rb +3 -0
  59. data/lib/ramaze/helper/inform.rb +3 -0
  60. data/lib/ramaze/helper/link.rb +56 -63
  61. data/lib/ramaze/helper/nitroform.rb +4 -0
  62. data/lib/ramaze/helper/redirect.rb +1 -1
  63. data/lib/ramaze/inform.rb +6 -2
  64. data/lib/ramaze/inform/analogger.rb +5 -1
  65. data/lib/ramaze/inform/hub.rb +1 -1
  66. data/lib/ramaze/inform/informing.rb +7 -0
  67. data/lib/ramaze/snippets/kernel/aquire.rb +2 -0
  68. data/lib/ramaze/snippets/kernel/constant.rb +2 -0
  69. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +2 -0
  70. data/lib/ramaze/snippets/object/traits.rb +4 -0
  71. data/lib/ramaze/snippets/openstruct/temp.rb +3 -0
  72. data/lib/ramaze/snippets/string/DIVIDE.rb +2 -0
  73. data/lib/ramaze/snippets/string/camel_case.rb +2 -0
  74. data/lib/ramaze/snippets/string/color.rb +2 -0
  75. data/lib/ramaze/snippets/string/each.rb +2 -0
  76. data/lib/ramaze/snippets/string/snake_case.rb +3 -0
  77. data/lib/ramaze/snippets/struct/fill.rb +8 -2
  78. data/lib/ramaze/snippets/struct/values_at.rb +16 -0
  79. data/lib/ramaze/snippets/symbol/to_proc.rb +3 -0
  80. data/lib/ramaze/sourcereload.rb +89 -0
  81. data/lib/ramaze/template.rb +21 -12
  82. data/lib/ramaze/template/amrita2.rb +6 -6
  83. data/lib/ramaze/template/erubis.rb +4 -9
  84. data/lib/ramaze/template/ezamar.rb +13 -57
  85. data/lib/ramaze/template/ezamar/element.rb +10 -12
  86. data/lib/ramaze/template/ezamar/engine.rb +40 -101
  87. data/lib/ramaze/template/ezamar/morpher.rb +3 -3
  88. data/lib/ramaze/template/haml.rb +3 -6
  89. data/lib/ramaze/template/liquid.rb +4 -9
  90. data/lib/ramaze/template/markaby.rb +16 -22
  91. data/lib/ramaze/template/remarkably.rb +28 -0
  92. data/lib/ramaze/tool/mime.rb +2 -0
  93. data/lib/ramaze/tool/record.rb +6 -0
  94. data/lib/ramaze/trinity/request.rb +44 -54
  95. data/lib/ramaze/trinity/response.rb +1 -1
  96. data/lib/ramaze/trinity/session.rb +15 -37
  97. data/lib/ramaze/version.rb +1 -1
  98. data/rake_tasks/gem.rake +2 -2
  99. data/rake_tasks/maintaince.rake +42 -1
  100. data/rake_tasks/spec.rake +45 -0
  101. data/spec/examples/caching.rb +1 -1
  102. data/spec/examples/simple.rb +1 -1
  103. data/spec/examples/templates/template_amrita2.rb +1 -0
  104. data/spec/examples/templates/template_erubis.rb +2 -1
  105. data/spec/examples/templates/template_ezamar.rb +1 -1
  106. data/spec/examples/templates/template_haml.rb +2 -1
  107. data/spec/examples/templates/template_liquid.rb +2 -1
  108. data/spec/examples/templates/template_markaby.rb +2 -1
  109. data/spec/examples/templates/template_remarkably.rb +22 -0
  110. data/spec/examples/todolist.rb +125 -0
  111. data/spec/helper.rb +2 -23
  112. data/spec/helper/minimal.rb +20 -0
  113. data/spec/helper/mock_http.rb +24 -30
  114. data/spec/helper/simple_http.rb +2 -2
  115. data/spec/helper/wrap.rb +6 -9
  116. data/spec/ramaze/adapter.rb +1 -1
  117. data/spec/ramaze/adapter/record.rb +31 -0
  118. data/spec/ramaze/cache.rb +41 -54
  119. data/spec/ramaze/controller.rb +121 -137
  120. data/spec/ramaze/controller/template/list.xhtml +1 -0
  121. data/spec/ramaze/controller/template/other/greet/other.xhtml +1 -0
  122. data/spec/ramaze/controller/template_resolving.rb +27 -3
  123. data/spec/ramaze/element.rb +11 -7
  124. data/spec/ramaze/error.rb +1 -1
  125. data/spec/ramaze/gestalt.rb +2 -0
  126. data/spec/ramaze/helper/aspect.rb +30 -21
  127. data/spec/ramaze/helper/auth.rb +1 -1
  128. data/spec/ramaze/helper/cache.rb +2 -1
  129. data/spec/ramaze/helper/form.rb +14 -11
  130. data/spec/ramaze/helper/link.rb +18 -41
  131. data/spec/ramaze/localize.rb +29 -2
  132. data/spec/ramaze/morpher.rb +23 -12
  133. data/spec/ramaze/params.rb +46 -24
  134. data/spec/ramaze/request.rb +6 -2
  135. data/spec/ramaze/store/yaml.rb +5 -0
  136. data/spec/ramaze/template.rb +22 -27
  137. data/spec/ramaze/template/amrita2.rb +1 -2
  138. data/spec/ramaze/template/erubis.rb +1 -1
  139. data/spec/ramaze/template/ezamar.rb +1 -2
  140. data/spec/ramaze/template/haml.rb +2 -2
  141. data/spec/ramaze/template/haml/with_vars.haml +1 -1
  142. data/spec/ramaze/template/liquid.rb +1 -1
  143. data/spec/ramaze/template/markaby.rb +1 -1
  144. data/spec/ramaze/template/remarkably.rb +56 -0
  145. data/spec/ramaze/template/remarkably/external.rem +8 -0
  146. data/spec/ramaze/template/remarkably/sum.rem +1 -0
  147. metadata +38 -63
  148. data/doc/README.html +0 -637
  149. data/doc/allison/LICENSE +0 -184
  150. data/doc/allison/README +0 -37
  151. data/doc/allison/allison.css +0 -299
  152. data/doc/allison/allison.gif +0 -0
  153. data/doc/allison/allison.js +0 -307
  154. data/doc/allison/allison.rb +0 -287
  155. data/doc/allison/cache/BODY +0 -588
  156. data/doc/allison/cache/CLASS_INDEX +0 -4
  157. data/doc/allison/cache/CLASS_PAGE +0 -1
  158. data/doc/allison/cache/FILE_INDEX +0 -4
  159. data/doc/allison/cache/FILE_PAGE +0 -1
  160. data/doc/allison/cache/FONTS +0 -1
  161. data/doc/allison/cache/FR_INDEX_BODY +0 -1
  162. data/doc/allison/cache/IMGPATH +0 -1
  163. data/doc/allison/cache/INDEX +0 -1
  164. data/doc/allison/cache/JAVASCRIPT +0 -307
  165. data/doc/allison/cache/METHOD_INDEX +0 -4
  166. data/doc/allison/cache/METHOD_LIST +0 -1
  167. data/doc/allison/cache/SRC_PAGE +0 -1
  168. data/doc/allison/cache/STYLE +0 -321
  169. data/doc/allison/cache/URL +0 -1
  170. data/doc/changes.txt +0 -3375
  171. data/doc/changes.xml +0 -3378
  172. data/examples/todolist/conf/benchmark.yaml +0 -35
  173. data/examples/todolist/conf/debug.yaml +0 -34
  174. data/examples/todolist/conf/live.yaml +0 -33
  175. data/examples/todolist/conf/silent.yaml +0 -31
  176. data/examples/todolist/conf/stage.yaml +0 -33
  177. data/examples/todolist/public/css/coderay.css +0 -105
  178. data/examples/todolist/public/css/ramaze_error.css +0 -42
  179. data/lib/proto/conf/benchmark.yaml +0 -21
  180. data/lib/proto/conf/debug.yaml +0 -21
  181. data/lib/proto/conf/live.yaml +0 -21
  182. data/lib/proto/conf/silent.yaml +0 -21
  183. data/lib/proto/conf/stage.yaml +0 -21
  184. data/lib/proto/public/css/coderay.css +0 -105
  185. data/lib/ramaze/http_status.rb +0 -66
  186. data/lib/ramaze/snippets/hash/keys_to_sym.rb +0 -19
  187. data/lib/ramaze/snippets/kernel/method.rb +0 -26
  188. data/lib/ramaze/snippets/method/name.rb +0 -22
  189. data/lib/ramaze/snippets/ramaze/autoreload.rb +0 -135
  190. data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +0 -65
  191. data/spec/all.rb +0 -32
  192. data/spec/ramaze/conf/locale_de.yaml +0 -6
  193. data/spec/ramaze/conf/locale_en.yaml +0 -6
  194. data/spec/ramaze/dependencies.rb +0 -16
  195. data/spec/ramaze/global.rb +0 -44
@@ -0,0 +1,147 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Ramaze
5
+ class Controller
6
+ class << self
7
+ # #ramaze - 9.5.2007
8
+ #
9
+ # manveru: if no possible controller is found, it's a NoController error
10
+ # manveru: that would be a 404 then
11
+ # Kashia: aye
12
+ # manveru: if some controller are found but no actions on them, it's NoAction Error for the first controller found, again, 404
13
+ # manveru: everything further down is considered 500
14
+
15
+ def resolve(path)
16
+ #Inform.debug("resolve_controller('#{path}')")
17
+ mapping = Global.mapping
18
+ controllers = Global.controllers
19
+
20
+ raise_no_controller(path) if controllers.empty? or mapping.empty?
21
+
22
+ patterns = Cache.patterns[path] ||= pattern_for(path)
23
+ first_controller = nil
24
+
25
+ patterns.each do |controller, method, params|
26
+ if controller = mapping[controller]
27
+ first_controller ||= controller
28
+
29
+ action = controller.resolve_action(method, *params)
30
+ template = action.template
31
+
32
+ valid_action = (action.method or (params.empty? && action.template))
33
+
34
+ return controller, action if valid_action
35
+ end
36
+ end
37
+
38
+ raise_no_action(first_controller, path) if first_controller
39
+ raise_no_controller(path)
40
+ end
41
+
42
+ def resolve_action(path, *parameter)
43
+ path, parameter = path.to_s, parameter.map(&:to_s)
44
+ if alternate_template = trait["#{path}_template"]
45
+ t_controller, t_path = *alternate_template
46
+ template = t_controller.resolve_template(t_path)
47
+ end
48
+
49
+ method, params = resolve_method(path, *parameter)
50
+
51
+ if method or parameter.empty?
52
+ template ||= resolve_template(path)
53
+ end
54
+
55
+ hash = {:method => method, :params => params, :template => template}
56
+ Action.fill(hash)
57
+ end
58
+
59
+ def resolve_template(action)
60
+ action = action.to_s
61
+ action_converted = action.split('__').inject{|s,v| s/v}
62
+ actions = [action, action_converted].compact
63
+
64
+ paths = template_paths.map{|pa| actions.map{|a| pa/a } }.flatten.uniq
65
+ glob = "{#{paths.join(',')}}.{#{extension_order.join(',')}}"
66
+
67
+ Dir[glob].first
68
+ end
69
+
70
+ def template_paths
71
+ first_path =
72
+ if template_root = @template_root
73
+ template_root
74
+ else
75
+ Global.template_root / Global.mapping.invert[self]
76
+ end
77
+ [ first_path, public_root, Global.public_root ].compact
78
+ end
79
+
80
+ def resolve_method(name, *params)
81
+ if method = action_methods.delete(name)
82
+ arity = instance_method(method).arity
83
+ if params.size == arity or arity < 0
84
+ return method, params
85
+ end
86
+ end
87
+ return nil, []
88
+ end
89
+
90
+ def action_methods
91
+ exclude = Controller.trait[:exclude_action_modules]
92
+
93
+ ancs = (ancestors - exclude).select{|a| a.is_a?(Module)}
94
+ meths = ancs.map{|a| a.instance_methods(false).map(&:to_s)}.flatten.uniq
95
+ # fix for facets/more/paramix
96
+ meths - ancs.map(&:to_s)
97
+ end
98
+
99
+ def pattern_for(path)
100
+ atoms = path.split('/').grep(/\S/)
101
+ atoms.unshift('')
102
+ patterns, joiners = [], ['/']
103
+
104
+ atoms.size.times do |enum|
105
+ enum += 1
106
+ joiners << '__' if enum == 3
107
+
108
+ joiners.each do |joinus|
109
+ pattern = atoms.dup
110
+
111
+ controller = pattern[0, enum].join(joinus)
112
+ controller.gsub!(/^__/, '/')
113
+ controller = "/" if controller == ""
114
+
115
+ pattern = pattern[enum..-1]
116
+ args, temp = [], []
117
+
118
+ patterns << [controller, 'index', atoms[enum..-1]]
119
+
120
+ until pattern.empty?
121
+ args << pattern.shift
122
+ patterns << [controller, args.join( '__' ), pattern.dup]
123
+ end
124
+ end
125
+ end
126
+
127
+ patterns.reverse!
128
+ end
129
+
130
+ def extension_order
131
+ t_extensions = Controller.trait[:template_extensions]
132
+ engine = trait[:engine]
133
+ c_extensions = t_extensions.reject{|k,v| v != engine}.keys
134
+ all_extensions = t_extensions.keys
135
+ (c_extensions + all_extensions).uniq
136
+ end
137
+
138
+ def raise_no_controller(path)
139
+ raise Ramaze::Error::NoController, "No Controller found for `#{path}'"
140
+ end
141
+
142
+ def raise_no_action(controller, path)
143
+ raise Ramaze::Error::NoAction, "No Action found for `#{path}' on #{controller}"
144
+ end
145
+ end
146
+ end
147
+ end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'timeout'
5
5
 
6
+ require 'ramaze/error'
6
7
  require 'ramaze/adapter'
7
8
  require 'ramaze/tool/mime'
8
9
 
@@ -19,25 +20,37 @@ module Ramaze
19
20
  ]
20
21
 
21
22
  trait :handle_error => {
22
- Exception => [500, '/error'],
23
- Ramaze::Error::NoAction => [404, '/error'],
24
- Ramaze::Error::NoController => [404, '/error'],
23
+ Exception =>
24
+ [ STATUS_CODE["Internal Server Error"], '/error' ],
25
+ Ramaze::Error::NoAction =>
26
+ [ STATUS_CODE["Not Found"], '/error' ],
27
+ Ramaze::Error::NoController =>
28
+ [ STATUS_CODE["Not Found"], '/error' ],
25
29
  }
26
30
 
31
+ Cache.add :shield
32
+
33
+ trait :shielded => [ STATUS_CODE["Not Found"] ]
34
+
27
35
  class << self
28
36
  include Trinity
29
37
 
30
38
  def handle rack_request, rack_response
31
39
  setup_environment(rack_request, rack_response)
32
- dispatch
33
- rescue Object => error
34
- Dispatcher::Error.process(error)
35
- end
36
40
 
37
- def dispatch
38
41
  path = request.path_info.squeeze('/')
39
42
  Inform.info("Request from #{request.remote_addr}: #{path}")
40
43
 
44
+ if Global.shield
45
+ shielded_dispatch(path)
46
+ else
47
+ dispatch(path)
48
+ end
49
+ rescue Object => error
50
+ Dispatcher::Error.process(error)
51
+ end
52
+
53
+ def dispatch(path)
41
54
  catch(:respond) do
42
55
  redirection = catch(:redirect) do
43
56
  found = filter(path)
@@ -53,7 +66,26 @@ module Ramaze
53
66
  def dispatch_to path
54
67
  raise "Redirect to #{path} from #{path}" if request.path_info == path
55
68
  request.path_info = path
56
- dispatch
69
+
70
+ if Global.shield
71
+ shielded_dispatch(path)
72
+ else
73
+ dispatch(path)
74
+ end
75
+ end
76
+
77
+ def shielded_dispatch(path)
78
+ shield_cache = Cache.shield
79
+ handled = shield_cache[path]
80
+ return handled if handled
81
+
82
+ dispatched = dispatch(path)
83
+
84
+ unless trait[:shielded].include?(dispatched.status)
85
+ dispatched
86
+ else
87
+ shield_cache[path] = dispatched
88
+ end
57
89
  end
58
90
 
59
91
  def filter path
@@ -7,7 +7,7 @@ module Ramaze
7
7
  class << self
8
8
  def process(path)
9
9
  return unless file = open_file(path)
10
- Dispatcher.build_response(file, Ramaze::STATUS_CODE[:ok])
10
+ Dispatcher.build_response(file, Ramaze::STATUS_CODE['OK'])
11
11
  end
12
12
 
13
13
  def lookup_paths
@@ -4,166 +4,81 @@
4
4
  require 'ostruct'
5
5
  require 'set'
6
6
 
7
+ require 'ramaze/global/dsl'
8
+
7
9
  module Ramaze
8
- class GlobalStruct < OpenStruct
9
- # autoreload - Interval for autoreloading changed source in seconds
10
- # adapter - Webserver-adapter ( :mongrel | :webrick )
11
- # backtrace_size - size of backtrace to be logged (and shown on error-page).
12
- # benchmarking - enable timing of each request
13
- # cache - Cache to use ( MemcachedCache | MemoryCache | YamlStoreCache )
14
- # cache_all - Naive caching for all responses ( true | false )
15
- # cookies -
16
- # error_page - Show default errorpage with inspection and backtrace ( true | false )
17
- # host - Host to respond to ( '0.0.0.0' )
18
- # mapping - Route to controller map ( {} )
19
- # port - First port of the port-range the adapters run on. ( 7000 )
20
- # run_loose - Don't wait for the servers to finish, useful for testing ( true | false )
21
- # template_root - Default directory for your templates.
22
- #
23
- # startup - List of methods and lambdas that are executed on startup
24
- # ramaze_startup - Internal list of methods and lambdas that are executed on startup
25
- #
26
- # shutdown - List of methods and lambdas that are executed on startup
27
- # ramaze_shutdown - Internal list of methods and lambdas that are executed on shutdown
28
-
29
- DEFAULT = {
30
- :autoreload => 5,
31
- :adapter => :webrick,
32
- :backtrace_size => 10,
33
- :benchmarking => false,
34
- :cache => MemoryCache,
35
- :cache_all => false,
36
- :controllers => Set.new,
37
- :cookies => true,
38
- :error_page => true,
39
- :host => '0.0.0.0',
40
- :localize => lambda{ Ramaze::Tool::Localize.trait },
41
- :logger => Ramaze::Informer.new($stdout),
42
- :mapping => {},
43
- :port => 7000,
44
- :run_loose => false,
45
- :template_root => 'template',
46
- :tidy => lambda{ Ramaze::Tool::Tidy.trait },
47
- :test_connections => true,
48
- :shutdown_trap => 'SIGINT',
49
-
50
- :startup => [
51
- lambda{
52
- Ramaze::Inform = Global.logger unless defined?(Inform)
53
- Inform.info("Starting up Ramaze (Version #{VERSION})")
54
- }
55
- ],
56
- :ramaze_startup => [
57
- :setup_controllers, :init_autoreload, :init_adapter
58
- ],
59
-
60
- :shutdown => [],
61
- :ramaze_shutdown => [
62
- :kill_threads,
63
- lambda{
64
- Inform.shutdown
65
- puts("Shutdown Ramaze (it's save to kill me now if i hang)")
66
- },
67
- :exit
68
- ],
69
- }
70
-
71
- # takes an hash of options and optionally an block that is evaled in this
72
- # instance of GlobalStruct.
73
-
74
- def setup hash = {}, &block
75
- Global.instance_eval(&block) if block_given?
76
- table.merge!( hash.keys_to_sym )
77
- end
78
-
79
- # just update the hash, not deleting values already set.
80
- # again, takes a block, but your assignments may be
81
- # overwritten if they existed before.
82
-
83
- def update hash = {}, &block
84
- old_table = table.dup
85
- Global.instance_eval(&block) if block_given?
86
- table.merge!( hash.keys_to_sym.merge( old_table ) )
87
- end
88
-
89
- # synonym to Global.key = value
90
-
91
- def []=(key, value)
92
- table[key.to_sym] = value
93
- end
94
-
95
- # synonym for Global.key
96
-
97
- def [](key)
98
- table[key.to_sym]
99
- end
100
-
101
- # get all the values for the given keys in the right order.
102
-
103
- def values_at(*keys)
104
- table.values_at(*keys.map(&:to_sym))
105
- end
106
-
107
- # all keys already set
108
-
109
- def keys
110
- table.keys
111
- end
112
-
113
- # iterate over the GlobalStruct, no guarantee on the order.
114
-
115
- def each
116
- table.each do |e|
117
- yield(e)
118
- end
119
- end
120
-
121
- def inspect
122
- table.inspect
123
- end
124
-
125
- def pretty_inspect
126
- table.pretty_inspect
127
- end
128
-
129
-
130
- def new_ostruct_member(name)
131
- name = name.to_sym
132
- unless self.respond_to?(name)
133
- class << self; self; end.class_eval do
134
- define_method(name) { @table[name] }
135
- define_method(:"#{name}=") { |x| @table[name] = x }
136
- end
137
- end
138
- end
10
+ GlobalDSL.option_dsl do
11
+ o "Set the adapter Ramaze will run on.",
12
+ :adapter => :webrick, :cli => [:webrick, :mongrel]
13
+
14
+ o "All running threads of Adapter will be collected here.",
15
+ :adapters => ThreadGroup.new
16
+
17
+ o "Set the size of Backtrace shown.",
18
+ :backtrace_size => 10, :cli => 10
19
+
20
+ o "Turn benchmarking every request on.",
21
+ :benchmarking => false, :cli => false
22
+
23
+ o "Use this for general caching and as base for Cache.new.",
24
+ :cache => :memory, :cli => [:memory, :memcached, :yaml]
25
+
26
+ o "Turn on naive caching of all requests.",
27
+ :cache_all => false, :cli => false
28
+
29
+ o "Turn on cookies for all requests.",
30
+ :cookies => true, :cli => true
31
+
32
+ o "All subclasses of Controller are collected here.",
33
+ :controllers => Set.new
34
+
35
+ o "Start Ramaze within an IRB session",
36
+ :console => false, :cli => false
37
+
38
+ o "Turn on customized error pages.",
39
+ :error_page => true, :cli => true
40
+
41
+ o "Specify what IP Ramaze will respond to - 0.0.0.0 for all",
42
+ :host => "0.0.0.0", :cli => '0.0.0.0'
139
43
 
140
- def new_ostruct_member(name)
141
- name = name.to_sym
142
- unless self.respond_to?(name)
143
- meta = (class << self; self; end)
144
- meta.class_eval do
145
- define_method(name) do
146
- sel = @table[name]
147
- if sel.respond_to?(:call)
148
- sel.call
149
- else
150
- sel
151
- end
152
- end
153
-
154
- define_method(:"#{name}=") do |x|
155
- sel = @table[name]
156
- if sel.respond_to?(:call)
157
- sel.call("#{name}=", x)
158
- else
159
- @table[name] = x
160
- end
161
- end
162
- end
163
- end
164
- end
44
+ o "All paths to controllers are mapped here.",
45
+ :mapping => {}
46
+
47
+ o "The place ramaze was started from, useful mostly for debugging",
48
+ :origin => :main
49
+
50
+ o "Specify port",
51
+ :port => 7000, :cli => 7000
52
+
53
+ o "Specify the shadowing public directory (default in proto)",
54
+ :public_root => ( BASEDIR / 'proto' / 'public' )
55
+
56
+ o "Record all Request objects by assigning a filtering Proc to me.",
57
+ :record => false
58
+
59
+ o "Don't wait until all adapter-threads are finished or killed.",
60
+ :run_loose => false, :cli => false
61
+
62
+ o "Turn on BF/DoS protection for error-responses",
63
+ :shield => false, :cli => false
64
+
65
+ o "What signal to trap to call Ramaze::shutdown",
66
+ :shutdown_trap => "SIGINT"
67
+
68
+ o "Interval in seconds of the background SourceReload",
69
+ :sourcereload => 3, :cli => 3
70
+
71
+ o "How many adapters Ramaze should spawn.",
72
+ :spawn => 1, :cli => 1
73
+
74
+ o "Test before start if adapters will be able to connect",
75
+ :test_connections => true, :cli => true
76
+
77
+ o "Specify template root for dynamic files relative to main.rb",
78
+ :template_root => 'template'
165
79
  end
166
80
 
167
- Thread.current[:global] = GlobalStruct.new(GlobalStruct::DEFAULT)
168
- Global = Thread.current[:global]
81
+ require 'ramaze/global/globalstruct'
82
+
83
+ Global = GlobalStruct.setup(OPTIONS)
169
84
  end