Class: ApiTransformer::Routes
- Inherits:
-
Object
- Object
- ApiTransformer::Routes
- Defined in:
- lib/api_transformer/routes.rb
Overview
Collection of routes
Instance Method Summary collapse
- #add(args) ⇒ Object
- #find(raw_method, path) ⇒ Object
-
#initialize ⇒ Routes
constructor
A new instance of Routes.
Constructor Details
#initialize ⇒ Routes
Returns a new instance of Routes.
4 5 6 |
# File 'lib/api_transformer/routes.rb', line 4 def initialize @routes = {} end |
Instance Method Details
#add(args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/api_transformer/routes.rb', line 8 def add(args) pattern, path_params = parse_path_definition(args[:path]) route = Route.new( path_params: path_params, options: args[:options], block: args[:block], failure_handlers: args[:failure_handlers], helper_blocks: args[:helper_blocks] ) store_route(args[:method], pattern, route) end |
#find(raw_method, path) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/api_transformer/routes.rb', line 22 def find(raw_method, path) method = raw_method.downcase.to_sym return unless @routes[method] pattern, route = @routes[method].find do |pattern, _| path.match(pattern) end [route, path_params(path, route, pattern)] end |