merb-core 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,8 +35,53 @@ module Merb
35
35
  class NotCompiledError < StandardError; end;
36
36
 
37
37
  class << self
38
- # @private
39
- attr_accessor :routes, :named_routes, :resource_routes, :root_behavior
38
+ # An array containing all the application routes in order of
39
+ # priority.
40
+ # ---
41
+ # @api private
42
+ attr_accessor :routes
43
+
44
+ # A hash containing all the named application routes. The names
45
+ # are absolute (as in, all routes named in a namespace will
46
+ # contain the name of the namespace).
47
+ # ---
48
+ # @api private
49
+ attr_accessor :named_routes
50
+
51
+ # A hash of all the application resource routes. The key of the hash
52
+ # is an array with each element containing the "path" for the resource
53
+ # for example, given the following resource routes:
54
+ #
55
+ # resources :users do
56
+ # resources :comments
57
+ # end
58
+ #
59
+ # The show comment route will have a key of ["User", "Comment"]
60
+ # ---
61
+ # @api private
62
+ attr_accessor :resource_routes
63
+
64
+ # The starting point for route definition. Any route defined in a
65
+ # Merb::Router.prepare block will defined in context of this
66
+ # behavior.
67
+ #
68
+ # ==== Examples
69
+ #
70
+ # Merb::Router.root_behavior = Merb::Router.root_bavior.match("/hello")
71
+ #
72
+ # In the previous example, all routes will have the path prefix /hello.
73
+ # It is important to note that this attribute must be set before any
74
+ # routes are defined in order for the behavior to be applied to the
75
+ # routes.
76
+ # ---
77
+ # @api plugin
78
+ attr_accessor :root_behavior
79
+
80
+ # A block that will be run around route matching. This block must yield
81
+ # in order for the actual matching to happen.
82
+ # ---
83
+ # @api plugin
84
+ attr_accessor :around_match
40
85
 
41
86
  # Creates a route building context and evaluates the block in it. A
42
87
  # copy of +root_behavior+ (and instance of Behavior) is copied as
@@ -53,7 +98,7 @@ module Merb
53
98
  # ==== Returns
54
99
  # Merb::Router::
55
100
  # Returns self to allow chaining of methods.
56
- #
101
+ # ---
57
102
  # @api public
58
103
  def prepare(first = [], last = [], &block)
59
104
  @routes = []
@@ -63,20 +108,6 @@ module Merb
63
108
  self
64
109
  end
65
110
 
66
- # Appends route in the block to routing table.
67
- #
68
- # @api public
69
- def append(&block)
70
- prepare(routes, [], &block)
71
- end
72
-
73
- # Prepends routes in the block to routing table.
74
- #
75
- # @api public
76
- def prepend(&block)
77
- prepare([], routes, &block)
78
- end
79
-
80
111
  # Clears the routing table. Route generation and request matching
81
112
  # won't work anymore until a new routing table is built.
82
113
  #
@@ -85,7 +116,7 @@ module Merb
85
116
  class << self
86
117
  alias_method :match, :match_before_compilation
87
118
  end
88
- self.routes, self.named_routes = [], {}
119
+ self.routes, self.named_routes, self.resource_routes = [], {}, {}
89
120
  end
90
121
 
91
122
  # Finds route matching URI of the request and returns a tuple of
@@ -101,8 +132,12 @@ module Merb
101
132
  # are :controller, :action and all the named segments of the route.
102
133
  #
103
134
  # @api private
104
- def route_for(request) #:nodoc:
105
- index, params = match(request)
135
+ def route_for(request)
136
+ index, params = if @around_match
137
+ send(@around_match, request) { match(request) }
138
+ else
139
+ match(request)
140
+ end
106
141
  route = routes[index] if index
107
142
  if !route
108
143
  raise ControllerExceptions::NotFound,
@@ -181,8 +216,8 @@ module Merb
181
216
  # end
182
217
  #
183
218
  # url(:articles, 2008, 10, "test_article")
184
- #
185
- # @api private
219
+ # ---
220
+ # @api plugin
186
221
  def url(name, *args)
187
222
  unless name.is_a?(Symbol)
188
223
  args.unshift(name)
@@ -211,8 +246,8 @@ module Merb
211
246
  #
212
247
  # ==== Returns
