Commit Graph

12725 Commits

Author SHA1 Message Date
Marcin Olichwirowicz
00234f5619 Get rid of mocha tests - part 2 2015-08-25 09:28:06 +02:00
Rafael Mendonça França
f3e68ec16a Merge pull request #21094 from aditya-kapoor/add-missing-ap-tests
add missing test for action regexp for routing
2015-08-25 03:10:23 -03:00
Anshul Sharma
7b1c783630 Remove unused block arguments 2015-08-25 09:31:12 +05:30
amitkumarsuroliya
65c4076927 Remove unused block arguments 2015-08-25 07:49:47 +05:30
Aaron Patterson
c82248ea86 remove more direct env mutations 2015-08-24 17:07:48 -07:00
Aaron Patterson
d4e1f58fd8 remove another @env access 2015-08-24 16:39:47 -07:00
Aaron Patterson
cccc759ff7 remove more direct access to env 2015-08-24 16:14:42 -07:00
Aaron Patterson
a1ff5585bd fewer calls to env
We don't want to directly access the env hash
2015-08-24 15:59:30 -07:00
Aaron Patterson
c4c5918b68 stop using @env in the GET / POST methods
I want to implement this with something besides `@env` in the future, so
lets stop directly referencing it.
2015-08-24 14:57:05 -07:00
Aaron Patterson
ec9c237acc rm useless method
superclass already has this method, so remove this one
2015-08-24 14:21:27 -07:00
Aaron Patterson
7a62cc7d22 remove dead code 💣 2015-08-24 14:11:37 -07:00
Aaron Patterson
9b20b1cc0f pull up dispatcher allocation
the dispatcher class isn't configurable anymore, so pull up allocation
to the method that needs it.
2015-08-24 14:05:54 -07:00
Aaron Patterson
59e3b648c3 directly ask the request for the controller class
Now that we don't have subclasses depending on this method (they augment
the request class instead of the dispatch class) we can remove this
method and directly ask the request object for the controller class
2015-08-24 14:01:11 -07:00
Aaron Patterson
74020eb255 use make_set helper method to generate route sets
We should keep the route set generation logic in one place
2015-08-24 13:59:40 -07:00
Aaron Patterson
b0e7db9ad9 remove useless ivar 2015-08-24 13:49:52 -07:00
Aaron Patterson
31cc4d621f remove setter for the dispatcher class
we don't need it anymore.  We always use the same dispatcher in tests.
2015-08-24 13:49:52 -07:00
Aaron Patterson
2237ee0596 subclass and delegate rather than mutating existing objects
If we subclass and augment the superclass, then we don't need to have
setters for particular things on the superclass.
2015-08-24 13:49:52 -07:00
Gaurav Sharma
a50872d51d temp files are no more require
`💅`
2015-08-25 01:36:05 +05:30
Aaron Patterson
337684fa28 use a custom request class to determine the controller class
controller class resolution has been moved to the request object, so we
should override that method instead of relying on the RouteSet to
generate the controller class.
2015-08-24 12:06:41 -07:00
Carlos Antonio da Silva
35decf4b6b Merge pull request #21339 from deepj/unused-block-arguments
Remove unused block arguments
2015-08-24 13:40:03 -03:00
Rafael Mendonça França
9e5ba3c86b Merge pull request #21355 from akihiro17/remove-variables
Remove unused variables
2015-08-24 13:36:10 -03:00
Kasper Timm Hansen
b9825801e2 Merge pull request #21321 from rodzyn/removing_mocha
Get rid of mocha tests in actionpack - part 1
2015-08-24 12:44:01 +02:00
Marcin Olichwirowicz
3a161e65e7 Get rid of mocha tests - part 1 2015-08-24 12:24:07 +02:00
akihiro17
7adef79e14 Remove unused variables 2015-08-24 17:33:19 +09:00
Aaron Patterson
9503e65b97 use methods on the request object instead of accessing env 2015-08-23 17:25:13 -07:00
Aaron Patterson
71d0b61f3a use Request#path_info instead of direct ENV access
we already have a request, so we should use the methods on the request
to access the path info information
2015-08-23 17:22:21 -07:00
Aaron Patterson
feb248ca76 remove env access from debug_exceptions
Creates fewer request objects and helps to abstract away from internals
2015-08-23 17:18:02 -07:00
Aaron Patterson
f16a33b68e remove more env access 2015-08-23 17:09:13 -07:00
Aaron Patterson
97c65aa144 remove more env access 2015-08-23 16:53:41 -07:00
Aaron Patterson
7de86d2cf3 remove more env access 2015-08-23 16:48:37 -07:00
Aaron Patterson
a682b44e70 convert more @env access to get / set header 2015-08-23 16:36:43 -07:00
Aaron Patterson
f038ed2d2a remove usage of @env
try to remove dependencies on `@env` so we can have more flexible
internals
2015-08-23 16:16:28 -07:00
Aditya Kapoor
b393c6af92 Trim out unneeded controllers from AP test suite 2015-08-24 01:02:14 +05:30
deepj
dbfab58457 Remove unused block arguments 2015-08-23 16:06:29 +02:00
Ronak Jangir
688bcc8e5b Another place to use a request object in NullSessionHash
May be missed in 5fe141638f1243ac6ae187ae14aa398b4c1875a2 commit
Also fixes the broken build
2015-08-23 19:11:37 +05:30
Aaron Patterson
5fe141638f use a request object in the session middleware
This commit allows us to use one request object rather than allocating
multiple request objects to deal with the session.
2015-08-22 17:57:45 -07:00
Aaron Patterson
4f244f7cab move more @env access to method calls
We're going to implement storing env values differently in the future,
so let's disconnect these methods from the instance variables
2015-08-22 16:01:53 -07:00
Aaron Patterson
3ca8f91543 move ORIGINAL_SCRIPT_NAME to the metaprogrammed methods 2015-08-22 15:56:08 -07:00
Aaron Patterson
39837b1709 metaprogram the HTTP_X_REQUEST_ID method
we're already doing this with a bunch of other header data.
2015-08-22 15:52:50 -07:00
Aaron Patterson
64f6dc6daf use body_stream instead of getting the env value ourselves
we have a method that knows how to get rack.input, so lets use that.
2015-08-22 15:52:15 -07:00
Aaron Patterson
3e0b9326f9 convert @env use to get / set header
We need to abstract the internals of the request object away from this
instance variable so that the values for `@env` can be calculated in a
different way.
2015-08-22 15:50:15 -07:00
Aaron Patterson
383f18b9ec use get / set header to avoid depending on the env ivar 2015-08-22 15:40:43 -07:00
eileencodes
f15a2609cb Fix Railties test failure for asset routes
Since none of the action pack tests failed without this conditional it
didn't seem necessary. This fixes the build because it correctly returns
a 404 instead of a 500 for the asset routes test.

