merb-core 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/LICENSE +1 -1
  2. data/README +3 -3
  3. data/Rakefile +144 -33
  4. data/bin/merb +0 -0
  5. data/bin/merb-specs +0 -0
  6. data/docs/bootloading.dox +1 -0
  7. data/docs/merb-core-call-stack-diagram.mmap +0 -0
  8. data/docs/merb-core-call-stack-diagram.pdf +0 -0
  9. data/docs/merb-core-call-stack-diagram.png +0 -0
  10. data/lib/merb-core.rb +159 -37
  11. data/lib/merb-core/autoload.rb +1 -0
  12. data/lib/merb-core/bootloader.rb +208 -92
  13. data/lib/merb-core/config.rb +20 -6
  14. data/lib/merb-core/controller/abstract_controller.rb +113 -61
  15. data/lib/merb-core/controller/exceptions.rb +28 -13
  16. data/lib/merb-core/controller/merb_controller.rb +73 -44
  17. data/lib/merb-core/controller/mime.rb +25 -7
  18. data/lib/merb-core/controller/mixins/authentication.rb +1 -1
  19. data/lib/merb-core/controller/mixins/controller.rb +44 -8
  20. data/lib/merb-core/controller/mixins/render.rb +191 -128
  21. data/lib/merb-core/controller/mixins/responder.rb +65 -63
  22. data/lib/merb-core/controller/template.rb +103 -54
  23. data/lib/merb-core/core_ext.rb +7 -12
  24. data/lib/merb-core/core_ext/kernel.rb +128 -136
  25. data/lib/merb-core/dispatch/cookies.rb +26 -4
  26. data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
  27. data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
  28. data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
  29. data/lib/merb-core/dispatch/default_exception/views/index.html.erb +92 -0
  30. data/lib/merb-core/dispatch/dispatcher.rb +156 -224
  31. data/lib/merb-core/dispatch/request.rb +126 -25
  32. data/lib/merb-core/dispatch/router.rb +61 -6
  33. data/lib/merb-core/dispatch/router/behavior.rb +122 -41
  34. data/lib/merb-core/dispatch/router/route.rb +147 -22
  35. data/lib/merb-core/dispatch/session.rb +52 -2
  36. data/lib/merb-core/dispatch/session/cookie.rb +4 -2
  37. data/lib/merb-core/dispatch/session/memcached.rb +38 -27
  38. data/lib/merb-core/dispatch/session/memory.rb +18 -11
  39. data/lib/merb-core/dispatch/worker.rb +28 -0
  40. data/lib/merb-core/gem_ext/erubis.rb +58 -0
  41. data/lib/merb-core/logger.rb +3 -31
  42. data/lib/merb-core/plugins.rb +25 -3
  43. data/lib/merb-core/rack.rb +18 -12
  44. data/lib/merb-core/rack/adapter.rb +10 -8
  45. data/lib/merb-core/rack/adapter/ebb.rb +2 -2
  46. data/lib/merb-core/rack/adapter/irb.rb +31 -21
  47. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
  48. data/lib/merb-core/rack/adapter/thin.rb +19 -9
  49. data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
  50. data/lib/merb-core/rack/application.rb +9 -84
  51. data/lib/merb-core/rack/middleware.rb +26 -0
  52. data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
  53. data/lib/merb-core/rack/middleware/profiler.rb +19 -0
  54. data/lib/merb-core/rack/middleware/static.rb +45 -0
  55. data/lib/merb-core/server.rb +27 -9
  56. data/lib/merb-core/tasks/audit.rake +68 -0
  57. data/lib/merb-core/tasks/merb.rb +1 -0
  58. data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
  59. data/lib/merb-core/tasks/stats.rake +71 -0
  60. data/lib/merb-core/test.rb +2 -1
  61. data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
  62. data/lib/merb-core/test/helpers/request_helper.rb +66 -24
  63. data/lib/merb-core/test/matchers/controller_matchers.rb +36 -4
  64. data/lib/merb-core/test/matchers/route_matchers.rb +12 -3
  65. data/lib/merb-core/test/matchers/view_matchers.rb +3 -3
  66. data/lib/merb-core/test/run_specs.rb +1 -0
  67. data/lib/merb-core/test/tasks/spectasks.rb +13 -5
  68. data/lib/merb-core/test/test_ext/string.rb +14 -0
  69. data/lib/merb-core/vendor/facets/dictionary.rb +3 -3
  70. data/lib/merb-core/vendor/facets/inflect.rb +82 -37
  71. data/lib/merb-core/version.rb +2 -2
  72. data/spec/private/config/config_spec.rb +39 -4
  73. data/spec/private/core_ext/kernel_spec.rb +3 -14
  74. data/spec/private/dispatch/bootloader_spec.rb +1 -1
  75. data/spec/private/dispatch/cookies_spec.rb +181 -69
  76. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -2
  77. data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -2
  78. data/spec/private/dispatch/fixture/config/rack.rb +10 -0
  79. data/spec/private/dispatch/fixture/log/merb_test.log +7054 -1802
  80. data/spec/private/dispatch/route_params_spec.rb +2 -3
  81. data/spec/private/dispatch/session_mixin_spec.rb +47 -0
  82. data/spec/private/plugins/plugin_spec.rb +73 -59
  83. data/spec/private/router/behavior_spec.rb +60 -0
  84. data/spec/private/router/fixture/log/merb_test.log +1693 -0
  85. data/spec/private/router/route_spec.rb +414 -0
  86. data/spec/private/router/router_spec.rb +175 -0
  87. data/spec/private/vendor/facets/plural_spec.rb +564 -0
  88. data/spec/private/vendor/facets/singular_spec.rb +489 -0
  89. data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
  90. data/spec/public/abstract_controller/controllers/helpers.rb +12 -2
  91. data/spec/public/abstract_controller/controllers/partial.rb +17 -2
  92. data/spec/public/abstract_controller/controllers/render.rb +16 -1
  93. data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
  94. data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
  95. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
  96. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
  97. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
  98. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
  99. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
  100. data/spec/public/abstract_controller/filter_spec.rb +20 -1
  101. data/spec/public/abstract_controller/helper_spec.rb +10 -2
  102. data/spec/public/abstract_controller/partial_spec.rb +8 -0
  103. data/spec/public/abstract_controller/render_spec.rb +8 -0
  104. data/spec/public/abstract_controller/spec_helper.rb +7 -3
  105. data/spec/public/boot_loader/boot_loader_spec.rb +2 -2
  106. data/spec/public/controller/base_spec.rb +10 -2
  107. data/spec/public/controller/config/init.rb +6 -0
  108. data/spec/public/controller/controllers/authentication.rb +9 -11
  109. data/spec/public/controller/controllers/base.rb +2 -8
  110. data/spec/public/controller/controllers/cookies.rb +16 -0
  111. data/spec/public/controller/controllers/dispatcher.rb +35 -0
  112. data/spec/public/controller/controllers/display.rb +62 -14
  113. data/spec/public/controller/controllers/redirect.rb +36 -0
  114. data/spec/public/controller/controllers/responder.rb +37 -11
  115. data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
  116. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
  117. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
  118. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
  119. data/spec/public/controller/cookies_spec.rb +23 -0
  120. data/spec/public/controller/dispatcher_spec.rb +411 -0
  121. data/spec/public/controller/display_spec.rb +43 -10
  122. data/spec/public/controller/redirect_spec.rb +33 -0
  123. data/spec/public/controller/responder_spec.rb +79 -11
  124. data/spec/public/controller/spec_helper.rb +3 -1
  125. data/spec/public/controller/url_spec.rb +10 -0
  126. data/spec/public/core/merb_core_spec.rb +11 -0
  127. data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
  128. data/spec/public/core_ext/kernel_spec.rb +9 -0
  129. data/spec/public/core_ext/spec_helper.rb +1 -0
  130. data/spec/public/directory_structure/directory/log/merb_test.log +3729 -272
  131. data/spec/public/directory_structure/directory_spec.rb +3 -4
  132. data/spec/public/logger/logger_spec.rb +4 -4
  133. data/spec/public/reloading/directory/log/merb_test.log +288066 -15
  134. data/spec/public/reloading/reload_spec.rb +49 -27
  135. data/spec/public/request/multipart_spec.rb +26 -0
  136. data/spec/public/request/request_spec.rb +21 -2
  137. data/spec/public/router/fixation_spec.rb +27 -0
  138. data/spec/public/router/fixture/log/merb_test.log +30050 -0
  139. data/spec/public/router/nested_matches_spec.rb +97 -0
  140. data/spec/public/router/resource_spec.rb +1 -9
  141. data/spec/public/router/resources_spec.rb +0 -20
  142. data/spec/public/router/spec_helper.rb +27 -9
  143. data/spec/public/router/special_spec.rb +21 -8
  144. data/spec/public/template/template_spec.rb +17 -5
  145. data/spec/public/test/controller_matchers_spec.rb +10 -0
  146. data/spec/public/test/request_helper_spec.rb +29 -0
  147. data/spec/public/test/route_helper_spec.rb +18 -1
  148. data/spec/public/test/route_matchers_spec.rb +28 -1
  149. data/spec/public/test/view_matchers_spec.rb +3 -3
  150. data/spec/spec_helper.rb +56 -12
  151. metadata +89 -47
  152. data/lib/merb-core/core_ext/class.rb +0 -299
  153. data/lib/merb-core/core_ext/hash.rb +0 -426
  154. data/lib/merb-core/core_ext/mash.rb +0 -154
  155. data/lib/merb-core/core_ext/object.rb +0 -147
  156. data/lib/merb-core/core_ext/object_space.rb +0 -14
  157. data/lib/merb-core/core_ext/rubygems.rb +0 -28
  158. data/lib/merb-core/core_ext/set.rb +0 -46
  159. data/lib/merb-core/core_ext/string.rb +0 -89
  160. data/lib/merb-core/core_ext/time.rb +0 -13
  161. data/lib/merb-core/dispatch/exceptions.html.erb +0 -297
  162. data/spec/private/core_ext/class_spec.rb +0 -22
  163. data/spec/private/core_ext/hash_spec.rb +0 -522
  164. data/spec/private/core_ext/object_spec.rb +0 -121
  165. data/spec/private/core_ext/set_spec.rb +0 -26
  166. data/spec/private/core_ext/string_spec.rb +0 -167
  167. data/spec/private/core_ext/time_spec.rb +0 -16
  168. data/spec/private/dispatch/dispatch_spec.rb +0 -26
  169. data/spec/private/dispatch/fixture/log/development.log +0 -1
  170. data/spec/private/dispatch/fixture/log/merb.4000.pid +0 -1
  171. data/spec/private/dispatch/fixture/log/production.log +0 -1
  172. data/spec/private/dispatch/fixture/merb.4000.pid +0 -1
  173. data/spec/private/rack/application_spec.rb +0 -43
  174. data/spec/public/controller/log/merb.4000.pid +0 -1
  175. data/spec/public/directory_structure/directory/log/merb.4000.pid +0 -1
  176. data/spec/public/directory_structure/directory/merb.4000.pid +0 -1
  177. data/spec/public/reloading/directory/log/merb.4000.pid +0 -1
  178. data/spec/public/reloading/directory/merb.4000.pid +0 -1
