Extract the scope building to a class method
Remove builder instances

All the job can be done at class level so we can avoid some object
allocation
Method visibility will not make difference here
Merge branch 'builder-instances'
stop creating a bunch of relation objects when we can slap all the joins on at once
Respect `SCRIPT_NAME` when using `redirect` with a relative path

Example:
    # application routes.rb
    mount BlogEngine => '/blog'

    # engine routes.rb
    get '/admin' => redirect('admin/dashboard')

This now redirects to the path `/blog/admin/dashboard`, whereas before it
would've generated an invalid url because there would be no slash between
the host name and the path. It also allows redirects to work where the
application is deployed to a subdirectory of a website.

Fixes #7977
Fix wrong variable name used in the select_day method documentation

The variable name created in the example is `my_date`, the methods  were using `my_time` instead.
Use bcrypt's public cost attr, not internal constant

See:

- https://github.com/codahale/bcrypt-ruby/pull/63
- https://github.com/codahale/bcrypt-ruby/pull/64
- https://github.com/codahale/bcrypt-ruby/pull/65
Merge pull request #12339 from tjschuck/bcrypt_cost_attr

Use bcrypt's public cost attr instead of internal constant
Keep code consistent with previous code blocks.

[ci skip]
simplify each method.

Stop writing terrible code Aaron.  This is Ruby, not Scheme
stop splatting things back and forth
stuff the join dependency object in the "anything goes" hash.
merge JoinDependency as outer joins

Merge JoinDependency objects as outer joins
delete unused code

Now that we merge trees from the top down, we don't need to search
through the whole tree for particular nodes, just walk it and merge.
nodes do not need to be sorted
pass the parent node to the construct method
the parent node is on the stack, so use it

we don't need to walk back up the node's parents when we have the parent
on the stack
refactor a little so we can remove some methods
flatten and flatten! methods for ActiveSupport::Duration