public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Merge branch 'master' of git@github.com:wycats/merb-core
ezmobius (author)
Thu May 15 19:27:22 -0700 2008
commit  151989977c12c9c37bc5fa46163887d6a2ab6c4c
tree    e7fa4cc10795ead30f2b0350c29e42343bcbfd07
parent  5e1941211a2cde5e4d9f18c84251806b373ed49a parent  c903c92bb1fe1054c3f2ad7e7a748d1525300fc8
...
115
116
117
118
 
119
120
121
122
123
124
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
152
153
154
 
155
156
157
...
115
116
117
 
118
119
120
 
121
122
123
...
127
128
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
131
132
...
136
137
138
139
140
141
142
0
@@ -115,10 +115,9 @@
0
   # # This will use the DataMapper generator for your ORM
0
   # $ ruby script/generate model MyModel
0
   def use_orm(orm)
0
- raise "Don't call use_orm more than once" if registred_orm?(orm)
0
+ raise "Don't call use_orm more than once" unless Merb.generator_scope.include?(:merb_default)
0
 
0
     begin
0
- Merb.generator_scope.delete(:merb_default)
0
       register_orm(orm)
0
       orm_plugin = "merb_#{orm}"
0
       Kernel.dependency(orm_plugin)
0
@@ -128,21 +127,6 @@
0
     end
0
   end
0
 
0
- # Use to check whether given ORM already registred at generator scope
0
- #
0
- # ==== Parameters
0
- # orm<~to_sym>::
0
- # ORM alias, like :activerecord, :datamapper or :sequel.
0
- #
0
- # ==== Returns
0
- # Boolean::
0
- # true if ORM is already registred, false otherwise
0
- #
0
- #--
0
- # @semi-public
0
- def registred_orm?(orm)
0
- !Merb.generator_scope.include?(:merb_default) && !Merb.generator_scope.include?(orm.to_sym)
0
- end
0
 
0
   # Registers ORM at generator scope.
0
   #
0
@@ -152,6 +136,7 @@
0
   #--
0
   # @private
0
   def register_orm(orm)
0
+ Merb.generator_scope.delete(:merb_default)
0
     Merb.generator_scope.unshift(orm.to_sym) unless Merb.generator_scope.include?(orm.to_sym)
0
   end
0
 
...
108
109
110
111
112
 
 
 
 
113
114
115
116
...
124
125
126
127
128
 
 
 
129
130
131
132
133
134
135
136
137
138
139
140
141
...
286
287
288
289
 
290
291
292
293
 
294
295
296
297
...
470
471
472
473
 
474
475
476
477
 
478
479
480
...
584
585
586
 
 
 
 
 
 
 
 
 
 
 
 
 
587
588
589
...
108
109
110
 
 
111
112
113
114
115
116
117
118
...
126
127
128
 
 
129
130
131
132
133
134
135
 
 
 
 
 
136
137
138
139
...
284
285
286
 
287
288
289
290
 
291
292
293
294
295
...
468
469
470
 
471
472
473
474
 
475
476
477
478
...
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
0
@@ -108,8 +108,10 @@
0
       # within the regular expression syntax.
0
       # +path+ is optional.
0
       # conditions<Hash>::
0
- # This optional hash helps refine the settings for the route.
0
- # When combined with a block it can help keep your routes DRY
0
+ # Addational conditions that the request must meet in order to match.
0
+ # the keys must be methods that the Merb::Request instance will respond
0
+ # to. The value is the string or regexp that matched the returned value.
0
+ # Conditions are inherited by child routes.
0
       # &block::
0
       # Passes a new instance of a Behavior object into the optional block so
0
       # that sub-matching and routes nesting may occur.
0
0
@@ -124,17 +126,13 @@
0
       # ==== Examples
0
       #
0
       # # registers /foo/bar to controller => "foo", :action => "bar"
0
- # # and /foo/baz to controller => "foo", :action => "caz"
0
- # r.match "/foo", :controller => "foo" do |f|
0
+ # # and /foo/baz to controller => "foo", :action => "baz"
0
+ # r.match "/foo" do |f|
0
+ # f.params[:controller] = 'foo'
0
       # f.match("/bar").to(:action => "bar")
0
       # f.match("/baz").to(:action => "caz")
0
       # end
0
       #
0
- # r.match "/foo", :controller => "foo" do |f|
0
- # f.match("/bar", :action => "bar")
0
- # f.match("/baz", :action => "caz")
0
- # end # => doesn't register any routes at all
0
- #
0
       # # match also takes regular expressions
0
       # r.match(%r[/account/([a-z]{4,6})]).to(:controller => "account",
