Class: Sasquatch::Changeset
- Inherits:
-
Object
- Object
- Sasquatch::Changeset
- Defined in:
- lib/sasquatch/changeset.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
-
#subject_of_change ⇒ Object
readonly
Returns the value of attribute subject_of_change.
Instance Method Summary collapse
- #add_statements(stmts) ⇒ Object
- #changeset_statement(stmt, action) ⇒ Object
-
#initialize(subject_of_change, resource = nil) ⇒ Changeset
constructor
A new instance of Changeset.
- #remove_statements(stmts) ⇒ Object
Constructor Details
#initialize(subject_of_change, resource = nil) ⇒ Changeset
Returns a new instance of Changeset.
30 31 32 33 34 35 36 37 38 |
# File 'lib/sasquatch/changeset.rb', line 30 def initialize(subject_of_change, resource=nil) @resource = RDF::Node.new unless resource @subject_of_change = subject_of_change @statements = [] @statements.concat [RDF::Statement.new(@resource, RDF.type, RDF::Talis::Changeset.ChangeSet), RDF::Statement.new(@resource, RDF::Talis::Changeset.changeReason, "Generated in Platform Party"), RDF::Statement.new(@resource, RDF::Talis::Changeset.createdDate, Time.now), RDF::Statement.new(@resource, RDF::Talis::Changeset.subjectOfChange, subject_of_change)] end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
29 30 31 |
# File 'lib/sasquatch/changeset.rb', line 29 def resource @resource end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
29 30 31 |
# File 'lib/sasquatch/changeset.rb', line 29 def statements @statements end |
#subject_of_change ⇒ Object (readonly)
Returns the value of attribute subject_of_change.
29 30 31 |
# File 'lib/sasquatch/changeset.rb', line 29 def subject_of_change @subject_of_change end |
Instance Method Details
#add_statements(stmts) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/sasquatch/changeset.rb', line 48 def add_statements(stmts) stmts = [stmts] if stmts.is_a?(RDF::Statement) stmts.each do |stmt| next unless stmt raise ArgumentError unless stmt.subject == @subject_of_change @statements.concat changeset_statement(stmt, :addition) end end |
#changeset_statement(stmt, action) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/sasquatch/changeset.rb', line 57 def changeset_statement(stmt, action) s = RDF::Node.new [RDF::Statement.new(@resource, RDF::Talis::Changeset.send(action), s), RDF::Statement.new(s, RDF.type, RDF.to_rdf+"Statement"), RDF::Statement.new(s, RDF.subject, stmt.subject), RDF::Statement.new(s, RDF.predicate, stmt.predicate), RDF::Statement.new(s, RDF.object, stmt.object)] end |
#remove_statements(stmts) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/sasquatch/changeset.rb', line 40 def remove_statements(stmts) stmts = [stmts] if stmts.is_a?(RDF::Statement) stmts.each do |stmt| raise ArgumentError unless stmt.subject == @subject_of_change @statements.concat changeset_statement(stmt, :removal) end end |