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, #response_graph

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

.for(client, subject, data) ⇒ Object Also known as: new_from_response



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

def self.for(client, subject, data)
  case
  when data.types.include?(RDF::Vocab::LDP.IndirectContainer)
    Ldp::Container::Indirect.new client, subject, data
  when data.types.include?(RDF::Vocab::LDP.DirectContainer)
    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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ldp/container.rb', line 30

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::Enumerable)
    slug = nil
    graph_or_content = args.first
  else
    slug = args.first
    graph_or_content = build_empty_graph
  end

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

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

#containsObject



22
23
24
25
26
# File 'lib/ldp/container.rb', line 22

def contains
  @contains ||= Hash[graph.query(predicate: RDF::Vocab::LDP.contains).map do |x|
    [x.object, Ldp::Resource::RdfSource.new(client, x.object, contained_graph(x.object))]
  end]
end