Sha256: 14c54972ab6e7ff8ae34ce367d839a1cbb98fa04f4c861aee868bbd266ad95e4

Contents?: true

Size: 997 Bytes

Versions: 19

Compression:

Stored size: 997 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

        # @api private
        # @since 0.4.0
        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

19 entries across 19 versions & 1 rubygems

Version Path
hanami-router-1.3.2 lib/hanami/routing/resource/nested.rb
hanami-router-1.3.1 lib/hanami/routing/resource/nested.rb
hanami-router-1.3.0 lib/hanami/routing/resource/nested.rb
hanami-router-1.3.0.beta1 lib/hanami/routing/resource/nested.rb
hanami-router-1.2.0 lib/hanami/routing/resource/nested.rb
hanami-router-1.2.0.rc2 lib/hanami/routing/resource/nested.rb
hanami-router-1.2.0.rc1 lib/hanami/routing/resource/nested.rb
hanami-router-1.2.0.beta2 lib/hanami/routing/resource/nested.rb
hanami-router-1.2.0.beta1 lib/hanami/routing/resource/nested.rb
hanami-router-1.1.1 lib/hanami/routing/resource/nested.rb
hanami-router-1.1.0 lib/hanami/routing/resource/nested.rb
hanami-router-1.1.0.rc1 lib/hanami/routing/resource/nested.rb
hanami-router-1.1.0.beta3 lib/hanami/routing/resource/nested.rb
hanami-router-1.1.0.beta2 lib/hanami/routing/resource/nested.rb
hanami-router-1.1.0.beta1 lib/hanami/routing/resource/nested.rb
hanami-router-1.0.1 lib/hanami/routing/resource/nested.rb
hanami-router-1.0.0 lib/hanami/routing/resource/nested.rb
hanami-router-1.0.0.rc1 lib/hanami/routing/resource/nested.rb
hanami-router-1.0.0.beta3 lib/hanami/routing/resource/nested.rb