Test that was failing was in the `assets_test.rb` file and was the test
named `test_assets_routes_are_not_drawn_when_compilation_is_disabled`.
2015-08-22 12:30:58 -04:00
eileencodes
4276b214f8 Refactor to remove controller class from route to request
This refactoring moves the controller class name that was on the route
set to the request. The purpose of this refactoring is for changes we
need to move controller tests to integration tests, mainly being able to
access the controller on the request instead of having to go through
the router.

[Eileen M. Uchitelle & Aaron Patterson]
2015-08-22 09:44:24 -04:00
Aaron Patterson
ec760e67fd set cached values in the env hash 2015-08-21 17:22:44 -07:00
Aaron Patterson
7bd34c107a stop directly accessing @env in mime_negotiation
we want to go through methods to access `env` because in the future that
ivar may not be available, or may be calculated lazily
2015-08-21 17:15:21 -07:00
Aaron Patterson
992bf079e8 use public API to fetch the parameter filter
now the parameter filter doesn't need to know about the env hash in
these two methds.
2015-08-21 17:08:24 -07:00
Aaron Patterson
bce4ff70dd use methods on the request object to implement fetch
Now the Headers internals don't depend on the env hash.
2015-08-21 16:59:13 -07:00
Aaron Patterson
c0c726849b dup the env hash on Header#env
This prevents external mutations from impacting the internals of the
request or the Header object.
2015-08-21 16:59:13 -07:00
Aaron Patterson
fbf6b98c95 use accessors on the request object for manipulating env
this reduces the API footprint for the env hash so that we can be more
flexible when changing API in the future
2015-08-21 16:59:12 -07:00
Aaron Patterson
ba2173a10d use set_header rather than []=
This allows us to avoid calling `env_name` twice.
2015-08-21 16:59:12 -07:00
Aaron Patterson
1fbf5ad7f7 dup the request and mutate its headers object.
duping the request will dup it's underlying env hash.
2015-08-21 16:59:12 -07:00
eileencodes
ec9c6d5846 Remove unnecessary caching
`ActiveSupport::Dependencies.constantize(const_name)` calls
`Reference.new` which is defined as
`ActiveSupport::Dependencies.constantize(const_name)` meaning this call
is already cached and we're doing caching that isn't necessary.
2015-08-21 14:36:51 -04:00
Aaron Patterson
34fa6658dd pass a request object to the headers object 2015-08-21 11:21:10 -07:00
Aaron Patterson
c6cfcc6124 move header allocation to a helper method
I'm going to change the constructor, so it's easier to do it in one
place.
2015-08-21 11:21:10 -07:00
Andrew White
95cb2e3a8a Merge pull request #21106 from amitsuroliya/fix_routing_test
Remove duplicity in tests
2015-08-21 11:25:38 +01:00
Aaron Patterson
867810cdfa set route precedence at allocation time
This way we can make the Route object a read-only data structure.
2015-08-20 15:34:18 -07:00
Aaron Patterson
51211a94bd point at rack master 2015-08-20 13:45:11 -07:00
Marcin Olichwirowicz
a8d0084c69 Remove dead code 2015-08-19 19:14:38 +02:00
Aaron Patterson
7187339854 make the routes reader private
nobody should be touching the routes hash without going through the
NamedRouteCollection object.
2015-08-18 16:33:18 -07:00
Aaron Patterson
62383ddecc don't touch internals
We shouldn't be messing with the NamedRouteCollection internals.  Just
ask the object if the named route is in there.
2015-08-18 16:30:01 -07:00
Aaron Patterson
d993cb3629 drop array allocations when building paths
```ruby
require 'action_pack'
require 'action_dispatch'
require 'benchmark/ips'

route_set = ActionDispatch::Routing::RouteSet.new
routes = ActionDispatch::Routing::Mapper.new route_set

ObjectSpace::AllocationTracer.setup(%i{path line type})
result = ObjectSpace::AllocationTracer.trace do
  500.times do
    routes.resources :foo
  end
end

sorted = ObjectSpace::AllocationTracer.allocated_count_table.sort_by(&:last)
sorted.each do |k,v|
  next if v == 0
  p k => v
end

__END__

Before:

{:T_SYMBOL=>11}
{:T_REGEXP=>17}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_OBJECT=>99009}
{:T_DATA=>100088}
{:T_HASH=>122015}
{:T_STRING=>159637}
{:T_IMEMO=>363134}
{:T_ARRAY=>433056}

After:

{:T_SYMBOL=>11}
{:T_REGEXP=>17}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_OBJECT=>91009}
{:T_DATA=>100088}
{:T_HASH=>114013}
{:T_STRING=>159637}
{:T_ARRAY=>321056}
{:T_IMEMO=>351133}
```
2015-08-18 15:57:11 -07:00
Aaron Patterson
4d9475bef9 symbols will always be constructed with strings. 💣 2015-08-18 15:20:19 -07:00
Aaron Patterson
01d88953e2 drop string allocations for each resource
Eagerly calculate and cache the name of Symbol objects in the path AST.
This drops about 26 string allocations per resource:

