Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor part processing (remove PartProcessor) #31

Merged
merged 4 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/lucky_router/fragment.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,29 @@ class LuckyRouter::Fragment(T)
# the final step to finding the payload is to search for a matching request method
getter method_to_payload = Hash(String, T).new

def find(parts : Array(String), method : String) : Match(T) | NoMatch
MatchFinder(T).new(self, parts: parts, method: method).run
end

def process_parts(parts : Array(String), method : String, payload : T)
PartProcessor(T).new(self, parts: parts, method: method, payload: payload).run
self
leaf_fragment = parts.reduce(self) { |fragment, part| fragment.add_part(part) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

leaf_fragment.method_to_payload[method] = payload
end

def find(parts : Array(String), method : String) : Match(T) | NoMatch
MatchFinder(T).new(self, parts: parts, method: method).run
def add_part(part : String) : Fragment(T)
if part.starts_with?(":")
paulcsmith marked this conversation as resolved.
Show resolved Hide resolved
dynamic_fragment = self.dynamic_part ||= create_dynamic_fragment(part)
dynamic_fragment.fragment
else
static_parts[part] ||= Fragment(T).new
end
end

private def create_dynamic_fragment(part : String) : DynamicFragment(T)
part_without_colon = part[1...]
DynamicFragment(T).new(
name: part_without_colon,
fragment: Fragment(T).new
)
end
end
66 changes: 0 additions & 66 deletions src/lucky_router/part_processor.cr

This file was deleted.