@@ -1,13 +1,8 @@
1
- corelib = File.join(File.dirname(__FILE__), "core_ext")
2
-
3
- require "#{corelib}/string"
4
- require corelib/:time
5
- require corelib/:class
6
- require corelib/:hash
7
- require corelib/:kernel
8
- require corelib/:mash
9
- require corelib/:object
10
- require corelib/:object_space
11
- require corelib/:rubygems
12
- require corelib/:set
1
+ begin
2
+ require "extlib"
3
+ rescue LoadError => e
4
+ puts "Merb-core 0.9.4 and later uses extlib for Ruby core class extensions. Install it from github.com/sam/extlib."
5
+ exit
6
+ end
13
7
 
8
+ require File.dirname(__FILE__) / "core_ext" / "kernel"
@@ -1,29 +1,41 @@
1
1
  module Kernel
2
- # Loads the given string as a gem. Execution is deferred to
3
- # the Merb::BootLoader::Dependencies.run during bootup.
2
+ # Loads the given string as a gem. Execution is deferred until
3
+ # after the logger has been instantiated and the framework directory
4
+ # structure is defined.
4
5
  #
6
+ # If that has already happened, the gem will be activated
7
+ # immediately.
8
+ #
5
9
  # ==== Parameters
6
- # name<String>:: The name of the gem to load.
7
- # *ver<Gem::Requirement, Gem::Version, Array, ~to_str>::
10
+ # @param name<String> The name of the gem to load.
11
+ # @param *ver<Gem::Requirement, Gem::Version, Array, #to_str>
8
12
  # Version requirements to be passed to Gem.activate.
