Class: Ldp::Container

Inherits:
Resource::RdfSource show all
Defined in:
lib/ldp/container.rb

Direct Known Subclasses

Basic

Defined Under Namespace

Classes: Basic, Direct, Indirect

Instance Attribute Summary

Attributes inherited from Resource

#client, #content, #subject

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource::RdfSource

#build_empty_graph, #content, #create, #graph, #graph_class, #initialize

Methods inherited from Resource

#create, #current?, #delete, #get, #head, #initialize, #new?, #reload, #retrieved_content?, #save, #subject_uri, #update, #update_cached_get

Constructor Details

This class inherits a constructor from Ldp::Resource::RdfSource

Class Method Details

.new_from_response(client, subject, data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/ldp/container.rb', line 7

def self.new_from_response client, subject, data
  case
  when data.types.include?(Ldp.indirect_container)
    Ldp::Container::Indirect.new client, subject, data
  when data.types.include?(Ldp.direct_container)
    Ldp::Container::Direct.new client, subject, data
  else
    Ldp::Container::Basic.new client, subject, data
  end
end

Instance Method Details

#add(*args) ⇒ Object

Add a new resource to the LDP container



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ldp/container.rb', line 20

def add *args
  # slug, graph
  # graph
  # slug

  case
  when (args.length > 2 || args.length == 0)

  when (args.length == 2)
    slug, graph_or_content = args
  when (args.first.is_a? RDF::Graph)
    slug = nil
    graph_or_content = args.first
  else
    slug = args.first
    graph_or_content = RDF::Graph.new
  end

  resp = client.post subject, (graph_or_content.is_a?(RDF::Graph) ? graph_or_content.dump(:ttl) : graph_or_content) do |req|
    req.headers['Slug'] = slug
  end

  client.find_or_initialize resp.headers['Location']
end