Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core routing refactor #211

Merged
merged 160 commits into from Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
e06d0a5
Initial routing refactor
bryanp Dec 5, 2016
a6a1b1f
Make example run with current code
bryanp Feb 16, 2017
7a2e1cc
Controller, Inline Handlers, & Error Mapping
bryanp Feb 26, 2017
f96beba
Stop after handler is called
bryanp Feb 26, 2017
2b4da99
Nested handler support
bryanp Feb 26, 2017
5df05bc
Match child routes first
bryanp Feb 26, 2017
50128dd
Remove comment
bryanp Feb 26, 2017
95a8d61
Process each request in a new router instance
bryanp Feb 27, 2017
967d968
Add a few comments
bryanp Feb 27, 2017
43f72a0
Remove unnecessary error classes
bryanp Feb 27, 2017
657355a
Add default implementations of Defineable::ClassApi#make and Defineab…
jphager2 Mar 1, 2017
719e195
rename send_as to as in Controller#send
jphager2 Mar 1, 2017
6d7074a
document Defineable#stateful method
jphager2 Mar 1, 2017
71621c1
remove example tag
jphager2 Mar 2, 2017
f81268e
add missing conjunction
jphager2 Mar 2, 2017
797dbd5
Remove unnecessary requires
bryanp Mar 4, 2017
6a1abe2
Rename variable to avoid shadowing
bryanp Mar 4, 2017
6b39692
Replace Loader with RecursiveRequire refinement
bryanp Mar 4, 2017
eb37162
Move Dir extensions to a refinement
bryanp Mar 4, 2017
ff9bed5
Remove Static middleware
bryanp Mar 4, 2017
dd94487
Define app/controller hooks inline
bryanp Mar 4, 2017
4ea2120
Define Restful extension under Extension
bryanp Mar 4, 2017
9386555
Document Pakyow::App
bryanp Mar 4, 2017
14de921
Replace App#use with delegator
bryanp Mar 4, 2017
cda9eb3
Fix module reference in router docs
bryanp Mar 4, 2017
54b25f0
Include Pakyow::Helpers in Router
bryanp Mar 4, 2017
b19549e
Remove empty errors file
bryanp Mar 4, 2017
3708bef
add rack-protection by default to Pakyow::App
jphager2 Mar 8, 2017
5f017ba
prefix ConfigGroup attributes with underscore
jphager2 Mar 8, 2017
0255439
add missing underscore for defaults
jphager2 Mar 8, 2017
086f4b7
Merge pull request #250 from jphager2/config-group-options
bryanp Mar 14, 2017
5405f93
add config option protection.enabled for Pakyow::App
jphager2 Mar 14, 2017
1ffb1cd
Improve Pakyow::App docs
bryanp Mar 14, 2017
17d49ca
Merge pull request #249 from jphager2/issue-241-rr
bryanp Mar 14, 2017
06f5664
Add documentation for protection.enabled
bryanp Mar 14, 2017
3c30666
Rename router.enabled config to routing.enabled
bryanp Mar 14, 2017
6400992
Fix cookies expiry
bryanp Mar 14, 2017
edbdc8e
Fix session expiry
bryanp Mar 14, 2017
732498c
Fix a variable name
bryanp Mar 14, 2017
585f148
Rename the redirect name_or_code param
bryanp Mar 14, 2017
027a3b3
Rename the send as argument
bryanp Mar 14, 2017
b6ee5ba
Improve Pakyow::Controller docs
bryanp Mar 14, 2017
cc2461a
Respect config.routing.enabled setting
bryanp Mar 14, 2017
d7b2e30
Rename Restful extension to Resource
bryanp Mar 15, 2017
715cc0a
Update Extension to work with Router classes
bryanp Mar 15, 2017
862fc2e
Improve Pakyow::Routing::Extension docs
bryanp Mar 15, 2017
7bb928f
Improve Pakyow::Routing::Extension::Resource docs
bryanp Mar 15, 2017
c936c30
Call make when expanding a template
bryanp Mar 15, 2017
2bd3e6f
Improve Pakyow::Routing::Expansion docs
bryanp Mar 15, 2017
c348866
Improve Pakyow::Routing::Route docs
bryanp Mar 15, 2017
f29e1d4
Freeze each default extension
bryanp Mar 15, 2017
388efd9
Delegate the rest of the controller methods
bryanp Mar 15, 2017
ffbef23
Don't try to eval nil blocks
bryanp Mar 15, 2017
f15ff73
Replace readers with getters that set default values
bryanp Mar 15, 2017
66cb036
Load default extensions for each router
bryanp Mar 15, 2017
82d9276
Don't try and eval nil blocks
bryanp Mar 15, 2017
beb23b6
Improve Pakyow::Router docs
bryanp Mar 15, 2017
ce88738
Improve Pakyow::App docs
bryanp Mar 15, 2017
3284db2
Tweaks to cookies.expiry config option
bryanp Mar 15, 2017
d1ed835
Fix typo in docs
bryanp Mar 15, 2017
62f16a5
Handle exceptions hierarchically
jphager2 Mar 1, 2017
0a6b38d
Update hierarchical exception handling
jphager2 Mar 2, 2017
34a7816
more Router parent to class attr_accessor
jphager2 Mar 2, 2017
e5e19a1
revert namespace router initialization
jphager2 Mar 2, 2017
2768b42
Remove puts statement
bryanp Mar 15, 2017
52c7ba7
Dup config group settings
bryanp Mar 15, 2017
38c315d
Exclude protection that depends on session
bryanp Mar 15, 2017
c61349e
Initialize nested_path ivar to avoid warning
bryanp Mar 15, 2017
d94fecf
Make config accessible from routes
bryanp Mar 15, 2017
1984d6e
Add ability to reset app, config, definable
bryanp Mar 16, 2017
b7920ff
Define found ivar
bryanp Mar 16, 2017
38d11b3
Fix hook calls
bryanp Mar 16, 2017
2c2a74d
Tweaks to send
bryanp Mar 16, 2017
082e47b
Fix a comment
bryanp Mar 16, 2017
a4ddb13
Fix a call in path_to, and always return nil
bryanp Mar 16, 2017
6d09136
Make it possible to access request params from router
bryanp Mar 16, 2017
e2b53f7
Avoid redefining router classes
bryanp Mar 16, 2017
69ecc4d
Update group / namespace to work with router classes
bryanp Mar 16, 2017
ffe13a4
Initialize parameterized_path
bryanp Mar 16, 2017
f84a451
Fix top level resource definition
bryanp Mar 16, 2017
eb04b4b
Return nil when no matching path found
bryanp Mar 17, 2017
c193872
Fix bug building paths with underscores
bryanp Mar 17, 2017
1294a90
Support path building with params
bryanp Mar 17, 2017
a3b9232
Make rerouting actually work
bryanp Mar 17, 2017
0103cf4
Delegate reject from router
bryanp Mar 17, 2017
297a46d
Fix check for existing class
bryanp Mar 17, 2017
00deb66
Fix a couple error handling bugs
bryanp Mar 17, 2017
eefcb74
Make reject a public method, with docs
bryanp Mar 17, 2017
66bca3a
Deep dup hooks when inheriting
bryanp Mar 17, 2017
1c94e8d
Initialized nested_path for inherited case
bryanp Mar 17, 2017
665c4e9
Reverse route extension extend/include
bryanp Mar 17, 2017
b5d849e
Remove hook validation
bryanp Mar 17, 2017
a0ad1e1
Share state between router instances
bryanp Mar 18, 2017
39cbc8b
Core feature tests
bryanp Mar 18, 2017
03680df
Rework exception matching logic
bryanp Mar 18, 2017
1e4d817
Test regex routes
bryanp Mar 18, 2017
5b033f4
Delegators for session, cookies, request, response
bryanp Mar 18, 2017
41f7ddb
Change how opts are passed to AppHelpers#call
bryanp Mar 18, 2017
07e6d43
Feature tests for session / cookies
bryanp Mar 18, 2017
2e8b1a0
Remove old tests
bryanp Mar 18, 2017
f5b79e5
Fix intermittent test failures
bryanp Mar 18, 2017
14232ec
Fix main pakyow tests
bryanp Mar 18, 2017
b832fd5
Improve hierarchical error handling
bryanp Mar 21, 2017
e890253
Refactor Request#format to be based on path ext
bryanp Mar 21, 2017
77855ad
Support request formats in routes
bryanp Mar 21, 2017
08c0df0
Don't set default content type on request
bryanp Mar 21, 2017
d8cfaf7
Remove charset from default content type
bryanp Mar 21, 2017
2e202e6
Fallback to response type when sending strings
bryanp Mar 21, 2017
3881868
Add support for respond_to
bryanp Mar 21, 2017
d7c6cce
Add support for defining routes in another router
bryanp Mar 22, 2017
d98997f
Support priority in definables
bryanp Mar 22, 2017
0a4416f
Add Class to list of undupables
bryanp Mar 22, 2017
ec71aed
Inherit handlers from parent
bryanp Mar 22, 2017
61edc12
Add support for global error handlers
bryanp Mar 22, 2017
c591638
Fix resource hooks
bryanp Mar 22, 2017
588c2c4
Label expand_within as private
bryanp Mar 22, 2017
ceea365
Document missing delegators
bryanp Mar 22, 2017
3783ee7
Add handoff_to method
bryanp Mar 22, 2017
1e65fc9
Refactor compile_hooks
bryanp Mar 22, 2017
fd71df3
Remove unnecessary calls to compile_hooks
bryanp Mar 22, 2017
c689eda
Refactor merge_hooks to shared helper
bryanp Mar 22, 2017
0591d2e
Refactor compile_pipeline
bryanp Mar 22, 2017
4523309
Remove unneeded attribute
bryanp Mar 22, 2017
49d2e30
Don't define all resource routes on the router
bryanp Mar 22, 2017
5436a3f
Support groups/namespaces in templates
bryanp Mar 22, 2017
00a7f11
Bit of code cleanup
bryanp Mar 22, 2017
a05a859
Store supported methods as symbols
bryanp Mar 22, 2017
cd1495f
Remove support for calling routes without context
bryanp Mar 22, 2017
c1c616d
Call handlers in context of the current router
bryanp Mar 22, 2017
aded2b7
Call 404 handler when no router is matched
bryanp Mar 22, 2017
ea1b391
Guard against undefined variable
bryanp Mar 22, 2017
3420848
Store method on route
bryanp Mar 22, 2017
79c9cf5
Cleanup route code
bryanp Mar 22, 2017
c65c1d5
Freeze route hooks
bryanp Mar 22, 2017
3216328
Make hook merger api private
bryanp Mar 22, 2017
efb2037
Remove unnecessary upcase
bryanp Mar 22, 2017
35f2dae
Remove pakyow-core.rb file
bryanp Mar 23, 2017
13b8d02
Code style changes
bryanp Mar 23, 2017
896ccbf
Change how app is run in tests
bryanp Mar 23, 2017
2957a27
Routing benchmarks
bryanp Mar 23, 2017
308a283
Minor performance tweaks to routing
bryanp Mar 23, 2017
6734934
Cleanup Gemfile
bryanp Mar 23, 2017
e6d909c
Reset definables
bryanp Mar 24, 2017
aac31c6
Better separation of routing concerns
bryanp Mar 26, 2017
b871a1f
Refactor router const set
bryanp Mar 26, 2017
a9fea9b
Document custom matchers
bryanp Mar 26, 2017
95ae698
Reorganize routing specs
bryanp Mar 26, 2017
e9cb745
Add note about defining sub in custom matchers
bryanp Mar 26, 2017
ca6e1c1
Return nil when no matching path is found
bryanp Mar 26, 2017
c6fd9bd
Simplify make_child method signature
bryanp Mar 26, 2017
262a70d
Fix bug matching args when first arg is nil
bryanp Mar 26, 2017
a587ad8
More tests for routing edge-cases
bryanp Mar 26, 2017
5293742
Remove some unnecessary code
bryanp Mar 26, 2017
9219465
Fix issue with code style
bryanp Mar 26, 2017
4fc9d6d
Completed feature tests for routing concerns
bryanp Mar 27, 2017
04e47ef
Don't fail when builder is nil
bryanp Mar 27, 2017
6b90402
Unit tests for Pakyow::App
bryanp Mar 27, 2017
29581f4
Remaining unit tests
bryanp Mar 27, 2017
c23139c
Don't protect against nil builder
bryanp Mar 28, 2017
e526bd6
Improvements to code style and docs
bryanp Mar 28, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions .rubocop.yml
@@ -1,7 +1,19 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.4

