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

[Controller] Adds Route Helper Methods to Controller #362

Merged
merged 4 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions spec/amber/controller/base_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module Amber::Controller
controller.responds_to?(:client_ip).should eq true
controller.responds_to?(:request).should eq true
controller.responds_to?(:response).should eq true
controller.responds_to?(:action_name).should eq true
controller.responds_to?(:route_resource).should eq true
controller.responds_to?(:route_scope).should eq true
controller.responds_to?(:controller_name).should eq true
end

describe "#redirect_back" do
Expand Down
5 changes: 1 addition & 4 deletions src/amber/controller/base.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Amber::Controller
include Helpers::Redirect
include Helpers::Render
include Helpers::Responders
include Helpers::Route

include Callbacks

Expand All @@ -22,9 +23,5 @@ module Amber::Controller
def initialize(@context : HTTP::Server::Context)
@params = Amber::Validators::Params.new(context.params)
end

def controller_name
self.class.name.gsub(/Controller/i, "")
end
end
end
19 changes: 19 additions & 0 deletions src/amber/controller/helpers/route.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Amber::Controller::Helpers
module Route
def action_name
context.request_handler.action
end

def route_resource
context.request_handler.resource
end

def route_scope
context.request_handler.scope
end

def controller_name
self.class.name.sub(/Controller$/, "").underscore
end
end
end