Class: Shaf::Responder::Hal
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#controller, #options, #resource
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
#build_response, call, #initialize, mime_type, #preload_links, use_as_default!
Constructor Details
This class inherits a constructor from Shaf::Responder::Base
Class Method Details
.can_handle?(resource) ⇒ Boolean
7 8 9 10 11 12 13 14 15 |
# File 'lib/shaf/responder/hal.rb', line 7 def self.can_handle?(resource) return false if resource.is_a? StandardError if resource.is_a? Class return false if resource <= Shaf::Profile end true end |
Instance Method Details
#body ⇒ Object
17 18 19 |
# File 'lib/shaf/responder/hal.rb', line 17 def body @body ||= generate_json end |
#lookup_rel(rel, response) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/shaf/responder/hal.rb', line 21 def lookup_rel(rel, response) hal = response.serialized_hash links = hal&.dig(:_links, rel.to_sym) return [] unless links links = [links] unless links.is_a? Array links.map do |link| { href: link[:href], as: 'fetch', crossorigin: 'anonymous' } end end |