Sha256: 63c0765082b743731e23872dd6218c171a4382c47cb8ed2b1e116c87ce995e3f

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 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 success of the response
      # @return [Boolean] Always returns true
      def succeeded?
        true
      end

      # 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.8.0 lib/usher/node/response.rb