Module: Shaf::Responder

Defined in:
lib/shaf/responder.rb,
lib/shaf/responder/hal.rb,
lib/shaf/responder/base.rb,
lib/shaf/responder/html.rb,
lib/shaf/responder/alps_json.rb,
lib/shaf/responder/problem_json.rb

Defined Under Namespace

Classes: AlpsJson, Base, Hal, Html, ProblemJson, Response

Constant Summary collapse

MEDIA_TYPE_SUFFIX_PATTERN =
%r{(.*)/([^+]+)\+(.*)}.freeze

Class Method Summary collapse

Class Method Details

.defaultObject



34
35
36
# File 'lib/shaf/responder.rb', line 34

def default
  responders.default
end

.default=(responder) ⇒ Object



30
31
32
# File 'lib/shaf/responder.rb', line 30

def default=(responder)
  responders.default = responder
end

.for(request, resource) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/shaf/responder.rb', line 20

def for(request, resource)
  return Responder::ProblemJson if resource.is_a?(Errors::NotAcceptableError)

  types = supported_responders_for(resource).map(&:mime_type)
  types = move_html_to_last(types)

  mime = preferred_type(request, types)
  responders[mime] or raise Errors::NotAcceptableError
end

.register(responder) ⇒ Object



9
10
11
# File 'lib/shaf/responder.rb', line 9

def register(responder)
  uninitialized << responder
end

.unregister(responder) ⇒ Object



13
14
15
16
17
18
# File 'lib/shaf/responder.rb', line 13

def unregister(responder)
  responders.delete_if { |_, r| r == responder }
  supported_responders.each do |_klass, responders|
    responders.delete_if { |r| r == responder }
  end
end