Method: ActiveTriples::Relation#build
- Defined in:
- lib/active_triples/relation.rb
#build(attributes = {}) ⇒ Object
Builds a node with the given attributes, adding it to the relation.
Nodes are built using the configured class_name for the relation. Attributes passed in the Hash argument are set on the new node through ‘RDFSource#attributes=`. If the attribute keys are not valid properties on the built node, we raise an error.
@todo: clarify class behavior; it is actually tied to type, in some cases.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/active_triples/relation.rb', line 190 def build(attributes={}) new_subject = attributes.fetch('id') { RDF::Node.new } make_node(new_subject).tap do |node| node.attributes = attributes.except('id') if parent.kind_of? List::ListResource parent.list << node elsif node.kind_of? RDF::List self.push node.rdf_subject else self.push node end end end |