Module: RDF::Mutable
- Extended by:
- Util::Aliasing::LateBound
- Included in:
- Graph, Repository, Transaction
- Defined in:
- lib/rdf/mixin/mutable.rb
Overview
Classes that include this module must implement the methods ‘#insert_statement`, `#delete_statement` and `#each_statement`.
Instance Method Summary collapse
-
#<<(data) ⇒ Mutable
Inserts RDF data into ‘self`.
-
#clear ⇒ Mutable
(also: #clear!)
Deletes all RDF statements from ‘self`.
-
#delete(*statements) ⇒ Mutable
(also: #delete!)
Deletes RDF statements from ‘self`.
-
#immutable? ⇒ Boolean
Returns ‘true` if `self` is immutable.
-
#insert(*statements) ⇒ Mutable
Inserts RDF statements into ‘self`.
-
#load(filename, options = {}) ⇒ void
(also: #load!)
Loads RDF statements from the given file or URL into ‘self`.
-
#mutable? ⇒ Boolean
Returns ‘true` if `self` is mutable.
-
#update(*statements) ⇒ Mutable
(also: #update!)
Updates RDF statements in ‘self`.
Methods included from Util::Aliasing::LateBound
Methods included from Writable
Methods included from Readable
Instance Method Details
#<<(data) ⇒ Mutable
Inserts RDF data into ‘self`.
65 66 67 68 69 |
# File 'lib/rdf/mixin/mutable.rb', line 65 def <<(data) raise TypeError.new("#{self} is immutable") if immutable? super # RDF::Writable#<< end |
#clear ⇒ Mutable Also known as: clear!
Deletes all RDF statements from ‘self`.
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/rdf/mixin/mutable.rb', line 141 def clear raise TypeError.new("#{self} is immutable") if immutable? if respond_to?(:clear_statements) clear_statements else delete_statements(self) end return self end |
#delete(*statements) ⇒ Mutable Also known as: delete!
Deletes RDF statements from ‘self`.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rdf/mixin/mutable.rb', line 113 def delete(*statements) raise TypeError.new("#{self} is immutable") if immutable? statements.map! do |value| case when value.respond_to?(:each_statement) delete_statements(value) nil when (statement = Statement.from(value)).valid? statement else delete_statements(query(value)) nil end end statements.compact! delete_statements(statements) unless statements.empty? return self end |
#immutable? ⇒ Boolean
Returns ‘true` if `self` is immutable.
27 28 29 |
# File 'lib/rdf/mixin/mutable.rb', line 27 def immutable? !mutable? end |
#insert(*statements) ⇒ Mutable
Inserts RDF statements into ‘self`.
78 79 80 81 82 |
# File 'lib/rdf/mixin/mutable.rb', line 78 def insert(*statements) raise TypeError.new("#{self} is immutable") if immutable? super # RDF::Writable#insert end |
#load(filename, options = {}) ⇒ void Also known as: load!
This method returns an undefined value.
Loads RDF statements from the given file or URL into ‘self`.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rdf/mixin/mutable.rb', line 37 def load(filename, = {}) raise TypeError.new("#{self} is immutable") if immutable? Reader.open(filename, {:base_uri => filename}.merge()) do |reader| if [:context] statements = [] reader.each_statement do |statement| statement.context = [:context] statements << statement end insert_statements(statements) statements.size else insert_statements(reader) nil end end end |
#mutable? ⇒ Boolean
Returns ‘true` if `self` is mutable.
18 19 20 |
# File 'lib/rdf/mixin/mutable.rb', line 18 def mutable? writable? end |
#update(*statements) ⇒ Mutable Also known as: update!
Updates RDF statements in ‘self`.
‘#update([subject, predicate, object])` is equivalent to `#delete([subject, predicate, nil])` followed by `#insert([subject, predicate, object])` unless `object` is `nil`.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rdf/mixin/mutable.rb', line 94 def update(*statements) raise TypeError.new("#{self} is immutable") if immutable? statements.each do |statement| if (statement = Statement.from(statement)) delete([statement.subject, statement.predicate, nil]) insert(statement) if statement.has_object? end end end |