Sha256: 9a00d880b2878fa793cb7c241d3ec8cf873f2a6fa9277ff358b292ca8e9d9243

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

class Usher
  class Node
    # The response from {Usher::Node::Root#lookup}. Adds some convenience methods for common parameter manipulation.
    class Response < Struct.new(:path, :params_as_array, :remaining_path, :matched_path, :only_trailing_delimiters)
      
      # The params from recognition
      # @return [Array<Symbol, String>] The parameters detected from recognition returned as an array of arrays.
      def params
        @params ||= path.convert_params_array(params_as_array)
      end

      # @return [Boolean] The state of partial matching
      def partial_match?
        !remaining_path.nil?
      end

      # The params from recognition
      # @return [Hash<Symbol, String>] The parameters detected from recognition returned as a hash.
      def params_as_hash
        @params_as_hash ||= params_as_array.inject({}){|hash, val| hash[path.dynamic_keys[hash.size]] = val; hash}
      end

      # @return [Object] The destination assigned to the matching enclosed path.
      def destination
        path && path.route.destination
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
usher-0.7.5 lib/usher/node/response.rb