```ruby
require 'action_pack'
require 'action_dispatch'
require 'benchmark/ips'

route_set = ActionDispatch::Routing::RouteSet.new
routes = ActionDispatch::Routing::Mapper.new route_set

ObjectSpace::AllocationTracer.setup(%i{path line type})
result = ObjectSpace::AllocationTracer.trace do
  500.times do
    routes.resources :foo
  end
end

sorted = ObjectSpace::AllocationTracer.allocated_count_table.sort_by(&:last)
sorted.each do |k,v|
  next if v == 0
  p k => v
end

__END__

Before:

{:T_SYMBOL=>11}
{:T_REGEXP=>17}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_OBJECT=>99009}
{:T_DATA=>116084}
{:T_HASH=>122015}
{:T_STRING=>172647}
{:T_IMEMO=>371132}
{:T_ARRAY=>433056}

After:

{:T_SYMBOL=>11}
{:T_REGEXP=>17}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_OBJECT=>99009}
{:T_DATA=>100088}
{:T_HASH=>122015}
{:T_STRING=>159637}
{:T_IMEMO=>363134}
{:T_ARRAY=>433056}
```
2015-08-18 15:12:44 -07:00
Rafael Mendonça França
88a1800526 Remove unreached default value
verb_matcher never returns nil.
2015-08-17 23:22:59 -03:00
Aaron Patterson
0b476de445 use the strategy pattern to match request verbs
Rather than building a regexp for every route, lets use the strategy
pattern to select among objects that can match HTTP verbs.  This commit
introduces strategy objects for each verb that has a predicate method on
the request object like `get?`, `post?`, etc.

When we build the route object, look up the strategy for the verbs the
user specified.  If we can't find it, fall back on string matching.

Using a strategy / null object pattern (the `All` VerbMatcher is our
"null" object in this case) we can:

1) Remove conditionals
2) Drop boot time allocations
2) Drop run time allocations
3) Improve runtime performance

Here is our boot time allocation benchmark:

```ruby
require 'action_pack'
require 'action_dispatch'

route_set = ActionDispatch::Routing::RouteSet.new
routes = ActionDispatch::Routing::Mapper.new route_set

result = ObjectSpace::AllocationTracer.trace do
  500.times do
    routes.resources :foo
  end
end

sorted = ObjectSpace::AllocationTracer.allocated_count_table.sort_by(&:last)
sorted.each do |k,v|
  next if v == 0
  p k => v
end
__END__

Before:

$ be ruby -rallocation_tracer route_test.rb
{:T_SYMBOL=>11}
{:T_REGEXP=>4017}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_DATA=>84092}
{:T_OBJECT=>99009}
{:T_HASH=>122015}
{:T_STRING=>216652}
{:T_IMEMO=>355137}
{:T_ARRAY=>441057}

After:

$ be ruby -rallocation_tracer route_test.rb
{:T_SYMBOL=>11}
{:T_REGEXP=>17}
{:T_STRUCT=>6500}
{:T_MATCH=>12004}
{:T_DATA=>84092}
{:T_OBJECT=>99009}
{:T_HASH=>122015}
{:T_STRING=>172647}
{:T_IMEMO=>355136}
{:T_ARRAY=>433056}
```

This benchmark adds 500 resources. Each resource has 8 routes, so it
adds 4000 routes.  You can see from the results that this patch
eliminates 4000 Regexp allocations, ~44000 String allocations, and ~8000
Array allocations.  With that, we can figure out that the previous code
would allocate 1 regexp, 11 strings, and 2 arrays per route *more* than
this patch in order to handle verb matching.

Next lets look at runtime allocations:

```ruby
require 'action_pack'
require 'action_dispatch'
require 'benchmark/ips'

route_set = ActionDispatch::Routing::RouteSet.new
routes = ActionDispatch::Routing::Mapper.new route_set

routes.resources :foo

route = route_set.routes.first
request = ActionDispatch::Request.new("REQUEST_METHOD" => "GET")

result = ObjectSpace::AllocationTracer.trace do
  500.times do
    route.matches? request
  end
end

sorted = ObjectSpace::AllocationTracer.allocated_count_table.sort_by(&:last)
sorted.each do |k,v|
  next if v == 0
  p k => v
end

__END__

Before:

$ be ruby -rallocation_tracer route_test.rb
{:T_MATCH=>500}
{:T_STRING=>501}
{:T_IMEMO=>1501}

After:

$ be ruby -rallocation_tracer route_test.rb
{:T_IMEMO=>1001}
```

This benchmark runs 500 calls against the `matches?` method on the route
object.  We check this method in the case that there are two methods
that match the same path, but they are differentiated by the verb (or
other conditionals).  For example `POST /users` vs `GET /users`, same
path, different action.

Previously, we were using regexps to match against the verb.  You can
see that doing the regexp match would allocate 1 match object and 1
string object each time it was called.  This patch eliminates those
allocations.

Next lets look at runtime performance.

