Class: Vundabar::Routing::Router
- Defined in:
- lib/vundabar/routing/routing.rb
Instance Attribute Summary collapse
-
#endpoints ⇒ Object
Returns the value of attribute endpoints.
Instance Method Summary collapse
- #controller_and_action(to) ⇒ Object
- #draw(&block) ⇒ Object
- #pattern_for(path) ⇒ Object
- #resources(args) ⇒ Object
- #root(address) ⇒ Object
Instance Attribute Details
#endpoints ⇒ Object
Returns the value of attribute endpoints.
4 5 6 |
# File 'lib/vundabar/routing/routing.rb', line 4 def endpoints @endpoints end |
Instance Method Details
#controller_and_action(to) ⇒ Object
49 50 51 52 53 |
# File 'lib/vundabar/routing/routing.rb', line 49 def controller_and_action(to) controller, action = to.split("#") controller = "#{controller.to_camel_case}Controller" [controller, action] end |
#draw(&block) ⇒ Object
5 6 7 |
# File 'lib/vundabar/routing/routing.rb', line 5 def draw(&block) instance_eval(&block) end |
#pattern_for(path) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/vundabar/routing/routing.rb', line 36 def pattern_for(path) placeholders = [] new_path = path.gsub(/(:\w+)/) do |match| placeholders << match[1..-1] "(?<#{placeholders.last}>[^?/#]+)" end [/^#{new_path}$/, placeholders] end |
#resources(args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vundabar/routing/routing.rb', line 25 def resources(args) args = args.to_s get("/#{args}", to: "#{args}#index") get("/#{args}/new", to: "#{args}#new") get("/#{args}/:id", to: "#{args}#show") get("/#{args}/:id/edit", to: "#{args}#edit") delete("/#{args}/:id", to: "#{args}#destroy") post("/#{args}/create", to: "#{args}#create") put("/#{args}/:id", to: "#{args}#update") end |