13
+ #
14
+ # ==== Returns
15
+ # Array[String, Array[Gem::Requirement, Gem::Version, Array, #to_str]]::
16
+ # The name and version information that was passed in.
9
17
  def dependency(name, *ver)
10
- Merb::BootLoader::Dependencies.dependencies << [name, ver]
18
+ if Merb::BootLoader.finished?(Merb::BootLoader::Dependencies)
19
+ load_dependency(name, *ver)
20
+ else
21
+ Merb::BootLoader::Dependencies.dependencies << [name, ver]
22
+ end
23
+ [name, ver]
11
24
  end
12
25
 
13
26
  # Loads the given string as a gem.
14
27
  #
15
- # ==== Parameters
16
- # name<String>:: The name of the gem to load.
17
- # *ver<Gem::Requirement, Gem::Version, Array, ~to_str>::
18
- # Version requirements to be passed to Gem.activate.
19
- #
20
- # ==== Notes
21
- # If the gem cannot be found, the method will attempt to require the string
22
- # as a library.
23
- #
24
28
  # This new version tries to load the file via ROOT/gems first before moving
25
29
  # off to the system gems (so if you have a lower version of a gem in
26
30
  # ROOT/gems, it'll still get loaded).
31
+ #
32
+ # @param name<String> The name of the gem to load.
33
+ # @param *ver<Gem::Requirement, Gem::Version, Array, #to_str>
34
+ # Version requirements to be passed to Gem.activate.
35
+ #
36
+ # @note
37
+ # If the gem cannot be found, the method will attempt to require the string
38
+ # as a library.
27
39
  def load_dependency(name, *ver)