Exclude:
- 'bin/**/*'
- 'vendor/**/*'
- '**/spec/**/*'
- 'pakyow-mailer/**/*'
- 'pakyow-presenter/**/*'
- 'pakyow-rake/**/*'
- 'pakyow-realtime/**/*'
- 'pakyow-support/**/*'
- 'pakyow-test/**/*'
- 'pakyow-ui/**/*'
DisplayCopNames: true

BlockDelimiters:
Expand Down Expand Up @@ -33,3 +45,12 @@ Style/FormatString:

Style/RegexpLiteral:
Enabled: false

Style/MethodName:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Style/Semicolon:
Enabled: false
148 changes: 148 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,148 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-03-22 17:29:38 -0700 using RuboCop version 0.47.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'Gemfile'

# Offense count: 1
# Cop supports --auto-correct.
Lint/DeprecatedClassMethods:
Exclude:
- 'lib/generators/pakyow/app/app_generator.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'lib/generators/pakyow/app/app_generator.rb'

# Offense count: 1
# Cop supports --auto-correct.
Performance/RegexpMatch:
Exclude:
- 'lib/pakyow/logger/formatters/logfmt.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'example/app/lib/helpers.rb'
- 'lib/generators/pakyow/app/templates/app/lib/helpers.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'lib/pakyow/request.rb'

