Class: FitApi::Router::Mapper
- Inherits:
-
Object
- Object
- FitApi::Router::Mapper
- Defined in:
- lib/fit_api/router/mapper.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #collection(&block) ⇒ Object
- #controller(controller, &block) ⇒ Object
-
#initialize ⇒ Mapper
constructor
A new instance of Mapper.
- #member(&block) ⇒ Object
- #namespace(path, options = {}, &block) ⇒ Object
- #not_found(to:) ⇒ Object
- #root(to:) ⇒ Object
Constructor Details
#initialize ⇒ Mapper
Returns a new instance of Mapper.
10 11 12 13 |
# File 'lib/fit_api/router/mapper.rb', line 10 def initialize @routes = Hash.new { |h,k| h[k] = [] } @namespaces = [] end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
8 9 10 |
# File 'lib/fit_api/router/mapper.rb', line 8 def routes @routes end |
Instance Method Details
#collection(&block) ⇒ Object
42 43 44 |
# File 'lib/fit_api/router/mapper.rb', line 42 def collection(&block) instance_eval &block end |
#controller(controller, &block) ⇒ Object
56 57 58 59 60 |
# File 'lib/fit_api/router/mapper.rb', line 56 def controller(controller, &block) @controller = controller instance_eval &block @controller = nil end |
#member(&block) ⇒ Object
38 39 40 |
# File 'lib/fit_api/router/mapper.rb', line 38 def member(&block) namespace "/:id", controller: @controller, &block end |
#namespace(path, options = {}, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/fit_api/router/mapper.rb', line 46 def namespace(path, = {}, &block) @namespaces << fix_path(path) if controller = [:controller] || path previous, @controller = @controller, controller end instance_eval &block @controller = previous if controller @namespaces.pop end |
#not_found(to:) ⇒ Object
34 35 36 |
# File 'lib/fit_api/router/mapper.rb', line 34 def not_found(to:) get "/404", to: to end |
#root(to:) ⇒ Object
30 31 32 |
# File 'lib/fit_api/router/mapper.rb', line 30 def root(to:) get "", to: to end |