grape-route-helpers icon indicating copy to clipboard operation
grape-route-helpers copied to clipboard

Multi-version API helper method lookup error

Open waldofe opened this issue 8 years ago • 1 comments

Grape gives the ability to define multi-version API's with fallbacks (i.e. if one hits an endpoint that doesn't exists, it goes up or down a version: version %w(v3 v4), using: :path). Using the array version definition in order to achieve that make it impossible to use grape-route-helpers, which raises NoMethodError: undefined method scan for ['v3', 'v4']:Array in the lookup process.

Steps to reproduce

  1. Define a multi-version Grape API such as version %w(v3 v4), using: :path
  2. Run rake grape:route_helpers

At this point it will raise NoMethodError: undefined method scan for ['v3', 'v4']:Array. I'm not sure if always taking the last element on the array will make sense in every scenario. I'm willing to work on it, any suggestions?

waldofe avatar Mar 06 '17 19:03 waldofe

Update: For some reason on tests route_version reaches as a String on the following method:

    def route_versions
      version_pattern = /[^\[",\]\s]+/
      if route_version
        route_version.scan(version_pattern)
      else
        [nil]
      end
    end

While outside tests, route_version is an Array.

waldofe avatar Apr 06 '17 00:04 waldofe