Method: Subjoin::Document#initialize

Defined in:
lib/subjoin/document.rb

#initialize(*args) ⇒ Document

Create a document. Parameters can take several forms:

  1. A URI object: Document will be created from the URI

  2. A Hash: The Hash is assumed to be a parsed JSON response and the Document will be created from that

  3. One string: Assumed to be a JSON-API object type. An attempt will be made to map this type to a class that inherits from InheritableResource and to load the create the Document from a URL provided by that class. There is also the assumption that this URL returns all objects of that type.

  4. Two strings: Assumed to be a JSON-API object type and id. The same mapping is attempted as before, and the second parameter is added to the URL

Parameters:

  • args (Array)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/subjoin/document.rb', line 30

def initialize(*args)
  if args.count < 1
    raise ArgumentError.new
  end

  contents = load_by_type(args[0], args[1..-1])

  @meta = load_meta(contents['meta'])
  @links = load_links(contents['links'])
  @included = load_included(contents)
  @data = load_data(contents)
  @jsonapi = load_jsonapi(contents)
end