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 ### Fixed
- Do not force adding paths with shared named parameter in an specific order (@jwoertink) - 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. - 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 ## [0.3.1] - 2016-07-29
### Added ### Added

View file

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

View file

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

View file

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