Class: ActiveFedora::SparqlInsert
- Inherits:
-
Object
- Object
- ActiveFedora::SparqlInsert
- Defined in:
- lib/active_fedora/sparql_insert.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #build ⇒ Object
- #execute(uri) ⇒ Object
-
#initialize(changes, subject = ::RDF::URI.new(nil)) ⇒ SparqlInsert
constructor
A new instance of SparqlInsert.
Constructor Details
#initialize(changes, subject = ::RDF::URI.new(nil)) ⇒ SparqlInsert
Returns a new instance of SparqlInsert.
6 7 8 9 |
# File 'lib/active_fedora/sparql_insert.rb', line 6 def initialize(changes, subject = ::RDF::URI.new(nil)) @changes = changes @subject = subject end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
4 5 6 |
# File 'lib/active_fedora/sparql_insert.rb', line 4 def changes @changes end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
4 5 6 |
# File 'lib/active_fedora/sparql_insert.rb', line 4 def subject @subject end |
Instance Method Details
#build ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_fedora/sparql_insert.rb', line 17 def build query = deletes(subject).join query += "INSERT { \n" query += changes.map do |_, result| result.map do |statement| ::RDF::Query::Pattern.new(subject: subject, predicate: statement.predicate, object: statement.object).to_s end.join("\n") end.join("\n") query += "\n}\n WHERE { }" query end |
#execute(uri) ⇒ Object
11 12 13 14 15 |
# File 'lib/active_fedora/sparql_insert.rb', line 11 def execute(uri) result = ActiveFedora.fedora.connection.patch(uri, build, "Content-Type" => "application/sparql-update") return true if result.status == 204 raise "Problem updating #{result.status} #{result.body}" end |