# Offense count: 3
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'example/app/lib/helpers.rb'
- 'lib/generators/pakyow/app/app_generator.rb'
- 'lib/generators/pakyow/app/templates/app/lib/helpers.rb'

# Offense count: 3
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'pakyow-core/lib/pakyow/core/router.rb'
- 'pakyow-core/lib/pakyow/core/routing/extension.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Exclude:
- 'Rakefile'

# Offense count: 2
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'lib/generators/pakyow/app/app_generator.rb'
- 'pakyow-core/lib/pakyow/core/app.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'lib/generators/pakyow/app/app_generator.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: only_raise, only_fail, semantic
Style/SignalException:
Exclude:
- 'Rakefile'

# Offense count: 1
# Cop supports --auto-correct.
Style/SpaceAfterComma:
Exclude:
- 'lib/generators/pakyow/app/app_generator.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceBeforeBlockBraces:
Exclude:
- 'lib/generators/pakyow/app/app_generator.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideBlockBraces:
Exclude:
- 'Rakefile'
- 'lib/generators/pakyow/app/app_generator.rb'

# Offense count: 37
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'Rakefile'
- 'example/Gemfile'
- 'example/Rakefile'
- 'example/app/lib/routes.rb'
- 'lib/generators/pakyow/app/app_generator.rb'
- 'lib/generators/pakyow/app/templates/Rakefile'
- 'lib/generators/pakyow/app/templates/app/define.rb'
- 'lib/generators/pakyow/app/templates/app/lib/routes.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'lib/generators/pakyow/app/app_generator.rb'

