Commit graph

75 commits

Author SHA1 Message Date
Luis Lavena
f764b3aed2 Fix incorrect lookup in non-root nodes
Given the following non-root tree:

  tree = Tree(Symbol).new
  tree.add "/prefix/", :prefix
  tree.add "/prefix/foo", :foo

Attempt to lookup for `/foo` was incorrectly identifying `:foo` entry as
the correct value.

This change ensures that child nodes of the current node are not scanned
if key and path being looked up do not match.

Fixes #27
2021-01-30 23:35:53 -03:00
Luis Lavena
f8df18baf1
Merge pull request #30 from luislavena/fix/partial-shared-key-glob
Correct lookup with shared key and glob
2021-01-30 22:39:31 -03:00
Luis Lavena
93247cd33a Correct lookup with shared key and glob
Properly skip nodes and continue lookup when the key to be looked up
shares partial elements with others.

With the following scenario:

  tree = Radix::Tree(Symbol).new
  tree.add "/*glob", :catch_all
  tree.add "/resources", :resources
  tree.add "/robots.txt", :robots

When attempt to lookup for `/reviews`, it will now correctly return
`:catch_all` as found.

Fixes #23
2021-01-30 22:25:26 -03:00
Luis Lavena
edcdddcd73
Merge pull request #28 from luislavena/fix/remove-unused-key
Remove `Radix::Result#key` usage in the codebase
2021-01-30 21:59:28 -03:00
Luis Lavena
3d0e8de952 Remove Radix::Result#key usage in the codebase
No longer expose internal functionality used only in tests. Reduce the
exposed elements of `Radix::Result` to focus on payload only.

Also remove the associated array used to collect all the traversed nodes
when performing the lookup.

NOTE: this is a breaking change
2021-01-30 21:09:52 -03:00
Luis Lavena
09a334a53d
Add CI status badge
Show GitHub actions status badge.
2021-01-30 21:08:30 -03:00
Luis Lavena
410dbc01c4
Merge pull request #29 from luislavena/dev/use-github-ci
Migrate to GitHub Actions
2021-01-30 21:04:48 -03:00
Luis Lavena
9a1b56c020 Use GitHub Actions for CI
Runs against Ubunut/macOS for latest version and introduce weekly on
schedule to run it against nightly versions.
2021-01-30 20:59:59 -03:00
Luis Lavena
b7fcf6fcb0 Remove Travis from CI
No longer use Travis for this project.
2021-01-30 20:42:39 -03:00
Luis Lavena
97b16625a4 Merge branch 'remove-dead-code' 2021-01-30 19:11:47 -03:00
Luis Lavena
c57ad82282 cleanup: remove old deprecation approach
Remove no longer used code.
2021-01-30 19:01:37 -03:00
Luis Lavena
cc7b59ec77 Prepare for release: v0.3.9 2019-01-02 19:03:19 +01:00
Luis Lavena
27ca183bd9 CHANGELOG: document merges
[skip ci]
2019-01-02 19:01:45 +01:00
Luis Lavena
461509d7c1
Merge pull request #26 from silasb/catch-all-continues-to-check-for-key-chars-when-path-chars-differ
Catch all will continue checking key chars when path chars differ
2019-01-02 18:53:50 +01:00
silasb
728aea392e Explaination of why we are returning early 2018-09-08 14:36:20 -04:00
silasb
2346312185 Fixing test description 2018-09-08 14:30:12 -04:00
silasb
1e410910e4 Catch all will continue checking key chars when path chars differ 2018-09-08 14:10:46 -04:00
Luis Lavena
905bd9e14b Add simper spec runners (with make)
Allow usage of `make spec` to run project's specs against default
Crystal compiler or one that can be supplied with `CRYSTAL`
environment variable.

Also provide ways to run in automated mode thanks to watchexec.

[skip ci]
2017-09-22 17:57:54 -03:00
Luis Lavena
211418416a Prepare for release: v0.3.8 2017-03-12 13:02:56 -03:00
Luis Lavena
7a398d463c Merge pull request #20 from luislavena/improve-unicode-support
Improves support for non-ascii keys in a tree
2017-03-12 12:59:16 -03:00
Luis Lavena
97ef407aec Improves support for non-ascii keys in a tree
Properly recognize and organize non-ascii keys into nodes, allowing
usage with entries in other languages.

