Module: VersionedRoutes::RouteVersions

Defined in:
lib/versioned_routes/route_versions.rb

Instance Method Summary collapse

Instance Method Details

#version(number, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/versioned_routes/route_versions.rb', line 5

def version(number, &block)
  @set.current_version_number = number
  @set.current_version.block = block

  versions = @set
             .version_info
             .values
             .select { |info| info.number <= number }
             .sort_by(&:number)
             .reverse

  scope path: "v#{number}", as: "v#{number}" do
    versions.each do |info|
      scope module: "v#{info.number}", defaults: { api_version: info.number } do
        info.block.call if info.number <= number
      end
    end
  end

  @set.current_version_number = nil
end