28
40
  try_framework = Merb.frozen?
29
41
  begin
@@ -52,8 +64,7 @@ module Kernel
52
64
  # Loads both gem and library dependencies that are passed in as arguments.
53
65
  # Execution is deferred to the Merb::BootLoader::Dependencies.run during bootup.
54
66
  #
55
- # ==== Parameters
56
- # *args<String, Hash, Array>:: The dependencies to load.
67
+ # @param *args<String, Hash, Array> The dependencies to load.
57
68
  def dependencies(*args)
58
69
  args.each do |arg|
59
70
  case arg
@@ -66,20 +77,18 @@ module Kernel
66
77
 
67
78
  # Loads both gem and library dependencies that are passed in as arguments.
68
79
  #
69
- # ==== Parameters
70
- # *args<String, Hash, Array>:: The dependencies to load.
71
- #
72
- # ==== Notes
73
- # Each argument can be:
74
- # String:: Single dependency.
75
- # Hash::
76
- # Multiple dependencies where the keys are names and the values versions.
77
- # Array:: Multiple string dependencies.
78
- #
79
- # ==== Examples
80
- # dependencies "RedCloth" # Loads the the RedCloth gem
81
- # dependencies "RedCloth", "merb_helpers" # Loads RedCloth and merb_helpers
82
- # dependencies "RedCloth" => "3.0" # Loads RedCloth 3.0
80
+ # @param *args<String, Hash, Array> The dependencies to load.
81
+ #
82
+ # @note
83
+ # Each argument can be:
84
+ # String:: Single dependency.
85
+ # Hash::
86
+ # Multiple dependencies where the keys are names and the values versions.
87
+ # Array:: Multiple string dependencies.
88
+ #
89
+ # @example dependencies "RedCloth" # Loads the the RedCloth gem
90
+ # @example dependencies "RedCloth", "merb_helpers" # Loads RedCloth and merb_helpers
91
+ # @example dependencies "RedCloth" => "3.0" # Loads RedCloth 3.0
83
92
  def load_dependencies(*args)
