Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Resource discovery rt #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
return resource type based upon list of resource_links
  • Loading branch information
mcr committed Nov 16, 2017
commit b6930a5047ccd0388b6a70fafe43ac2e88514733
34 changes: 30 additions & 4 deletions lib/david/resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,37 @@ def _call(env)

@env = env

filtered = routes_hash.select { |link| filter(link) }
body = filtered.keys.map(&:to_s).join(',')
queries = @env[QUERY_STRING].split('&')
Copy link
Owner

Choose a reason for hiding this comment

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

Could the filtering by rt not be done in the filter method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At first, I tried to do exactly that. (see: AnimaGUS-minerva@d463c9d) The problem is that one then has complex logic to decide how many times to return a resource which may be duplicated by others, so I changed my mind.

Copy link
Owner

Choose a reason for hiding this comment

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

Can't we dedup them after filtering?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought about dedup, and I tried that, but it just seemed like a backwards way to do things. Can you explain why you think it's better to do this in filter? It seems like really we are doing two different things in this query, and why conflate them?
I also am thinking that if we moved the resource_discovery out of david and somehow into the application, that it would be easier to support Sinatra.

body_links = []

if queries.length > 0
queries.each {|q|
# XXX do these need to %-unescaped now?
(item, value) = q.split('=')

case item
when 'href'
# TODO If query end in '*', match on prefix.
# Otherwise match on whole string.
# https://tools.ietf.org/html/rfc6690#section-4.1
filtered = routes_hash.select { |link| filter(link) }
body_links = filtered.keys

when 'rt'
byebug
unless resource_links[value].blank?
body_links << sprintf("<%s>", ERB::Util.html_escape(resource_links[value]))
end

else
false
end
}
end

# TODO On multicast, do not respond if result set empty.
body = body_links.map(&:to_s).join(',')

# TODO On multicast, do not respond if result set empty.
[
200,
{
Expand Down Expand Up @@ -58,7 +84,7 @@ def clean_routes
end

def resource_links
Hash[routes.collect { |r| [r[3], r[4]] }]
@resource_links ||= Hash[routes.collect { |r| [r[3], r[4]] }]
end

def delete_format!(route)
Expand Down