class RoadForest::Augment::Affordance::Links

Public Instance Methods

apply(term) { |node, type, Af.Null| ... } click to toggle source
# File lib/roadforest/augment/affordance.rb, line 44
def apply(term)
  if term.uri.host != canonical_uri.hostname
    return
  end

  case term.resource
  when Webmachine::Dispatcher::NotFoundResource
    node = ::RDF::Node.new
    yield [node, ::RDF.type, Af.Null]
    yield [node, Af.target, term.uri]
  else
    if term.resource.allowed_methods.include?("GET")
      embeddable = ContentHandling::MediaTypeList.build(["image/jpeg"])

      if embeddable.matches?(term.type_list)
        node = ::RDF::Node.new
        yield [node, ::RDF.type, Af.Embed]
        yield [node, Af.target, term.uri]
      else
        node = ::RDF::Node.new
        yield [node, ::RDF.type, Af.Navigate]
        yield [node, Af.target, term.uri]
      end
      each_grant_token("GET", term) do |token|
        yield [node, Af.authorizedBy, token]
      end
    end
  end
end