0
       # :action => "show", :id => "[1]")
0
0
@@ -286,11 +284,11 @@
0
       # admin.resources :accounts
0
       # admin.resource :email
0
       # end
0
- #
0
+ #
0
       # # /super_admin/accounts
0
       # r.namespace(:admin, :path=>"super_admin") do |admin|
0
       # admin.resources :accounts
0
- # end
0
+ # end
0
       #---
0
       # @public
0
       def namespace(name_or_path, options={}, &block)
0
0
@@ -470,11 +468,11 @@
0
         if name_prefix.nil? && !namespace.nil?
0
           name_prefix = namespace_to_name_prefix namespace
0
         end
0
-
0
+
0
         unless @@parent_resource.empty?
0
           parent_resource = namespace_to_name_prefix @@parent_resource.join('_')
0
         end
0
-
0
+
0
         routes = next_level.to_resource options
0
 
0
         route_name = "#{name_prefix}#{name}"
0
@@ -584,6 +582,19 @@
0
       # Boolean:: True if this behavior has a regexp.
0
       def regexp?
0
         @conditions_have_regexp
0
+ end
0
+
0
+ def redirect(url, permanent = true)
0
+ @redirects = true
0
+ @redirect_url = url
0
+ @redirect_status = permanent ? 301 : 302
0
+
0
+ # satisfy route compilation
0
+ self.to({})
0
+ end
0
+
0
+ def redirects?
0
+ @redirects
0
       end
0
 
0
     protected
...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
97
98
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
101
102
0
@@ -97,26 +97,6 @@
0
 
0
 
0
 
0
-describe "Plugins", "registred_orm?" do
0
- before(:each) do
0
- Merb.generator_scope.replace [:merb_default, :merb, :rspec]
0
- Kernel.stub!(:dependency)
0
- end
0
-
0
- it "returns false unless ORM is registred" do
0
- registred_orm?(:sequel).should be(false)
0
- end
0
-
0
- it "returns true once ORM is registred" do
0
- use_orm(:sequel)
0
-
0
- registred_orm?(:sequel).should be(false)
0
- end
0
-end
0
-
0
-
0
-
0
-
0
 describe "Plugins", "register_test_framework" do
0
   before(:each) do
0
     Merb.generator_scope.replace [:merb_default, :merb, :rspec]
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
0
@@ -1 +1,57 @@
0
+require File.dirname(__FILE__) + '/../../spec_helper'
0
+require 'ostruct'
0
+require 'rack/mock'
0
+require 'stringio'
0
+Merb.start :environment => 'test',
0
+ :merb_root => File.dirname(__FILE__) / 'fixture'
0
+
0
+
0
+class SimpleRequest < OpenStruct
0
+ def method
0
+ @table[:method]
0
+ end
0
+
0
+ def params
0
+ @table
0
+ end
0
+end
0
+
0
+def match_for(path, args = {}, protocol = "http://")
0
+ Merb::Router.match(SimpleRequest.new({:protocol => protocol, :path => path}.merge(args)))
0
+end
0
+
0
+def matched_route_for(*args)
0
+ # get route index
0
+ idx = match_for(*args)[0]
0
+
0
+ Merb::Router.routes[idx]
0
+end
0
+
0
+describe Merb::Router::Behavior, "#redirect" do
0
+ predicate_matchers[:redirect] = :redirects?
0
+
0
+ before :each do
0
+ Merb::Router.prepare do |r|
0
+ r.match('/old/location').redirect("/new/location", true)
0
+ end
0
+ end
0
+
0
+ it "makes route redirecting" do
0
+ @behavior = matched_route_for("/old/location").behavior
0
+ @behavior.should redirect
0
+ end
0
+end
0
+
0
+describe Merb::Dispatcher do
0
+ before :each do
0
+ Merb::Router.prepare do |r|
0
+ r.match('/old/location').redirect("/new/location", true)
0
+ end
0
+ end
0
+
0
+ it "redirects right away if route is redirecting" do
0
+ env = Rack::MockRequest.env_for("/old/location")
0
+ puts Merb::Dispatcher.handle(env).inspect
0
+ end
0
+end
...
1
2
 
 
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -1,5 +1,12 @@
0
 require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
0
 require 'ostruct'
0
+
0
+require 'rack/mock'
0
+require 'stringio'
0
+Merb.start :environment => 'test',
0
+ :merb_root => File.dirname(__FILE__) / 'fixture'
0
+
0
+
0
 class SimpleRequest < OpenStruct
0
 
0
   def method

Comments

    No one has commented yet.