Class: Halibut::Adapter::JSON::ResourceExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/halibut/adapter/json.rb

Overview

ResourceExtractor is responsible for deserializing an HAL resource from the JSON representation.

Examples:

extractor = ResourceExtractor.new({})
# => #<Halibut::Adapter::JSON::ResourceExtractor:0x007f8adb92f2a8
extractor.resource
# => #<Halibut::Core::Resource:0x007f8add058fb0

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ ResourceExtractor

Straight-forward, just pass in the JSON string you want to extract the resource from.

Examples:

json = '{"_links":{"self":{"href":"http://example.com"}}}'
ResourceExtractor.new('{}')

Parameters:

  • json (StringIO)

    the json from which to extract the resource


82
83
84
85
86
87
88
89
# File 'lib/halibut/adapter/json.rb', line 82

def initialize(json)
  @halibut = Halibut::Core::Resource.new
  @json    = ::JSON.load(json)

  extract_properties
  extract_links
  extract_embedded_resources
end

Instance Method Details

#resourceObject

This method should be called when the the resource extracted is needed


92
93
94
# File 'lib/halibut/adapter/json.rb', line 92

def resource
  @halibut
end