Class: Gambiarra::Router
- Inherits:
-
Object
- Object
- Gambiarra::Router
- Defined in:
- lib/gambiarra/router.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #get(**params) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #previous_path ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/gambiarra/router.rb', line 5 def initialize @routes = [] @history = History.new base_view = View.descendants[:BaseView] draw_route '', to: base_view.descendants[:Index] base_view.descendants.each do |name, view| next if name == :Index draw_route name.to_s.underscore.humanize.downcase, to: view end end |
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
3 4 5 |
# File 'lib/gambiarra/router.rb', line 3 def history @history end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/gambiarra/router.rb', line 3 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/gambiarra/router.rb', line 3 def path @path end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
3 4 5 |
# File 'lib/gambiarra/router.rb', line 3 def routes @routes end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/gambiarra/router.rb', line 3 def url @url end |
Instance Method Details
#get(**params) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/gambiarra/router.rb', line 17 def get(**params) path = params.delete(:path) @url = build_url(path || history.current_route.path, **params) route = routes.detect { |route| route.path == path } return history.refresh(params) unless route history.add(route) route.respond(**params) end |
#previous_path ⇒ Object
26 27 28 |
# File 'lib/gambiarra/router.rb', line 26 def previous_path history.previous end |