213
248
  # String:: The generated URL
214
- #
215
- # @api private
249
+ # ---
250
+ # @api plugin
216
251
  def resource(*args)
217
252
  defaults = args.pop
218
253
  options = extract_options_from_args!(args) || {}
@@ -266,7 +301,7 @@ module Merb
266
301
  # # ... routes come here ...
267
302
  # end
268
303
  # end
269
- #
304
+ # ---
270
305
  # @api public
271
306
  def extensions(&block)
272
307
  Router::Behavior.class_eval(&block)
@@ -275,7 +310,7 @@ module Merb
275
310
  private
276
311
 
277
312
  # Compiles the routes and creates the +match+ method.
278
- #
313
+ # ---
279
314
  # @api private
280
315
  def compile
281
316
  if routes.any?
@@ -287,7 +322,7 @@ module Merb
287
322
 
288
323
  # Generates the method for evaluation defining a +match+ method to match
289
324
  # a request with the defined routes.
290
- #
325
+ # ---
291
326
  # @api private
292
327
  def compiled_statement
293
328
  @compiler_mutex.synchronize do
@@ -73,19 +73,22 @@ module Merb
73
73
  match_opts = options.except(*resource_options)
74
74
  options = options.only(*resource_options)
75
75
  singular = options[:singular] ? options[:singular].to_s : Extlib::Inflection.singularize(name)
76
- klass_name = args.first ? args.first.to_s : Extlib::Inflection.classify(singular)
77
- klass = Object.full_const_get(klass_name) rescue nil
76
+ klass_name = args.first ? args.first.to_s : singular.to_const_string
78
77
  keys = options.delete(:keys) || options.delete(:key)
79
78
  params = { :controller => options.delete(:controller) || name }
80
79
  collection = options.delete(:collection) || {}
81
80
  member = { :edit => :get, :delete => :get }.merge(options.delete(:member) || {})
82
81
 
83
82
  # Use the identifier for the class as a default
84
- if klass
85
- keys ||= options[:identify]
86
- keys ||= @identifiers[klass]
87
- elsif options[:identify]
88
- raise Error, "The constant #{klass_name} does not exist, please specify the constant for this resource"
83
+ begin
84
+ if klass = Object.full_const_get(klass_name)
85
+ keys ||= options[:identify]
86
+ keys ||= @identifiers[klass]
87
+ elsif options[:identify]
88
+ raise Error, "The constant #{klass_name} does not exist, please specify the constant for this resource"
89
+ end
90
+ rescue NameError => e
91
+ Merb.logger.debug!("Could not find resource model #{klass_name}")
89
92
  end
90
93
 
91
94
  keys = [ keys || :id ].flatten
@@ -424,6 +424,8 @@ module Merb
424
424
  segments << match[2].intern
425
425
  path = match.post_match
426
426
  end
427
+
428
+ raise Router::Behavior::Error, "cannot use :path as a route placeholder" if segments.include?(:path)
427
429
 
428
430
  segments << path unless path.empty?
429
431
  segments
@@ -19,7 +19,7 @@ module Merb
19
19
  end # Config
20
20
 
21
21
  # The Merb::Session module gets mixed into Merb::SessionContainer to allow
22
- # app-level functionality (usually found in app/models/merb/session.rb) for
22
+ # app-level functionality (usually found in ./merb/session/session.rb) for
23
23
  # session.
24
24
  #
25
25
  # You can use this module to implement additional methods to simplify
@@ -38,7 +38,7 @@ module Merb
38
38
  # session data; min. 16 chars
39
39
  #
40
40
  # :default_cookie_domain The default domain to write cookies for.
41
- module Session
41
+ module Session
42
42
  end
43
43
 
44
44
  # This is mixed into Merb::Controller on framework boot.
@@ -154,7 +154,7 @@ module Merb
154
154
  Merb::Server.remove_pid(port)
155
155
  end
156
156
 
157
- Merb::Worker.start
157
+ Merb::Worker.start unless Merb.testing?
158
158
 
159
159
  # If Merb is daemonized, trap INT. If it's not daemonized,
160
160
  # we let the master process' ctrl-c control the cluster
@@ -189,7 +189,7 @@ module GemManagement
189
189
  options[:version] = Gem::Requirement.new ["= #{options[:version]}"]
190
190
  end
