Class: RoadForest::Augment::Affordance::Links

Inherits:
RoadForest::Augment::Augmentation show all
Includes:
GrantTokens
Defined in:
lib/roadforest/augment/affordance.rb

Instance Method Summary collapse

Methods included from GrantTokens

#each_grant_token

Methods inherited from RoadForest::Augment::Augmentation

#canonical_uri, #initialize, object_follows, object_precedes, register_for_objects, register_for_subjects, #router, subject_follows, subject_precedes

Constructor Details

This class inherits a constructor from RoadForest::Augment::Augmentation

Instance Method Details

#apply(term) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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