Sha256: 84985175b7cf3402003cd4e96e4c07c880a0639dc9502abd8073fa76d538f435

Contents?: true

Size: 950 Bytes

Versions: 6

Compression:

Stored size: 950 Bytes

Contents

module Lotus
  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

6 entries across 6 versions & 1 rubygems

Version Path
lotus-router-0.5.1 lib/lotus/routing/resource/nested.rb
lotus-router-0.5.0 lib/lotus/routing/resource/nested.rb
lotus-router-0.4.3 lib/lotus/routing/resource/nested.rb
lotus-router-0.4.2 lib/lotus/routing/resource/nested.rb
lotus-router-0.4.1 lib/lotus/routing/resource/nested.rb
lotus-router-0.4.0 lib/lotus/routing/resource/nested.rb