Ensure code samples in docs can be executed

This commit is contained in:
Luis Lavena 2016-11-05 15:24:27 -03:00
parent a6984844bd
commit 961a98dd02
4 changed files with 33 additions and 32 deletions

View File

@ -8,6 +8,7 @@ so please check *Changed* and *Removed* notes before upgrading.
### Fixed
- Do not force adding paths with shared named parameter in an specific order (@jwoertink)
- Give proper name to `Radix::VERSION` spec when running in verbose mode.
- Ensure code samples in docs can be executed.
## [0.3.1] - 2016-07-29
### Added

View File

@ -14,10 +14,10 @@ module Radix
# methods within `Tree`.
#
# ```
# node = Node.new("/", :root)
# node.children << Node.new("a", :a)
# node.children << Node.new("bc", :bc)
# node.children << Node.new("def", :def)
# node = Radix::Node.new("/", :root)
# node.children << Radix::Node.new("a", :a)
# node.children << Radix::Node.new("bc", :bc)
# node.children << Radix::Node.new("def", :def)
# node.sort!
#
# node.priority
@ -42,16 +42,16 @@ module Radix
# * Any other type of key will receive priority based on its size.
#
# ```
# Node(Nil).new("a").priority
# Radix::Node(Nil).new("a").priority
# # => 1
#
# Node(Nil).new("abc").priority
# Radix::Node(Nil).new("abc").priority
# # => 3
#
# Node(Nil).new("*filepath").priority
# Radix::Node(Nil).new("*filepath").priority
# # => 0
#
# Node(Nil).new(":query").priority
# Radix::Node(Nil).new(":query").priority
# # => 1
# ```
getter priority : Int32
@ -66,13 +66,13 @@ module Radix
#
# ```
# # Good, node type is inferred from payload (Symbol)
# node = Node.new("/", :root)
# node = Radix::Node.new("/", :root)
#
# # Good, node type is now Int32 but payload is optional
# node = Node(Int32).new("/")
# node = Radix::Node(Int32).new("/")
#
# # Error, node type cannot be inferred (compiler error)
# node = Node.new("/")
# node = Radix::Node.new("/")
# ```
def initialize(@key : String, @payload : T? = nil, @placeholder = false)
@children = [] of Node(T)
@ -82,7 +82,7 @@ module Radix
# Changes current *key*
#
# ```
# node = Node(Nil).new("a")
# node = Radix::Node(Nil).new("a")
# node.key
# # => "a"
#
@ -94,7 +94,7 @@ module Radix
# This will also result in a new priority for the node.
#
# ```
# node = Node(Nil).new("a")
# node = Radix::Node(Nil).new("a")
# node.priority
# # => 1
#
@ -129,11 +129,11 @@ module Radix
# This ensures highest priority nodes are listed before others.
#
# ```
# root = Node(Nil).new("/")
# root.children << Node(Nil).new("*filepath") # node.priority => 0
# root.children << Node(Nil).new(":query") # node.priority => 1
# root.children << Node(Nil).new("a") # node.priority => 1
# root.children << Node(Nil).new("bc") # node.priority => 2
# root = Radix::Node(Nil).new("/")
# root.children << Radix::Node(Nil).new("*filepath") # node.priority => 0
# root.children << Radix::Node(Nil).new(":query") # node.priority => 1
# root.children << Radix::Node(Nil).new("a") # node.priority => 1
# root.children << Radix::Node(Nil).new("bc") # node.priority => 2
# root.sort!
#
# root.children.map &.priority

View File

@ -2,16 +2,16 @@ require "./node"
module Radix
# A Result is the comulative output of walking our [Radix tree](https://en.wikipedia.org/wiki/Radix_tree)
# `Tree` implementation.
# `Radix::Tree` implementation.
#
# It provides helpers to retrieve the information obtained from walking
# our tree using `Tree#find`
# our tree using `Radix::Tree#find`
#
# This information can be used to perform actions in case of the *path*
# that was looked on the Tree was found.
#
# A Result is also used recursively by `Tree#find` when collecting extra
# information like *params*.
# A Result is also used recursively by `Radix::Tree#find` when collecting
# extra information like *params*.
class Result(T)
@key : String?
@ -28,11 +28,11 @@ module Radix
# the result.
#
# ```
# result = Result(Symbol).new
# result = Radix::Result(Symbol).new
# result.found?
# # => false
#
# root = Node(Symbol).new("/", :root)
# root = Radix::Node(Symbol).new("/", :root)
# result.use(root)
# result.found?
# # => true
@ -44,10 +44,10 @@ module Radix
# Returns a String built based on the nodes used in the result
#
# ```
# node1 = Node(Symbol).new("/", :root)
# node2 = Node(Symbol).new("about", :about)
# node1 = Radix::Node(Symbol).new("/", :root)
# node2 = Radix::Node(Symbol).new("about", :about)
#
# result = Result(Symbol).new
# result = Radix::Result(Symbol).new
# result.use node1
# result.use node2
#
@ -58,7 +58,7 @@ module Radix
# When no node has been used, returns an empty String.
#
# ```
# result = Result(Nil).new
# result = Radix::Result(Nil).new
# result.key
# # => ""
# ```

View File

@ -45,7 +45,7 @@ module Radix
# defined placeholder.
#
# ```
# tree = Tree(Symbol).new
# tree = Radix::Tree(Symbol).new
#
# # / (:root)
# tree.add "/", :root
@ -64,7 +64,7 @@ module Radix
# segments of the given *path*.
#
# ```
# tree = Tree(Symbol).new
# tree = Radix::Tree(Symbol).new
#
# # / (:root)
# tree.add "/", :root
@ -84,7 +84,7 @@ module Radix
# lower priority against other nodes.
#
# ```
# tree = Tree(Symbol).new
# tree = Radix::Tree(Symbol).new
#
# # / (:root)
# tree.add "/", :root
@ -208,7 +208,7 @@ module Radix
# endpoint is found (or not).
#
# ```
# tree = Tree(Symbol).new
# tree = Radix::Tree(Symbol).new
# tree.add "/about", :about
#
# result = tree.find "/products"