Sha256: e5fab7a5a3c19aa0b715840c1de585aeef6e689a7001c90588bb80439d71e8b3

Contents?: true

Size: 951 Bytes

Versions: 8

Compression:

Stored size: 951 Bytes

Contents

module Hanami
  module Routing
    class Resource
      # Helper class to calculate nested path
      #
      # @api private
      # @since 0.4.0
      class Nested
        # @api private
        # @since 0.4.0
        SEPARATOR = '/'.freeze

        # @api private
        # @since 0.4.0
        def initialize(resource_name, resource)
          @resource_name = resource_name.to_s.split(SEPARATOR)
          @resource      = resource
          @path          = []
          _calculate(@resource_name.dup, @resource)
        end

        # @api private
        # @since 0.4.0
        def to_path
          @path.reverse!.pop
          @resource_name.zip(@path).flatten.join
        end

        private

        def _calculate(param_wildcard, resource = nil)
          return if resource.nil?
          @path << resource.wildcard_param(param_wildcard.pop)
          _calculate(param_wildcard, resource.parent)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hanami-router-1.0.0.beta2 lib/hanami/routing/resource/nested.rb
hanami-router-1.0.0.beta1 lib/hanami/routing/resource/nested.rb
hanami-router-0.8.1 lib/hanami/routing/resource/nested.rb
hanami-router-0.8.0 lib/hanami/routing/resource/nested.rb
hanami-router-0.7.0 lib/hanami/routing/resource/nested.rb
hanami-router-0.6.2 lib/hanami/routing/resource/nested.rb
hanami-router-0.6.1 lib/hanami/routing/resource/nested.rb
hanami-router-0.6.0 lib/hanami/routing/resource/nested.rb