84
93
  args.each do |arg|
85
94
  case arg
@@ -92,9 +101,8 @@ module Kernel
92
101
 
93
102
  # Does a basic require, and prints a message if an error occurs.
94
103
  #
95
- # ==== Parameters
96
- # library<~to_s>:: The library to attempt to include.
97
- # message<String>:: The error to add to the log upon failure. Defaults to nil.
104
+ # @param library<to_s> The library to attempt to include.
105
+ # @param message<String> The error to add to the log upon failure. Defaults to nil.
98
106
  def rescue_require(library, message = nil)
99
107
  require library
100
108
  rescue LoadError, RuntimeError
@@ -105,20 +113,19 @@ module Kernel
105
113
  # Mapper) you wish to use. Currently Merb has plugins to support
106
114
  # ActiveRecord, DataMapper, and Sequel.
107
115
  #
108
- # ==== Parameters
109
- # orm<~to_s>:: The ORM to use.
116
+ # @param orm<#to_s> The ORM to use.
110
117
  #
111
- # ==== Examples
112
- # # This line goes in dependencies.yml
118
+ # @example
113
119
  # use_orm :datamapper
114
120
  #
115
121
  # # This will use the DataMapper generator for your ORM
116
- # $ ruby script/generate model MyModel
122
+ # $ merb-gen model ActivityEvent
123
+ #
124
+ # @note
125
+ # If for some reason this is called more than once, latter
126
+ # call takes over other.
117
127
  def use_orm(orm)
118
- raise "Don't call use_orm more than once" if registred_orm?(orm)
119
-
120
128
  begin
121
- Merb.generator_scope.delete(:merb_default)
122
129
  register_orm(orm)
123
130
  orm_plugin = "merb_#{orm}"
124
131
  Kernel.dependency(orm_plugin)
@@ -128,46 +135,28 @@ module Kernel
128
135
  end
129
136
  end
130
137
 
131
- # Use to check whether given ORM already registred at generator scope
132
- #
133
- # ==== Parameters
134
- # orm<~to_sym>::
135
- # ORM alias, like :activerecord, :datamapper or :sequel.
136
- #
137
- # ==== Returns
138
- # Boolean::
139
- # true if ORM is already registred, false otherwise
140
- #
141
- #--
142
- # @semi-public
143
- def registred_orm?(orm)
144
- !Merb.generator_scope.include?(:merb_default) && !Merb.generator_scope.include?(orm.to_sym)
145
- end
146
138
 
147
139
  # Registers ORM at generator scope.
148
140
  #
149
- # ==== Parameters
150
- # orm<~to_sym>::
141
+ # @param orm<#to_sym>
151
142
  # ORM alias, like :activerecord, :datamapper or :sequel.
152
- #--
153
- # @private
143
+ #
144
+ # @api private
154
145
  def register_orm(orm)
155
- Merb.generator_scope.unshift(orm.to_sym) unless Merb.generator_scope.include?(orm.to_sym)
146
+ Merb.orm_generator_scope = orm
156
147
  end
157
148
 
158
149
  # Used in Merb.root/config/init.rb to tell Merb which testing framework to
159
150
  # use. Currently Merb has plugins to support RSpec and Test::Unit.
160
151
  #