```ruby
require 'action_pack'
require 'action_dispatch'
require 'benchmark/ips'

route_set = ActionDispatch::Routing::RouteSet.new
routes = ActionDispatch::Routing::Mapper.new route_set

routes.resources :foo

route = route_set.routes.first
match = ActionDispatch::Request.new("REQUEST_METHOD" => "GET")
no_match = ActionDispatch::Request.new("REQUEST_METHOD" => "POST")

Benchmark.ips do |x|
  x.report("match") do
    route.matches? match
  end

  x.report("no match") do
    route.matches? no_match
  end
end

__END__

Before:

$ be ruby -rallocation_tracer runtime.rb
Calculating -------------------------------------
               match    17.145k i/100ms
            no match    24.244k i/100ms
-------------------------------------------------
               match    259.708k (± 4.3%) i/s -      1.303M
            no match    453.376k (± 5.9%) i/s -      2.279M

After:

$ be ruby -rallocation_tracer runtime.rb
Calculating -------------------------------------
               match    23.958k i/100ms
            no match    29.402k i/100ms
-------------------------------------------------
               match    465.063k (± 3.8%) i/s -      2.324M
            no match    691.956k (± 4.5%) i/s -      3.469M

```

This tests tries to see how many times it can match a request per
second.  Switching to method calls and string comparison makes the
successful match case about 79% faster, and the unsuccessful case about
52% faster.

That was fun!
2015-08-17 18:17:55 -07:00
Aaron Patterson
c989e2c56f switch Route constructors and pass in the regexp
We don't need to add and delete from the conditions hash anymore, just
pass the regexp directly to the constructor.
2015-08-17 16:43:40 -07:00
Aaron Patterson
bb10030802 split the verb regex from the constraints hash
verb matching is very common (all routes besides rack app endpoints
require one).  We will extract verb matching for now, and use a more
efficient method of matching (then regexp) later
2015-08-17 16:39:26 -07:00
Aaron Patterson
23cfdd4b71 test the verb method on the route, specifically 2015-08-17 16:36:31 -07:00
Aaron Patterson
c42db41f54 routes are always constructed with a hash for the conditions 2015-08-17 16:30:53 -07:00
Aaron Patterson
1ce74b009f introduce an alternate constructor for Route objects
I want to change the real constructor to take a particular parameter for
matching the request method
2015-08-17 16:08:39 -07:00
Aaron Patterson
559e7f9450 drop object allocation during routes setup
This commit introduces a functional Path AST visitor and implements
`each` on the AST in terms of the functional visitor.  The functional
visitor doesn't maintain state, so we only need to allocate one of them.

Given this benchmark route file:

```ruby
require 'action_pack'
require 'action_dispatch'

route_set = ActionDispatch::Routing::RouteSet.new
routes = ActionDispatch::Routing::Mapper.new route_set

ObjectSpace::AllocationTracer.setup(%i{path line type})

result = ObjectSpace::AllocationTracer.trace do
  500.times{|i|
    routes.resource :omglol
  }
end

result.find_all { |k,v| k.first =~ /git\/rails/ }.sort_by { |k,v|
  v.first
}.each { |k,v|
  p k => v
}
```

node.rb line 17 was in our top 3 allocation spot:

```
{["/Users/aaron/git/rails/actionpack/lib/action_dispatch/journey/nodes/node.rb", 17, :T_OBJECT]=>[31526, 0, 28329, 0, 2, 1123160]}
{["/Users/aaron/git/rails/actionpack/lib/action_dispatch/routing/mapper.rb", 2080, :T_IMEMO]=>[34002, 0, 30563, 0, 2, 1211480]}
{["/Users/aaron/git/rails/actionpack/lib/action_dispatch/routing/mapper.rb", 2071, :T_IMEMO]=>[121934, 1, 109608, 0, 7, 4344400]}
```

This commit eliminates allocations at that place.
2015-08-17 15:57:06 -07:00
Aaron Patterson
8d7b883f33 avoid is_a? checks
add another predicate method so we can avoid is_a checks
2015-08-17 15:28:23 -07:00
Aaron Patterson
56f734a361 pull RegexpOffsets in to a method
we don't really need this visitor
2015-08-17 15:11:20 -07:00
Aaron Patterson
15bc6b630f required_defaults is always passed in, remove conditional
Routes are always constructed with a list of required_defaults, so
there's no need to check whether or not it's nil
2015-08-17 15:11:20 -07:00
Marcin Olichwirowicz
48a240bcbe Fix master build 2015-08-17 23:30:32 +02:00
Aaron Patterson
d12ff4fa50 use predicate methods to avoid is_a? checks
we may want to change the name of the class at some point, so it's
better to use a predicate
2015-08-17 13:51:39 -07:00
Aaron Patterson
e9777ef62e default pattern to use a joined string
The string we create is almost always the same, so rather than joining
all the time, lets join once, then reuse that string everywhere.
2015-08-17 13:51:38 -07:00
Rafael Mendonça França
15fd2586a8 Merge pull request #21252 from rodzyn/improve_params_parser
Improve params parser
2015-08-17 13:20:09 -03:00
Jon Atack
51b237c955 [skip ci] Fix minor typo 2015-08-17 16:02:56 +02:00
Marcin Olichwirowicz
9366d622be Cleanup ActionDispatch:ParamsParser 2015-08-17 11:38:37 +02:00
Aaron Patterson
fe19d07138 move route allocation to a factory method on the mapping object
I would like to change the signature of the Route constructor.  Since
the mapping object has all the data required to construct a Route
object, move the allocation to a factory method.
2015-08-15 14:34:37 -07:00
Aaron Patterson
703275ba70 use the mapper to build the routing table
We should build the routes using the user facing API which is `Mapper`.
This frees up the library internals to change as we see fit. IOW we
shouldn't be testing internals.
2015-08-15 14:32:04 -07:00
Aaron Patterson
05eea6a2c3 only process via once
we can directly turn it in to a regular expression here, so we don't
need to test its value twice
2015-08-15 14:32:03 -07:00
eileencodes
f6232a518b Refactor how assign_parameters sets generated_path & query_string_keys
This is part of a larger refactoring on controller tests. We needed to
move these methods here so that we could get rid of the `|| key ==
:action || key == :controller` in `assign_parameters`. We know this is
ugly and intend to fix it but for now `generate_extras` needs to be used
in the two methods to access the path and the query_string_keys.