With this change, it is possible to use 2 or 3 bytes wide characters
(Unicode) without issues:

    tree = Radix::Tree(Symbol).new
    tree.add "/", :root
    tree.add "/日本語", :japanese
    tree.add "/日本は難しい", :japanese_is_difficult

Which produces the following node hierarchy:

    # ( 1) /       (:root)
    # ( 6)  日本
    # (12)    は難しい (:japanese_is_difficult)
    # ( 3)    語    (:japanese)

And lookup works as expected:

    result = tree.find "/日本は難しい"
    puts result.found? # => true
2017-03-12 12:49:13 -03:00
Luis Lavena
7460033db3 Merge pull request #22 from luislavena/fix-incorrect-shared-key
Fix incorrect lookup on non-shared partial keys
2017-03-12 12:46:27 -03:00
Luis Lavena
9895655a8a Fix incorrect lookup on non-shared partial keys
Given the following nodes in a tree:

    # ( 8) /product
    # ( 4)         /new
    # ( 1)         s
    tree = Radix::Tree(Symbol).new
    tree.add "/products", :products
    tree.add "/product/new", :product_new

It failed to properly identify `/products` during lookup:

    result = tree.find "/products"
    result.found? # => false

Caused by incorrect comparsion of `s` remaining path against `/new`
node instead of continue comparison with the next one.

Fixes #21
2017-03-12 12:36:05 -03:00
Luis Lavena
b81ac70758 Prepare for release: v0.3.7 2017-02-04 13:00:14 -03:00
Luis Lavena
c04be1b4bd Display latest release badge in README
Use shields.io and display GitHub latest release version.

Update Travis CI badge to use shields.io too.

[skip ci]
2017-02-04 12:56:52 -03:00
Luis Lavena
68e21bcff1 Merge pull request #19 from luislavena/improve-node-sorting
Makes node prioritization insertion-independent
2017-02-04 17:47:17 +02:00
Luis Lavena
1764332123 Makes node prioritization insertion-independent
The order in which nodes were inserted into a tree might produce
failures in lookup mechanism.

    tree = Radix::Tree(Symbol).new
    tree.add "/one/:id", :one
    tree.add "/one-longer/:id", :two

    result = tree.find "/one-longer/10"

    # expected `true`
    result.found? # => false

In above example, reversing the order of insertion solved the issue,
but exposed the naive sorting/prioritization mechanism used.

This change improves that by properly identifying the kind of node
being evaluated and compared against others of the same kind.

It is now possible to know in advance if a node contains an special
condition (named parameter or globbing) or is a normal one:

    node = Radix::Node(Nil).new("a")
    node.normal? # => true

    node = Radix::Node(Nil).new(":query")
    node.named? # => true

    node = Radix::Node(Nil).new("*filepath")
    node.glob? # => true

Which helps out with prioritization of nodes:

- A normal node ranks higher than a named one
- A named node ranks higher than a glob one
- On two of same kind, ranks are based on priority

With this change in place, above example works as expected:

    tree = Radix::Tree(Symbol).new
    tree.add "/one/:id", :one
    tree.add "/one-longer/:id", :two

    result = tree.find "/one-longer/10"

    result.found? # => true

Fixes #18
2017-02-04 12:36:38 -03:00
Luis Lavena
0dc6e174d2 Prepare for release: v0.3.6 2017-01-18 12:29:43 -03:00
Luis Lavena
1eabf1a23f Merge pull request #17 from luislavena/fix-sorting-named-parameters
Lower named and glob node priority to fix lookup issue
2017-01-18 12:24:52 -03:00
Luis Lavena
9163860e4d Lowers named and glob node priority to fix lookup issue
Given two similar keys, one short and one with named parameter, lookup
was incorrectly picking up the named parameter version instead of the
specific one:

    tree = Radix::Tree(Symbol).new
    tree.add "/tag-edit/:id", :edit_tag
    tree.add "/tag-edit2", :alternate_edit_tag

    result = tree.find("/tag-edit2")
    result.found? # => false

The order of insertion (named before specific) was causing the
lookup mechanism to validate it before checking the other options.

With the changes present here, short or long keys will be affected
anymore by named or globbed keys present when sharing part of the
key.

Fixes kemalcr/kemal#293
2017-01-17 14:40:16 -03:00
Luis Lavena
40b8e26ba5 spec(Tree): Replace deprecated MemoryIO
Crystal 0.20 introduced a change so `MemoryIO` is know known as
`IO::Memory`.