161
- # ==== Parameters
162
- # test_framework<Symbol>::
152
+ # @param test_framework<Symbol>
163
153
  # The test framework to use. Currently only supports :rspec and :test_unit.
164
154
  #
165
- # ==== Examples
166
- # # This line goes in dependencies.yml
155
+ # @example
167
156
  # use_test :rspec
168
157
  #
169
158
  # # This will now use the RSpec generator for tests
170
- # $ ruby script/generate controller MyController
159
+ # $ merb-gen model ActivityEvent
171
160
  def use_test(test_framework, *test_dependencies)
172
161
  raise "use_test only supports :rspec and :test_unit currently" unless supported_test_framework?(test_framework)
173
162
  register_test_framework(test_framework)
@@ -177,112 +166,117 @@ module Kernel
177
166
 
178
167
  # Check whether Merb supports test framework. Currently Merb has plugins to support RSpec and Test::Unit.
179
168
  #
180
- # ==== Parameters
181
- # test_framework<Symbol>::
169
+ # @param test_framework<Symbol>
182
170
  # The test framework to check. Currently only supports :rspec and :test_unit.
183
- #--
184
- # @semi-public
171
+ #
172
+ # @api plugin
185
173
  def supported_test_framework?(test_framework)
186
174
  [:rspec, :test_unit].include?(test_framework.to_sym)
187
175
  end
188
176
 
189
177
  # Register test framework at generator scope. Currently Merb has plugins to support RSpec and Test::Unit.
190
178
  #
191
- # ==== Parameters
192
- # test_framework<Symbol>::
193
- # The test framework to check. Currently only supports :rspec and :test_unit but the check is performed before registration if you use API.
194
- #--
195
- # @private
179
+ # @param test_framework<Symbol>
180
+ # The test framework to check. Currently only supports :rspec and :test_unit but the
181
+ # check is performed before registration if you use API.
182
+ #
183
+ # @api private
196
184
  def register_test_framework(test_framework)
197
- Merb.generator_scope.delete(:rspec)
198
- Merb.generator_scope.delete(:test_unit)
199
-
200
- Merb.generator_scope.push(test_framework.to_sym)
185
+ Merb.test_framework_generator_scope = test_framework
201
186
  end
202
187
 
203
- # ==== Parameters
204
- # i<Fixnum>:: The caller number. Defaults to 1.
188
+ # @param i<Fixnum> The caller number. Defaults to 1.
205
189
  #
206
- # ==== Returns
207
- # Array[Array]:: The file, line and method of the caller.
190
+ # @return <Array[Array]> The file, line and method of the caller.
208
191
  #
209
- # ==== Examples
192
+ # @example
210
193
  # __caller_info__(1)
211
194
  # # => ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']
212
195
  def __caller_info__(i = 1)