We're adding `:controller` and `:action` to the `query_string_keys`
because we always need a controller and action. If someone passed
`action` or `controller` in in there test they are unambigious - we
know they have to go into the query params.
2015-08-15 13:23:41 -04:00
Marcin Olichwirowicz
174b9a3097 Initialize symbols instead of mapping to_sym on the set of strings 2015-08-15 17:45:13 +02:00
Aaron Patterson
a293812bff only keep one hash of named routes
The outer router object already keeps a hash of named routes, so we
should just use that.
2015-08-14 18:06:48 -07:00
Aaron Patterson
4bdd92d9fd rm add_route2
refactor the tests with a backwards compatible method call so we can rm
add_route2 from the journey router
2015-08-14 16:25:03 -07:00
Aaron Patterson
6c48d9392f pass pass the mapping object down the add_route stack
then we can let the mapping object derive stuff that the Route object
needs.
2015-08-14 16:13:26 -07:00
Aaron Patterson
5ba6966766 pass the mapping object to build_route
now that we aren't doing options manipulations, we can just pass the
mapping object down and read values from it.
2015-08-14 14:41:48 -07:00
Aaron Patterson
68dd5abf14 remove process_path
since we've extracted the `to` initialization, there's no need for
`process_path`
2015-08-14 14:05:00 -07:00
Aaron Patterson
565582c0f5 explicitly return nil from get_to_from_path
if `to` was initialized, this method would return, so we can eliminate
the to ||= in the conditional.  Finally, let's return a nil in the else
block so that it's explicit that this method can return nil
2015-08-14 12:08:30 -07:00
Aaron Patterson
b543ee74f4 extract method on determining :to from the path
Eventually we'll pull this up and delete `process_path`.
2015-08-14 12:03:08 -07:00
Aaron Patterson
b10b279b97 deprecate passing a string for both the beginning path and :path option 2015-08-14 11:55:50 -07:00
Aaron Patterson
b6146b0d96 rm path_params method
We don't need a method for something like this.  I want to pull this up
the stack as well and move the module + :controller ArgumentError up the
stack as well
2015-08-14 11:03:49 -07:00
Aaron Patterson
4a591ce2f8 extract method on wildcard path parameter handling 2015-08-14 10:54:04 -07:00
Aaron Patterson
b592c5b607 pass the path ast down
now we don't need to add it to a hash and delete it from the hash later
just to pass it around
2015-08-14 10:44:49 -07:00
Aaron Patterson
aaaa67902e pull up path parsing
`add_route` needs the AST, so rather than shove it in a hash and delete
later, lets move parsing up the stack so we can pass down later
2015-08-14 10:39:33 -07:00
Aaron Patterson
7fa6600b52 use predicate methods instead of hard coding verb strings
also change the feeler to subclass AD::Request so that it has all the
methods that Request has
2015-08-14 10:39:33 -07:00
Aaron Patterson
ad311f215d remove hard coded regular expression 2015-08-14 10:39:33 -07:00
Aaron Patterson
c3284e2a36 implement requirements in terms of routes 2015-08-14 10:39:33 -07:00
Aaron Patterson
60adf118a6 implement the asts method in terms of paths / patterns
Eventually I want to eliminate the FakeSet test class
2015-08-14 10:39:32 -07:00
Aaron Patterson
61437232a9 extract ast finding to a method
I'm going to reimplement this using route objects, so it will be easier
if we just change ast access to go through a method rather than hashes
2015-08-14 10:39:32 -07:00
Aaron Patterson
715abbbb33 stop adding path_info to the conditions hash
we don't need to keep adding it and deleting if from hashes.
2015-08-14 10:39:32 -07:00
Aaron Patterson
1eb6b4a679 pull up path normalization.
Eventually I want to pull up AST generation so that we don't have to add
it to the `conditions` hash.
2015-08-14 10:39:32 -07:00
Aaron Patterson
95a5d177cc build_path doesn't need the path variable anymore
It just constructs a Path::Pattern object with the AST that it already
has
2015-08-13 15:44:15 -07:00
Aaron Patterson
947ebe9a6d remove Strexp
This was a useless object.  We can just directly construct a
Path::Pattern object without a Strexp object.
2015-08-13 15:42:46 -07:00
Aaron Patterson
4868692687 pass anchor directly to Pattern
the caller already has it, there is no reason to pack it in to an object
and just throw that object away.
2015-08-13 15:16:25 -07:00
Aaron Patterson
36f26fd47e we already have access to the AST, so just use it 2015-08-13 15:03:20 -07:00
Aaron Patterson
b3d73e789c remove default arguments that aren't used
we always pass all parameters, so there is no reason to provide default
arguments.
2015-08-13 14:19:58 -07:00
Aaron Patterson
45d594fa53 pull up options_constrants extraction 2015-08-13 14:15:04 -07:00
Aaron Patterson
b778f6348b remove as
the caller already has access to `as`, so we can stop passing it around.
2015-08-13 14:04:02 -07:00
Aaron Patterson
e38a456faf remove anchor from mapping
the same value that is extracted from the options hash earlier is
returned, so we don't need to pass it in in the first place.  The caller
already has the data, so stop passing it around.
2015-08-13 13:58:16 -07:00
Aaron Patterson
aef421ed9d pull anchor extraction up
this way we don't have to mutate the options hash so far away from where
the user passed it in
2015-08-13 13:55:03 -07:00
Aaron Patterson
33dc653466 raise if anchor is passed to scope
The `anchor` parameter [is overridden](b4b4a611d0/actionpack/lib/action_dispatch/routing/mapper.rb (L1528)) unless it
is directly passed to `match`, so setting it in a scope must be a
mistake.
2015-08-13 13:41:03 -07:00
Aaron Patterson
ba7602b881 remove the add_request_method method
I didn't like this method because it mutates the parameters.  Now that
the method is so small, just push it up to `initialize`
2015-08-12 17:24:23 -07:00
Aaron Patterson
a4f7809472 remove side effects in normalize_defaults
now the `@defaults` variable doesn't need to be set before calling
`normalize_defaults`
2015-08-12 17:10:44 -07:00
Aaron Patterson
3e3e23f048 remove unnecessary deletes
These three options are stored in the `scope` chain outside of the
options hash.  If they are in the options hash, then someone passed them
in to `match` and they don't really do anything.  So lets remove the
code.
2015-08-12 17:04:32 -07:00
Aaron Patterson
3955688440 pull format out of the options hash
remove `format` from the options hash in the scope chain so that we
don't need to remove it later
2015-08-12 16:54:35 -07:00
Aaron Patterson
ec895189e4 pull formatted up the stack
this reduces the number of times we have to mutate the options hash.
2015-08-12 16:54:35 -07:00
Aaron Patterson
d61e3c79dc add a regression test for scoped format params
This just ensures that `format` is applied to things inside the scope
2015-08-12 16:54:35 -07:00
Rafael Mendonça França
7d4ad74ce5 Merge pull request #21214 from rodzyn/fewer_objects_and_refactoring
Fewer objects and refactoring
2015-08-12 20:15:37 -03:00
Marcin Olichwirowicz
fc22cb88ed Simplify code
Since we are always responding with an array and using `any?`, we don't
need to check if an array is empty
2015-08-13 01:00:49 +02:00
Marcin Olichwirowicz
0c15b85d5d Avoid unnecessary MatchData objects 2015-08-13 00:56:29 +02:00
Aaron Patterson
2a05a72e6a store via outside the options hash
Now we don't have to manually remove this from the options hash since
the scope stores it outside of "options"
2015-08-12 15:54:24 -07:00
Aaron Patterson
f514c9c04a don't mutate the caller's variables
Remove the `options` reader from `Resource` because nobody needs to see
that hash.  Also remove mutations on the options hash in
`apply_common_behavior_for` because leaving the side effects in that
method makes it difficult to understand what is going on in the caller.
2015-08-12 15:50:14 -07:00
Aaron Patterson
33d20ea184 store :only and :except outside the normal options hash
these two keys have a different merge strategy, and they also just get
removed from the options hash later in the code.  If we store them in a
separate place, then we don't need to remove them later
2015-08-12 15:30:43 -07:00
Aaron Patterson
e2735b2b32 add a regression test for adding arbitrary keys to scope 2015-08-12 15:17:21 -07:00
Aaron Patterson
1c94317539 add a method to Scope for getting mapping options
Eventually we don't want to expose the "options" hash from scope, only
read values from it.  Lets start by adding a reader method.
2015-08-12 14:30:54 -07:00
Aaron Patterson
58117fadae pull via checking up to via extraction
now we don't need to construct a Mapping object just to get an
ArgumentError if there is no `via` parameter provided.
2015-08-12 14:30:53 -07:00
Aaron Patterson
b46c67fb47 pull via all the way out of add_route 2015-08-12 14:30:53 -07:00
Aaron Patterson
b106dddfaf fix via handling when it's in a scope 2015-08-12 14:30:53 -07:00
Aaron Patterson
4c641c6e36 add a test for adding "via" using scope 2015-08-12 14:30:53 -07:00
Aaron Patterson
b59ff24207 pull via extraction up
We're going to try pulling this up further, and check `via` validity
sooner.  This way we don't have to do a bunch of processing on `options`
hashes only to find out that the route is incorrect
2015-08-12 14:30:53 -07:00
Aaron Patterson
f88c68a819 simplify split_constraints
If we do the Regexp verification in a second method, then the
`split_constraints` method gets much easier.
2015-08-12 14:30:53 -07:00
Aaron Patterson
c10d7d1690 remove side effects from normalize_format 2015-08-12 14:30:53 -07:00
Aaron Patterson
b9a622f817 switch === to case / when 2015-08-12 14:30:52 -07:00
Aaron Patterson
463339c4bb make split_constraints more functional.
I don't want `split_constraints` to mutate any instance variables.  That
way it's easier to move the method around and understand what it does
(it has no side effects)
2015-08-12 14:30:52 -07:00
Aaron Patterson
3042b71a7a make constraints more functional
I don't want to rely on mutating ivars.  This gives me more freedom when
refactoring
2015-08-12 14:30:52 -07:00
Aaron Patterson
cbf1617015 only call split_constraints once 2015-08-11 18:23:25 -07:00
Aaron Patterson
3420849f85 only do is_a? checks on options_constraints once
we don't need to do it so many times.
2015-08-11 18:17:05 -07:00
Aaron Patterson
ea4da199b7 Mapping instances don't need scope anymore 2015-08-11 18:10:41 -07:00
Aaron Patterson
175280ccb5 pull scope[:constraints] up
Now we only need to call `split_constraints` possibly twice!
2015-08-11 18:06:54 -07:00
Aaron Patterson
0988ad0fa7 pull :format up a little bit
apparently `format` can also come from the scope options, so we need to
extract it there too.
2015-08-11 18:06:53 -07:00
Sean Griffin
e69364bc2d Merge pull request #21203 from denniss/issue-21199
Authorization scheme should be case insensitive. Fixes #21199
2015-08-11 17:25:00 -06:00
Aaron Patterson
97d7dc48d6 pull to up
this way we don't have to insert / delete it from the options hash so
many times.
2015-08-11 16:16:09 -07:00
Aaron Patterson
c25d1707b9 push scope access up for modules
eventually we'll remove the need to access `scope` inside the Mapping
object.
2015-08-11 16:16:09 -07:00
Dennis Suratna
dec2f52fa4 Authorization scheme should be case insensitive. Fixes #21199 2015-08-11 15:59:44 -07:00
Aaron Patterson
41e7923cd4 path is never nil 2015-08-11 14:50:15 -07:00
Aaron Patterson
763dd50a76 split options hash and pass values down
`using_match_shorthand?` doesn't need to know that an options hash
exists.  Also use this opportunity to make the boolean logic a little
more sane
2015-08-11 14:49:19 -07:00
Aaron Patterson
0c3f8e3f02 pull option duping up 2015-08-11 14:49:19 -07:00
Aaron Patterson
1a830cbd83 split paths by type
this simplifies the "downstream" logic since we know we'll only be
dealing with one particular type
2015-08-11 14:49:19 -07:00
Aaron Patterson
7df7c707ab one fewer hash mutation 2015-08-11 14:49:19 -07:00
Aaron Patterson
5935e4c882 push option decomposition up a bit more
I think we can find the original place where `action` is added to the
options hash now.
2015-08-11 14:49:19 -07:00
Aaron Patterson
934bdf6724 push action option extraction up one frame. 2015-08-11 14:49:18 -07:00
Aaron Patterson
97bbde7600 pull up the "options.delete(:controller)" logic
we want to try to pull this logic up to where the user actually passed
in "controller" so that it's close to the related call.  That way when
we're down the stack, we don't need to wonder "why are we doing this?"
2015-08-11 14:49:18 -07:00
Robin Dupret
f51d142881 Tiny documentation fixes [ci skip] 2015-08-11 15:35:35 +02:00
Rafael Mendonça França
30608648ef Only use path if the key is not present
There are some cases where :path is nil on option and we should respect
that.
2015-08-10 22:51:46 -03:00
Aaron Patterson
8adf25a632 try to pass fewer options to scope
We already know how to handle `path`, so lets just handle it on our own.
2015-08-10 17:57:17 -07:00
Aaron Patterson
7f3cfb6067 always cast name to a symbol, and never to_s it
All callers of `action_path` interpolate the return value in to a
string, so there is no need for the method to to_s it.  to_sym on a
symbol will return the same symbol, though I think `action_path` may
always be called with a symbol so this might not be necessary.
2015-08-10 17:57:17 -07:00
Aaron Patterson
f727bd24c2 pull path conditional up
we only need to check for `path` once.
2015-08-10 17:57:17 -07:00
Aaron Patterson
e852daa697 pull defaults extraction up the stack.
Now we can see where `defaults` options originate
2015-08-10 15:31:33 -07:00
Aaron Patterson
7c6c048f97 avoid calling scope on defaults methods 2015-08-10 15:20:33 -07:00
Aaron Patterson
d193b3bbf6 let the controller method push / pop the stack
since `controller` and `controller_scope` were the same, just combine
them
2015-08-10 14:39:33 -07:00
Aaron Patterson
ae3269b79b remove another call to scope 2015-08-10 14:36:59 -07:00
Aaron Patterson
628a23cdd2 remove dead code
This method isn't used internally, isn't tested, isn't documented.  We
should delete it.
2015-08-10 14:31:29 -07:00
Aaron Patterson
6ac882bb58 avoid is_a? calls
add a predicate method so that we can avoid is_a? calls on the resource
object.
2015-08-10 13:36:17 -07:00
Aaron Patterson
3c8775349c avoid another call to scope
calling `scope` isn't cheap, so try to call cheaper methods that do the
same thing for those particular parameters (in this case `path_scope`)
2015-08-10 13:30:31 -07:00
Aaron Patterson
6bc8ada05c push with_scope_level up so resource_scope doesn't know
`resource_scope` should just put resource scopes on the stack, and
doesn't need to know what a `scope_level` is.
2015-08-10 13:24:35 -07:00
Aaron Patterson
d4e1a75918 reuse the same frame so we don't need a singleton hash
We just want to augment the scope level, not the frame itself, so just
copy the frame to the new scope object.
2015-08-10 13:24:35 -07:00
Aaron Patterson
8e014f28cc add a null node at the top of the stack
this gives us an easier way to iterate the stack
2015-08-10 12:35:57 -07:00
Aaron Patterson
53454bfcb6 remove @nesting ivar
The same information is stored in the `@scope` linked list, so just get
it from there.
2015-08-10 12:16:49 -07:00
Aaron Patterson
d9603cb09f pass shallow in to the resource constructor
this lets us remove the setter and make the Resource object Read-Only
2015-08-10 11:51:24 -07:00
Aaron Patterson
6a9d1925dc we have the resource on the stack, so just use it
We don't need to ask `scope` for the resource because we already have it
right here.
2015-08-10 11:39:41 -07:00
Rafael Mendonça França
8d0c107a60 Remove wrong comment
This method raises conditionally not always so we should not documment
as it always raise.
2015-08-09 23:30:08 -03:00
Rafael Mendonça França
09e1689252 Remove the conditional since it is done in the method 2015-08-09 23:27:40 -03:00
Rafael Mendonça França
20cf2dd089 Execute the block when the controller doesn't exist
We should return when the contoller key is not present or if the
controller doesn't exist and we didn't raised an error.
2015-08-09 23:15:35 -03:00
Rafael Mendonça França
4818fdd36b Name the argument according with its job
Related with dc1b937db780155089fce522f03d340e62f5df36
2015-08-09 23:10:48 -03:00
Aaron Patterson
919e7d3e6c push scope calls up one frame
eliminates calling `scope` in one method, pushes the other calls up one
frame.  This goes a little way towards eliminating the internal calls to
`scope`.
2015-08-09 17:11:43 -07:00
Aaron Patterson
378e3a666e remove useless hash
we don't really need this hash.
2015-08-08 18:57:47 -07:00
Aaron Patterson
f360689586 stop calling scope internally
we need to get a grip on what `scope` actually does.  This commit
removes some of the internal calls to `scope`.  Eventually we should add
public facing methods that provide the API that `scope` is trying to
accomplish.
2015-08-08 18:48:27 -07:00
Aaron Patterson
5a18b853ed remove useless conditional
`prepare_params!` would raise an exception if `params` wasn't
initialized, so it must always be available.  Remove the existence
conditional from the `controller` method.
2015-08-08 17:12:50 -07:00
Aaron Patterson
1b73d53a1c eliminate assignment in conditional
The method we called already has the conditional we need.  Just add an
else block so that we don't need two tests.
2015-08-08 16:39:16 -07:00
Aaron Patterson
dc1b937db7 Remove defaults hash from Dispatcher
`Dispatcher` doesn't need to hold on to the defaults hash.  It only used
the hash to determine whether or not it should raise an exception if
there is a name error.  We can pass that in further up the stack and
alleviate Dispatcher from knowing about that hash.
2015-08-08 16:34:34 -07:00
Aaron Patterson
175e92c9ac eliminate runtime conditional
We know in advance whether the object is a dispatcher or not, so we can
configure the Constraints object with a strategy that will call the
right method.
2015-08-08 16:12:00 -07:00
Aaron Patterson
246bfcb473 whitespace 2015-08-08 15:41:36 -07:00
Aaron Patterson
5e81e6ca31 remove the setter from Scope
it isn't used.
2015-08-08 15:04:20 -07:00
Kasper Timm Hansen
3a7609e2ba Merge pull request #21167 from AaronLasseigne/use_each_key
replace each with each_key when only the key is needed
2015-08-08 18:56:10 +02:00
Aaron Lasseigne
725f9bf3e2 replace each with each_key when only the key is needed
Using each_key is faster and more intention revealing.

