lib/rdf/ldp/indirect_container.rb in rdf-ldp-0.5.1 vs lib/rdf/ldp/indirect_container.rb in rdf-ldp-0.6.0

- old
+ new

@@ -27,10 +27,21 @@ def container_class CONTAINER_CLASSES[:indirect] end ## + # @see Container#create + def create(input, content_type, &block) + super + graph.insert RDF::Statement(subject_uri, + RDF::Vocab::LDP.insertedContentRelation, + RDF::Vocab::LDP.MemberSubject) if + inserted_content_statements.empty? + self + end + + ## # Gives the inserted content relation for the indirect container. If none is # present in the container state, we add `ldp:MemberSubject`, effectively # treating this LDP-IC as an LDP-DC. # # @return [RDF::URI] the inserted content relation; either a predicate term @@ -40,23 +51,15 @@ # exist. # # @see http://www.w3.org/TR/ldp/#dfn-membership-triples def inserted_content_relation statements = inserted_content_statements - case statements.count - when 0 - graph << RDF::Statement(subject_uri, - RDF::Vocab::LDP.insertedContentRelation, - RDF::Vocab::LDP.MemberSubject) - RDF::Vocab::LDP.MemberSubject - when 1 - statements.first.object - else - raise NotAcceptable.new('An LDP-IC MUST have exactly ' \ - 'one inserted content relation triple; found ' \ - "#{statements.count}.") - end + return statements.first.object if statements.count == 1 + + raise NotAcceptable.new('An LDP-IC MUST have exactly ' \ + 'one inserted content relation triple; found ' \ + "#{statements.count}.") end private def inserted_content_statements @@ -74,19 +77,14 @@ return resource.to_uri if predicate == RDF::Vocab::LDP.MemberSubject raise NotAcceptable.new("#{resource.to_uri} is an LDP-NR; cannot add " \ 'it to an IndirectContainer with a content ' \ 'relation.') if resource.non_rdf_source? - - resource statements = resource.graph.query([resource.subject_uri, predicate, :o]) - case statements.count - when 1 - statements.first.object - else - raise NotAcceptable.new("#{statements.count} inserted content" \ - "#{predicate} found on #{resource.to_uri}") - end + return statements.first.object if statements.count == 1 + + raise NotAcceptable.new("#{statements.count} inserted content" \ + "#{predicate} found on #{resource.to_uri}") end end end