Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rdf lists should only have one RDF.rest node #174

Merged
merged 1 commit into from
Aug 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/active_fedora/rdf_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ module RdfList

attr_reader :graph, :subject

# RdfList is a node of a linked list structure.
# The RDF.first predicate points to the contained object
# The RDF.rest predicate points to the next node in the list or
# RDF.nil if this is the final node.
# @see http://www.w3.org/TR/rdf-schema/#ch_list
def initialize(graph, subject)
@graph = graph
@subject = subject
first = graph.query([subject, RDF.first, nil]).first
last = graph.query([subject, RDF.rest, nil]).first
graph.insert([subject, RDF.first, RDF.nil]) unless first
graph.insert([subject, RDF.rest, RDF.nil])
graph.insert([subject, RDF.rest, RDF.nil]) unless last
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be OK to add a line or two of documentation to this method? It's not obvious to me what all the first and last business is doing or why.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so simple: http://www.w3.org/TR/rdf-schema/#ch_list ;) It's for building descriptions of lists and list-like structures.

end

# Override assign_nested_attributes
Expand Down
5 changes: 4 additions & 1 deletion spec/unit/rdf_list_nested_attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Topic
topic.elementList.first[0].elementValue.should == ["Baseball"]
topic.elementList.first[1].should be_kind_of(TopicElement)
topic.elementList.first[1].elementValue.should == ["Football"]

# only one rdf:rest rdf:nil
topic.graph.query([nil, RDF.rest, RDF.nil]).size.should == 1
end
it "should insert new nodes of varying types into RdfLists (rather than calling .build)" do
# It's Not clear what the syntax should be when an RDF list contains multiple types of sub-nodes.
Expand Down Expand Up @@ -107,4 +110,4 @@ class Topic
topic.elementList.first[3].elementValue.should == ["Twentieth Century"]
end
end
end
end