# Offense count: 11
# Cop supports --auto-correct.
Style/TrailingWhitespace:
Exclude:
- 'lib/pakyow/environment.rb'
8 changes: 1 addition & 7 deletions Gemfile
@@ -1,6 +1,7 @@
source "https://rubygems.org"

gemspec
gemspec path: "pakyow-core"

gem "rake", "~> 11.1"
gem "rack", "~> 2.0"
Expand All @@ -18,8 +19,6 @@ gem "redis", "~> 3.2"

group :test do
gem "minitest", "~> 5.6"
gem "rspec", "~> 3.2"
gem "pry", "~> 0.10"

gem "simplecov", "~> 0.10", require: false, group: :test
gem "simplecov-console", "~> 0.2"
Expand All @@ -32,8 +31,3 @@ group :test do
gem "httparty", "~> 0.14"
gem "puma", "~> 3.6"
end

group :development do
gem "guard-rspec", "~> 4.6", require: false
gem "rubocop", "~> 0.34"
end
2 changes: 1 addition & 1 deletion example/app/lib/routes.rb
@@ -1,4 +1,4 @@
Pakyow::App.routes do
Pakyow::App.router do
default do
logger.info 'hello ' + Time.now.to_s
end
Expand Down
14 changes: 7 additions & 7 deletions lib/pakyow/all.rb
@@ -1,10 +1,10 @@
%w(
pakyow-support
pakyow-core
pakyow-presenter
pakyow-mailer
pakyow-realtime
pakyow-ui
support
core
presenter
mailer
realtime
ui
).each do |lib|
require lib
require "pakyow/#{lib}"
end
3 changes: 2 additions & 1 deletion lib/pakyow/environment.rb
Expand Up @@ -154,7 +154,7 @@ module Pakyow
# Loads the default middleware stack.
#
before :setup do
use Rack::ContentType, "text/html;charset=utf-8"
use Rack::ContentType, "text/html"
use Rack::ContentLength
use Rack::Head
use Rack::MethodOverride
Expand Down Expand Up @@ -287,6 +287,7 @@ def forked
call_hooks :after, :fork
end

