Class: RoadForest::Interface::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/interface/application.rb

Instance Attribute Summary collapse

Utility methods collapse

Authorization collapse

Instance Method Summary collapse

Constructor Details

#initialize(route_name, params, path_provider, services) ⇒ Application

Returns a new instance of Application.



12
13
14
15
16
17
18
19
# File 'lib/roadforest/interface/application.rb', line 12

def initialize(route_name, params, path_provider, services)
  @route_name = route_name
  @params = params
  @path_provider = path_provider
  @services = services
  @data = nil
  @response_values = {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



20
21
22
# File 'lib/roadforest/interface/application.rb', line 20

def data
  @data
end

#paramsObject (readonly)

Returns the value of attribute params.



20
21
22
# File 'lib/roadforest/interface/application.rb', line 20

def params
  @params
end

#path_providerObject (readonly)

Returns the value of attribute path_provider.



20
21
22
# File 'lib/roadforest/interface/application.rb', line 20

def path_provider
  @path_provider
end

#response_valuesObject (readonly)

Returns the value of attribute response_values.



21
22
23
# File 'lib/roadforest/interface/application.rb', line 21

def response_values
  @response_values
end

#route_nameObject (readonly)

Returns the value of attribute route_name.



20
21
22
# File 'lib/roadforest/interface/application.rb', line 20

def route_name
  @route_name
end

#servicesObject (readonly)

Returns the value of attribute services.



20
21
22
# File 'lib/roadforest/interface/application.rb', line 20

def services
  @services
end

Instance Method Details

#add_child(results) ⇒ Object

Raises:

  • (NotImplementedError)


148
149
150
# File 'lib/roadforest/interface/application.rb', line 148

def add_child(results)
  raise NotImplementedError
end

#authentication_challengeObject



73
74
75
# File 'lib/roadforest/interface/application.rb', line 73

def authentication_challenge
  services.authz.challenge(:realm => "Roadforest")
end

#authorization(request) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/roadforest/interface/application.rb', line 63

def authorization(request)
  method = request.method
  required = required_grants(method)
  if required.empty?
    :public
  else
    services.authz.authorization(request, required)
  end
end

#canonical_hostObject



79
80
81
# File 'lib/roadforest/interface/application.rb', line 79

def canonical_host
  services.canonical_host
end

#canonical_uriObject



41
42
43
# File 'lib/roadforest/interface/application.rb', line 41

def canonical_uri
  url_for(route_name, params)
end

#create_payloadObject



140
141
142
# File 'lib/roadforest/interface/application.rb', line 140

def create_payload
  nil
end

#deleteObject



157
158
159
# File 'lib/roadforest/interface/application.rb', line 157

def delete
  false
end

#error_data(status) ⇒ Object

group Resource interface



88
89
90
# File 'lib/roadforest/interface/application.rb', line 88

def error_data(status)
  nil
end

#etagObject



96
97
98
# File 'lib/roadforest/interface/application.rb', line 96

def etag
  nil
end

#exists?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/roadforest/interface/application.rb', line 92

def exists?
  !data.nil?
end

#expiresObject



132
133
134
# File 'lib/roadforest/interface/application.rb', line 132

def expires
  nil
end

#interface_for(route_name = nil, params = nil) ⇒ Object



37
38
39
# File 'lib/roadforest/interface/application.rb', line 37

def interface_for(route_name = nil, params = nil)
  path_provider.interface_for(route_name, params || self.params)
end

#last_modifiedObject



100
101
102
# File 'lib/roadforest/interface/application.rb', line 100

def last_modified
  nil
end

#my_pathObject



45
46
47
# File 'lib/roadforest/interface/application.rb', line 45

def my_path
  path_for(route_name, params)
end

#my_urlObject



49
50
51
# File 'lib/roadforest/interface/application.rb', line 49

def my_url
  canonical_uri.to_s
end

#path_for(route_name = nil, params = nil) ⇒ Object



25
26
27
# File 'lib/roadforest/interface/application.rb', line 25

def path_for(route_name = nil, params = nil)
  path_provider.path_for(route_name, params || self.params)
end

#pattern_for(route_name, vals = nil, extra = nil) ⇒ Object



33
34
35
# File 'lib/roadforest/interface/application.rb', line 33

def pattern_for(route_name, vals = nil, extra = nil)
  path_provider.pattern_for(route_name, vals, extra)
end

#processedObject



124
125
126
127
128
129
130
# File 'lib/roadforest/interface/application.rb', line 124

def processed
  [:location, :data].each do |key|
    unless @response_values.has_key?(key)
      @response_values[key] = nil
    end
  end
end

#required_grants(method) ⇒ Object



57
58
59
60
61
# File 'lib/roadforest/interface/application.rb', line 57

def required_grants(method)
  services.authz.build_grants do |grants|
    grants.add(:admin)
  end
end

#resetObject

XXX remove?



83
84
# File 'lib/roadforest/interface/application.rb', line 83

def reset #XXX remove?
end

#response_dataObject



114
115
116
117
118
# File 'lib/roadforest/interface/application.rb', line 114

def response_data
  @response_values.fetch(:data) do
    raise ProcessingSequenceError, "Location not available until request processed"
  end
end

#response_data=(data) ⇒ Object



120
121
122
# File 'lib/roadforest/interface/application.rb', line 120

def response_data=(data)
  @response_values[:data] = data
end

#response_locationObject



104
105
106
107
108
# File 'lib/roadforest/interface/application.rb', line 104

def response_location
  @response_values.fetch(:location) do
    raise ProcessingSequenceError, "Location not available until request processed"
  end
end

#response_location=(location) ⇒ Object



110
111
112
# File 'lib/roadforest/interface/application.rb', line 110

def response_location=(location)
  @response_values[:location] = location
end

#retrieveObject Also known as: retreive

Raises:

  • (NotImplementedError)


152
153
154
# File 'lib/roadforest/interface/application.rb', line 152

def retrieve
  raise NotImplementedError
end

#update(data) ⇒ Object

Raises:

  • (NotImplementedError)


144
145
146
# File 'lib/roadforest/interface/application.rb', line 144

def update(data)
  raise NotImplementedError
end

#update_payloadObject



136
137
138
# File 'lib/roadforest/interface/application.rb', line 136

def update_payload
  nil
end

#url_for(route_name, params = nil) ⇒ Object



29
30
31
# File 'lib/roadforest/interface/application.rb', line 29

def url_for(route_name, params = nil)
  ::RDF::URI.new(Addressable::URI.parse(canonical_host.to_s).join(path_for(route_name, params)))
end