Class: RoadForest::TypeHandlers::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/type-handlers/handler.rb

Direct Known Subclasses

RDFHandler

Instance Method Summary collapse

Instance Method Details

#add_child_to(resource) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/roadforest/type-handlers/handler.rb', line 31

def add_child_to(resource)
  interface = resource.interface
  source = resource.request_body
  input_data = network_to_local(interface.my_url, source)

  child_for_interface(resource.interface, input_data)

  build_response(resource)
end

#build_response(resource) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/roadforest/type-handlers/handler.rb', line 41

def build_response(resource)
  interface = resource.interface

  renderer = resource.content_engine.choose_renderer(resource.request_accept_header)
  body = renderer.local_to_network(interface.my_url, interface.response_data)

  resource.response_content_type = renderer.content_type_header
  resource.response_body = body
  if interface.response_location
    resource.redirect_to(interface.response_location)
  end
end

#child_for_interface(interface, data) ⇒ Object



54
55
56
57
# File 'lib/roadforest/type-handlers/handler.rb', line 54

def child_for_interface(interface, data)
  interface.add_child(data)
  interface.processed
end

#get_output(interface) ⇒ Object



66
67
68
69
70
71
# File 'lib/roadforest/type-handlers/handler.rb', line 66

def get_output(interface)
  result = interface.retrieve
  interface.response_data = result
  interface.processed
  result
end

#local_to_network(base_uri, local) ⇒ Object



8
9
10
# File 'lib/roadforest/type-handlers/handler.rb', line 8

def local_to_network(base_uri, local)
  return local
end

#network_to_local(base_uri, network) ⇒ Object



4
5
6
# File 'lib/roadforest/type-handlers/handler.rb', line 4

def network_to_local(base_uri, network)
  return network
end

#parse_for(resource) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/roadforest/type-handlers/handler.rb', line 12

def parse_for(resource)
  source = resource.request_body
  interface = resource.interface
  input_data = network_to_local(interface.my_url, source)

  update_interface(interface, input_data)

  renderer = resource.content_engine.choose_renderer(resource.request_accept_header)
  body = renderer.local_to_network(interface.my_url, interface.response_data)

  build_response(resource)
end

#render_for(resource) ⇒ Object



25
26
27
28
29
# File 'lib/roadforest/type-handlers/handler.rb', line 25

def render_for(resource)
  interface = resource.interface
  output_data = get_output(interface)
  local_to_network(interface.my_url,  output_data)
end

#update_interface(interface, input_data) ⇒ Object



59
60
61
62
63
64
# File 'lib/roadforest/type-handlers/handler.rb', line 59

def update_interface(interface, input_data)
  result = interface.update(input_data)
  interface.response_data = result
  interface.processed
  result
end