# TODO: this is only ever used by tests and should be removed
# @api private
def call(env)
builder.call(env)
Expand Down
19 changes: 6 additions & 13 deletions lib/pakyow/request.rb
Expand Up @@ -14,11 +14,6 @@ class Request < Rack::Request
# @api public
attr_accessor :error

def initialize(*)
super
@env["CONTENT_TYPE"] = "text/html"
end

# Returns the request method (e.g. `:get`).
#
# @api public
Expand All @@ -34,15 +29,13 @@ def method
#
# @api public
def format
type = Rack::Mime::MIME_TYPES.select { |_key, value|
value == @env["CONTENT_TYPE"]
}
return @format if defined?(@format)

return if type.empty?
extension = type.keys.first
# works around a dumb thing in Rack::Mime
return :html if extension == ".htm"
extension[1..-1].to_sym
if path.include?(".")
@format = path.split(".").last.to_sym
else
@format = :html
end
end

# Returns an indifferentized params hash.
Expand Down
1 change: 0 additions & 1 deletion pakyow-core/lib/pakyow-core.rb

This file was deleted.

28 changes: 8 additions & 20 deletions pakyow-core/lib/pakyow/core.rb
@@ -1,25 +1,13 @@
require "find"
require "rack"
require "rack/file"
require "cgi"

require "pakyow"
require "pakyow/support"

require "pakyow/core/helpers"
require "pakyow/core/app_context"
require "pakyow/core/loader"
require "pakyow/core/router"
require "pakyow/core/route_merger"
require "pakyow/core/route_module"
require "pakyow/core/route_set"
require "pakyow/core/route_eval"
require "pakyow/core/route_expansion_eval"
require "pakyow/core/route_template_eval"
require "pakyow/core/route_template_defaults"
require "pakyow/core/route_lookup"
require "pakyow/core/app"
require "pakyow/core/errors"

require "pakyow/core/hooks"
require "pakyow/core/controller"
require "pakyow/core/helpers"

require "pakyow/core/router"
require "pakyow/core/routing/route"
require "pakyow/core/routing/extension"
require "pakyow/core/routing/route"
require "pakyow/core/routing/expansion"
require "pakyow/core/routing/extensions/resource"