Class: RoadForest::Resource::RDF::ReadOnly

Inherits:
Webmachine::Resource
  • Object
show all
Defined in:
lib/roadforest/resource/rdf/read-only.rb

Overview

Used for a resource that presents a read-only representation

Direct Known Subclasses

LeafItem, List, ParentItem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject

Returns the value of attribute model.



18
19
20
# File 'lib/roadforest/resource/rdf/read-only.rb', line 18

def model
  @model
end

#traceObject

Returns the value of attribute trace.



18
19
20
# File 'lib/roadforest/resource/rdf/read-only.rb', line 18

def trace
  @trace
end

Class Method Details

.register(method_name) ⇒ Object



12
13
14
# File 'lib/roadforest/resource/rdf/read-only.rb', line 12

def self.register(method_name)
  RoadForest::Resource.registry.add(method_name, self)
end

Instance Method Details

#content_types_providedObject



85
86
87
88
89
# File 'lib/roadforest/resource/rdf/read-only.rb', line 85

def content_types_provided
  model.type_handling.renderers.type_map
rescue => ex
  super
end

#expiresObject



115
116
117
# File 'lib/roadforest/resource/rdf/read-only.rb', line 115

def expires
  @model.expires
end

#finish_requestObject

Add cache-control headers here



100
101
# File 'lib/roadforest/resource/rdf/read-only.rb', line 100

def finish_request
end

#generate_etagObject



107
108
109
# File 'lib/roadforest/resource/rdf/read-only.rb', line 107

def generate_etag
  @model.etag
end

#is_authorized?(header) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
# File 'lib/roadforest/resource/rdf/read-only.rb', line 91

def is_authorized?(header)
  @authorization = @model.authorization(request.method, header)
  if(@authorization == :public || @authorization == :granted)
    return true
  end
  @model.authentication_challenge
end

#last_modifiedObject



111
112
113
# File 'lib/roadforest/resource/rdf/read-only.rb', line 111

def last_modified
  @model.last_modified
end

#method(name) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/roadforest/resource/rdf/read-only.rb', line 75

def method(name)
  if model.nil?
    super
  else
    model.type_handling.fetch(name).method(:call)
  end
rescue KeyError
  super
end

#model_supports(action) ⇒ Object

def known_methods

  super + ["PATCH"]
end


55
56
57
# File 'lib/roadforest/resource/rdf/read-only.rb', line 55

def model_supports(action)
  @model.respond_to?(action)
end

#paramsObject

RoadForest interface



22
23
24
25
26
27
28
# File 'lib/roadforest/resource/rdf/read-only.rb', line 22

def params
  params = Application::Parameters.new do |params|
    params.path_info = @request.path_info
    params.query_params = @request.query_params
    params.path_tokens = @request.path_tokens
  end
end

#request_accept_headerObject



34
35
36
# File 'lib/roadforest/resource/rdf/read-only.rb', line 34

def request_accept_header
  request.headers["Accept"] || "*/*"
end

#request_uriObject



30
31
32
# File 'lib/roadforest/resource/rdf/read-only.rb', line 30

def request_uri
  request.uri.to_s.sub(/[?]\Z/, '')
end

#resource_exists?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/roadforest/resource/rdf/read-only.rb', line 103

def resource_exists?
  @model.exists?
end

#response_body=(body) ⇒ Object



42
43
44
# File 'lib/roadforest/resource/rdf/read-only.rb', line 42

def response_body=(body)
  response.body = body
end

#response_content_type=(type) ⇒ Object



38
39
40
# File 'lib/roadforest/resource/rdf/read-only.rb', line 38

def response_content_type=(type)
  response.headers["Content-Type"] = type
end

#retrieve_modelObject Also known as: retreive_model



46
47
48
# File 'lib/roadforest/resource/rdf/read-only.rb', line 46

def retrieve_model
  absolutize(@model.canonical_host, @model.retrieve)
end

#send(*args) ⇒ Object

Overridden rather than metaprogram content type methods



65
66
67
68
69
70
71
72
73
# File 'lib/roadforest/resource/rdf/read-only.rb', line 65

def send(*args)
  if args.length == 1 and not model.nil?
    model.type_handling.fetch(args.first).call(self)
  else
    super
  end
rescue KeyError
  super
end

#trace?Boolean

Webmachine interface

Returns:

  • (Boolean)


60
61
62
# File 'lib/roadforest/resource/rdf/read-only.rb', line 60

def trace?
  !!@trace
end