Calculating -------------------------------------
                each    31.378k i/100ms
            each_key    33.790k i/100ms
-------------------------------------------------
                each    450.225k (± 7.0%) i/s -      2.259M
            each_key    494.459k (± 6.3%) i/s -      2.467M

Comparison:
            each_key:   494459.4 i/s
                each:   450225.1 i/s - 1.10x slower
2015-08-08 11:54:09 -05:00
eileencodes
286cb890de Refactor route assertion methods in resources test
The tests and methods were hard to read with `options[:options]` all
over the place. This refactoring makes the code easier to understand.

The change came out of work for moving the underlying code of controller
tests to integraiton tests.
2015-08-08 11:53:05 -04:00
Rafael Mendonça França
d919fd88ec Merge pull request #11352 from xaviershay/dispatcher-api
Allow a custom dispatcher to be provided to routing.
2015-08-08 12:22:21 -03:00
eileencodes
12f08acbac Fix deprecation warning in tests
Using the string version of the class reference is now deprecated when
referencing middleware. This should be written as a class not as a string.

Deprecation warning that this change fixes:
```
DEPRECATION WARNING: Passing strings or symbols to the middleware
builder is deprecated, please change
them to actual class references.  For example:
  "ActionDispatch::ShowExceptions" => ActionDispatch::ShowExceptions
```
2015-08-08 10:38:09 -04:00
eileencodes
e7dd9069ca Rename extra_keys variables to query_string_keys
`extra_keys` is a confusing variable name because it's not clear what is
"extra". This renames it to `query_string_keys` so it's clear that the
"extra" is just the query string.
2015-08-08 10:29:34 -04:00
eileencodes
c8b8295583 Refactor to remove DrawOnce module
We were doing extra work that could be pushed off to Integration test
and SharedRoutes. Creating an extra module isn't necessary when those
are created by their respective classes.
2015-08-08 10:15:35 -04:00
Xavier Shay
2992b1c04c Allow a custom dispatcher to be provided to routing. 2015-08-07 20:06:24 -07:00
Xavier Shay
f26ae7d10f Move controller_reference and controller_class_names to protected
scope so that they are available to subclasses.
2015-08-07 19:50:14 -07:00
Aaron Patterson
05934d24af deprecate the env method on controller instances
people should be accessing request information through the request
object, not via the env hash.  If they really really want at the env
hash, then they can get it off the request.
2015-08-07 16:27:32 -07:00
Aaron Patterson
869b007172 the request object manages env
remove the setter.  The request object manages the env hash, so any
mutations need to go through it
2015-08-07 16:20:38 -07:00
Aaron Patterson
1f80f3a373 remove vestigial code
Looks like this was left over from converting Rails to Rack.  I think
it's safe to remove now.
2015-08-07 16:17:22 -07:00
Aaron Patterson
81cfdf2489 stop using @_env in the controller instance
Actions are processed through `dispatch`, so they should have the
request set on them before any user land code can be executed.  Lets
stop setting _env on the controller, and give access to it through the
`env` method.
2015-08-07 16:00:57 -07:00