191
191
  update_source_index(options[:install_dir]) if options[:install_dir]
192
- Gem::Uninstaller.new(gem, options).uninstall
192
+ Gem::Uninstaller.new(gem, options).uninstall rescue nil
193
193
  end
194
194
 
195
195
  def clobber(source_dir)
@@ -251,7 +251,7 @@ module GemManagement
251
251
  gemspecs = ::Gem.source_index.search(dep)
252
252
  local = gemspecs.reverse.find { |s| s.loaded_from.index(gem_dir) == 0 }
253
253
  if local
254
- local_specs << local
254
+ local_specs << local
255
255
  elsif gemspecs.last
256
256
  system_specs << gemspecs.last
257
257
  else
@@ -259,6 +259,15 @@ module GemManagement
259
259
  end
260
260
  end
261
261
  ::Gem.clear_paths
262
+ else
263
+ dependencies.each do |dep|
264
+ gemspecs = ::Gem.source_index.search(dep)
265
+ if gemspecs.last
266
+ system_specs << gemspecs.last
267
+ else
268
+ missing_deps << dep
269
+ end
270
+ end
262
271
  end
263
272
  [system_specs, local_specs, missing_deps]
264
273
  end
@@ -307,9 +316,12 @@ end
307
316
  if File.directory?(gems_dir = File.join(Dir.pwd, 'gems')) ||
308
317
  File.directory?(gems_dir = File.join(File.dirname(__FILE__), '..', 'gems'))
309
318
  $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(gems_dir)
319
+ if (local_gem = Dir[File.join(gems_dir, "specifications", "#{spec.name}-*.gemspec")].last)
320
+ version = File.basename(local_gem)[/-([\\.\\d]+)\\.gemspec$/, 1]
321
+ end
310
322
  end
311
323
 
312
- version = "#{Gem::Requirement.default}"
324
+ version ||= "#{Gem::Requirement.default}"
313
325
 
314
326
  if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
315
327
  version = $1
@@ -51,6 +51,10 @@ module Merb
51
51
 
52
52
  @__cookie__ = rack.headers["Set-Cookie"] && rack.headers["Set-Cookie"].join
53
53
 
54
+ Merb::Dispatcher.work_queue.size.times do
55
+ Merb::Dispatcher.work_queue.pop.call
56
+ end
57
+
54
58
  rack
55
59
  end
56
60
  alias requesting request
@@ -28,6 +28,16 @@ namespace :spec do
28
28
  end
29
29
  end
30
30
 
31
+ desc "Run all request specs, run a spec for a specific Request with REQUEST=MyRequest"
32
+ Spec::Rake::SpecTask.new('request') do |t|
33
+ t.spec_opts = SPEC_OPTS
34
+ if(ENV['REQUEST'])
35
+ t.spec_files = Dir["spec/requests/**/#{ENV['REQUEST']}_spec.rb"].sort
36
+ else
37
+ t.spec_files = Dir['spec/requests/**/*_spec.rb'].sort
38
+ end
39
+ end
40
+
31
41
  desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
32
42
  Spec::Rake::SpecTask.new('controller') do |t|
33
43
  t.spec_opts = SPEC_OPTS
@@ -42,11 +42,6 @@ module Merb
42
42
  include ::Merb::Test::RouteHelper
43
43
  include ::Merb::Test::ControllerHelper
44
44
 
45
- def initialize(defined_description, &implementation)
46
- @_defined_description = defined_description
47
- @_implementation = implementation
48
- end
49
-
50
45
  class << self
51
46
  # This is a copy of the method in rspec, so we can have
52
47
  # describe "...", :when => "logged in", and the like
@@ -1,3 +1,3 @@
1
1
  module Merb
2
- VERSION = '0.9.9' unless defined?(Merb::VERSION)
2
+ VERSION = '0.9.10' unless defined?(Merb::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-13 00:00:00 +03:00
12
+ date: 2008-10-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: "0"
33
+ version: 2.6.2
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rake
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  requirements:
256
256
  - install the json gem to get faster json parsing
257
257
  rubyforge_project:
258
- rubygems_version: 1.2.0
258
+ rubygems_version: 1.3.0
259
259
  signing_key:
260
260
  specification_version: 2
261
261
  summary: Merb. Pocket rocket web framework.