Since no current spec was using the deprecation redirect, there was
warning raised.

Fixes #16
2016-12-03 10:55:48 -03:00
Luis Lavena
bed664a936 misc(git): update ignores for latest version of Crystal
[skip ci]
2016-11-24 21:29:13 -03:00
Luis Lavena
a0fcdb896e misc(Travis): silence annoying success emails
Got it, it worked, nice, no need to email me on every push about it.

[skip ci]
2016-11-24 21:27:29 -03:00
Luis Lavena
6c8981af91 Prepare for release: v0.3.5 2016-11-24 21:04:15 -03:00
Luis Lavena
c81694fbec Merge pull request #15 from luislavena/14-fix-catch-all-lookup
Corrects lookup issue with catch all and shared key
2016-11-24 21:00:50 -03:00
Luis Lavena
95b6638f1a fix(Tree): corrects lookup issue with catch all and shared key
Lookup was failing when part of the given path matched a key at the
first character, even when the rest of the key didn't match.

It was not possible place a catch all an another key at the same
level that started with same character.

This change ensures that all shared part between path and key is
compared prior assuming usage of that node as part of the lookup.

Closes #14
2016-11-24 20:52:07 -03:00
Luis Lavena
6880b341a6 Prepare for release: v0.3.4
Yank v0.3.3 due mismatched `Radix::VERSION` version.
2016-11-12 15:49:32 -03:00
Luis Lavena
82b9c915e1 Prepare for release: v0.3.3 2016-11-12 13:58:42 -03:00
Luis Lavena
61f58207fd Merge pull request #13 from luislavena/inclusive-catch-all
Allows catch all to be used as optional globbing
2016-11-12 13:45:26 -03:00
Luis Lavena
c8d20afc54 fix(Tree): allows catch all to be used as optional globbing
Catch all parameter was limited to be used *after* a slash (`/`) on
a path (ie. `/members/*trailing`).

Attempts to use it immediately after the path (ie. `/members*trailing`)
was not properly identified or captured.

This change ensures catch all can be used as globbing, allowing capture
of anything after the matching path.

Closes #12
2016-11-12 13:10:44 -03:00
Luis Lavena
e4c53ba7b9 Prepare for release: v0.3.2 2016-11-05 15:32:44 -03:00
Luis Lavena
961a98dd02 Ensure code samples in docs can be executed 2016-11-05 15:24:27 -03:00
Luis Lavena
a6984844bd spec(VERSION): format naming for better verbose output
Avoid `Radix::VERSION` being evaluated and use the string version
for presentation purposes.
2016-11-05 15:02:45 -03:00
Luis Lavena
07f7576895 Merge pull request #10 from luislavena/fix-shared-key-branching
Allow insert paths with shared keys unordered
2016-11-05 14:56:29 -03:00
Luis Lavena
d7c0779ac9 fix(Tree): allows insert paths with shared keys unordered
When adding new nodes into the tree, the lookup mechanism failed
to detect same named parameter was already added to it, raising
an exception.

Example:

    tree = Radix::Tree(Symbol).new
    tree.add "/members/:id/edit", :member_edit
    tree.add "/members/export",   :members_export
    tree.add "/members/:id/videos", :member_videos # Exception

This fix ensures that comparison is done key by key, even if they
are inserted into the tree in a different order.

Closes #9
2016-11-05 14:16:09 -03:00
Luis Lavena
e55d144413 doc(Tree): adjust documentation for correct usage
Code samples embedded into `Tree` documentation weren't accurate,
so this corrects them to be up-to-date on usage.

[skip ci]
2016-08-14 11:15:01 +01:00
Luis Lavena
95d2d0aedb Prepare for release: v0.3.1 2016-07-29 18:27:51 +02:00
Luis Lavena
77789be285 Add VERSION constant for runtime usage
Introduce `Radix::VERSION` to be used at runtime by users of the
library for any purpose this will help them (expose them, use
conditional blocks or similar).

Also add spec that checks that defined versions in both `shard.yml`
and `Radix::VERSION` matches to avoid messing up releases.
2016-05-16 20:37:41 -03:00
Luis Lavena
54d3b627a2 Prepare for release: v0.3.0 2016-04-16 17:19:29 -03:00
Luis Lavena
08db441c9a Merge pull request #8 from luislavena/define-payload-type
Introduce types for forward compiler compatibility

Closes #7
2016-04-16 17:06:16 -03:00