213
196
  file, line, meth = caller[i].scan(/(.*?):(\d+):in `(.*?)'/).first
214
197
  end
215
198
 
216
- # ==== Parameters
217
- # file<String>:: The file to read.
218
- # line<Fixnum>:: The line number to look for.
219
- # size<Fixnum>::
199
+ # @param file<String> The file to read.
200
+ # @param line<Fixnum> The line number to look for.
201
+ # @param size<Fixnum>
220
202
  # Number of lines to include above and below the the line to look for.
221
203
  # Defaults to 4.
222
204
  #
223
- # ==== Returns
224
- # Array[Array]::
205
+ # @return <Array[Array]>
225
206
  # Triplets containing the line number, the line and whether this was the
226
207
  # searched line.
227
208
  #
228
- # ==== Examples
229
- # __caller_lines__('/usr/lib/ruby/1.8/debug.rb', 122, 2) # =>
230
- # [
231
- # [ 120, " def check_suspend", false ],
232
- # [ 121, " return if Thread.critical", false ],
233
- # [ 122, " while (Thread.critical = true; @suspend_next)", true ],
234
- # [ 123, " DEBUGGER__.waiting.push Thread.current", false ],
235
- # [ 124, " @suspend_next = false", false ]
236
- # ]
209
+ # @example
210
+ # __caller_lines__('/usr/lib/ruby/1.8/debug.rb', 122, 2) # =>
211
+ # [
212
+ # [ 120, " def check_suspend", false ],
213
+ # [ 121, " return if Thread.critical", false ],
214
+ # [ 122, " while (Thread.critical = true; @suspend_next)", true ],
215
+ # [ 123, " DEBUGGER__.waiting.push Thread.current", false ],
216
+ # [ 124, " @suspend_next = false", false ]
217
+ # ]
237
218
  def __caller_lines__(file, line, size = 4)
238
- return [['Template Error!', "problem while rendering", false]] if file =~ /\(erubis\)/
239
- lines = File.readlines(file)
240
- current = line.to_i - 1
241
-
242
- first = current - size
243
- first = first < 0 ? 0 : first
244
-
245
- last = current + size
246
- last = last > lines.size ? lines.size : last
247
-
248
- log = lines[first..last]
249
-
250
- area = []
251
-
252
- log.each_with_index do |line, index|
253
- index = index + first + 1
254
- area << [index, line.chomp, index == current + 1]
219
+ line = line.to_i
220
+ if file =~ /\(erubis\)/
221
+ yield :error, "Template Error! Problem while rendering", false
222
+ elsif !File.file?(file) || !File.readable?(file)
223
+ yield :error, "File `#{file}' not available", false
224
+ else
225
+ lines = File.read(file).split("\n")
226
+ first_line = (f = line - size - 1) < 0 ? 0 : f
227
+ lines = lines[first_line, size * 2 + 1]
228
+
229
+ lines.each_with_index do |str, index|
230
+ yield index + line - size, str.chomp
231
+ end
255
232
  end
256
-
257
- area
233
+ #
234
+ # lines = File.readlines(file)
235
+ # current = line.to_i - 1
236
+ #
237
+ # first = current - size
238
+ # first = first < 0 ? 0 : first
239
+ #
240
+ # last = current + size
241
+ # last = last > lines.size ? lines.size : last
242
+ #
243
+ # log = lines[first..last]
244
+ #
245
+ # area = []
246
+ #
247
+ # log.each_with_index do |line, index|
248
+ # index = index + first + 1
249
+ # area << [index, line.chomp, index == current + 1]
250
+ # end
251
+ #
252
+ # area
258
253
  end
259
254
 
260
255
  # Takes a block, profiles the results of running the block
261
256
  # specified number of times and generates HTML report.
262
257
  #
263
- # ==== Parameters
264
- # name<~to_s>::
258
+ # @param name<#to_s>
265
259
  # The file name. The result will be written out to
266
260
  # Merb.root/"log/#{name}.html".
267
- # min<Fixnum>::
261
+ # @param min<Fixnum>
268
262
  # Minimum percentage of the total time a method must take for it to be
269
263
  # included in the result. Defaults to 1.
270
264
  #
271
- # ==== Returns
272
- # String:: The result of the profiling.
265
+ # @return <String>
266
+ # The result of the profiling.
273
267
  #
274
- # ==== Notes
275
- # Requires ruby-prof (<tt>sudo gem install ruby-prof</tt>)
268
+ # @note
269
+ # Requires ruby-prof (<tt>sudo gem install ruby-prof</tt>)
276
270
  #
277
- # ==== Examples
271
+ # @example
278
272
  # __profile__("MyProfile", 5, 30) do
279
273
  # rand(10)**rand(10)
280
274
  # puts "Profile run"
281
275
  # end
282
276
  #
283
- # Assuming that the total time taken for #puts calls was less than 5% of the
284
- # total time to run, #puts won't appear in the profile report.
285
- # The code block will be run 30 times in the example above.
277
+ # Assuming that the total time taken for #puts calls was less than 5% of the
278
+ # total time to run, #puts won't appear in the profile report.
279
+ # The code block will be run 30 times in the example above.
286
280
  def __profile__(name, min=1, iter=100)
287
281
  require 'ruby-prof' unless defined?(RubyProf)
288
282
  return_result = ''
@@ -301,10 +295,9 @@ module Kernel
301
295
  # Extracts an options hash if it is the last item in the args array. Used
302
296
  # internally in methods that take *args.
303
297
  #
304
- # ==== Parameters
305
- # args<Array>:: The arguments to extract the hash from.
298
+ # @param args<Array> The arguments to extract the hash from.
306
299
  #
307
- # ==== Examples
300
+ # @example
308
301
  # def render(*args,&blk)
309
302
  # opts = extract_options_from_args!(args) || {}
310
303
  # # [...]
@@ -315,13 +308,12 @@ module Kernel
315
308
 
316
309
  # Checks that the given objects quack like the given conditions.
317
310
  #
318
- # ==== Parameters
319
- # opts<Hash>::
311
+ # @param opts<Hash>
320
312
  # Conditions to enforce. Each key will receive a quacks_like? call with the
321
313
  # value (see Object#quacks_like? for details).
322
314
  #
323
- # ==== Raises
324
- # ArgumentError:: An object failed to quack like a condition.
315
+ # @raise <ArgumentError>
316
+ # An object failed to quack like a condition.
325
317
  def enforce!(opts = {})
326
318
  opts.each do |k,v|
327
319
  raise ArgumentError, "#{k.inspect} doesn't quack like #{v.inspect}" unless k.quacks_like?(v)
@@ -32,6 +32,8 @@ module Merb
32
32
  # :value<~to_s>:: Value of the cookie
33
33
  # :path<String>:: The path for which this cookie applies. Defaults to "/".
34
34
  # :expires<Time>:: Cookie expiry date.
35
+ # :domain<String>:: The domain for which this cookie applies.
36
+ # :secure<Boolean>:: Security flag.
35
37
  #
36
38
  # ==== Alternatives
37
39
  # If options is not a hash, it will be used as the cookie value directly.
@@ -65,6 +67,11 @@ module Merb
65
67
  cookie = @_cookies.delete(name)
66
68
  options = Mash.new(options)
67
69
  options[:expires] = Time.at(0)
70
+
71
+ if domain = options[:domain] || Merb::Controller._session_cookie_domain
72
+ options[:domain] = domain
73
+ end
74
+
68
75
  set_cookie(name, "", options)
69
76
  Merb.logger.info("Cookie deleted: #{name} => #{cookie.inspect}")
70
77
  cookie
@@ -78,14 +85,29 @@ module Merb
78
85
  # ==== Options (options)
79
86
  # :path<String>:: The path for which this cookie applies. Defaults to "/".
80
87
  # :expires<Time>:: Cookie expiry date.
88
+ # :domain<String>:: The domain for which this cookie applies.
89
+ # :secure<Boolean>:: Security flag.
81
90
  def set_cookie(name, value, options)
82
91
  options[:path] = '/' unless options[:path]
83
92
  if expiry = options[:expires]
84
93
  options[:expires] = expiry.gmtime.strftime(Merb::Const::COOKIE_EXPIRATION_FORMAT)
85
94
  end
86
- # options are sorted for testing purposes
87
- (@_headers['Set-Cookie'] ||=[]) << "#{name}=#{value}; " +
88
- options.map{|k, v| "#{k}=#{v};"}.sort.join(' ')
95
+
96
+ if domain = options[:domain] || Merb::Controller._session_cookie_domain
97
+ options[:domain] = domain
98
+ end
99
+
100
+ secure = options.delete(:secure)
101
+
102
+ @_headers['Set-Cookie'] ||=[]
103
+
104
+ kookie = "#{name}=#{value}; "
105
+ # options are sorted for testing purposes:
106
+ # Hash is unsorted so string is spec is random every run
107
+ kookie << options.map{|k, v| "#{k}=#{v};"}.join(' ')
108
+ kookie << ' secure' if secure
109
+
110
+ @_headers['Set-Cookie'] << kookie
89
111
  end
90
112
  end
91
- end
113
+ end