module ActiveTriples::Persistable

Bundles the core interfaces used by ActiveTriples persistence strategies to treat a graph as persistable. Specificially:

- RDF::Enumerable
- RDF::Mutable

@abstract implement {#graph} as a reference to an `RDF::Graph` or similar.

Public Instance Methods

delete_statement(*args) click to toggle source

@see RDF::Writable.delete_statement

# File lib/active_triples/persistable.rb, line 37
def delete_statement(*args)
  graph.send(:delete_statement, *args)
end
destroy() click to toggle source

Removes the statements in this RDFSource's graph from the persisted graph

@return [Boolean]

# File lib/active_triples/persistable.rb, line 61
def destroy
  persistence_strategy.destroy
end
Also aliased as: destroy!
destroy!()
Alias for: destroy
destroyed?() click to toggle source

@return [Boolean] true if this item is destroyed

# File lib/active_triples/persistable.rb, line 68
def destroyed?
  persistence_strategy.destroyed?
end
graph() click to toggle source

This gives the {RDF::Graph} which represents the current state of this resource.

@return [RDF::Graph] the underlying graph representation of the

`RDFSource`.

@see www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#change-over-time

RDF Concepts and Abstract Syntax comment on "RDF source"
# File lib/active_triples/persistable.rb, line 26
def graph
  persistence_strategy.graph
end
insert_statement(*args) click to toggle source

@see RDF::Writable.insert_statement

# File lib/active_triples/persistable.rb, line 31
def insert_statement(*args)
  graph.send(:insert_statement, *args)
end
persist!(opts={}) click to toggle source

Sends a persistence message to the `persistence_startegy`, saving the `Persistable`.

@return [Boolean]

# File lib/active_triples/persistable.rb, line 77
def persist!(opts={})
  result = false
  return result if opts[:validate] && !valid?
  run_callbacks :persist do
    result = persistence_strategy.persist!
  end
  result
end
persisted?() click to toggle source

Indicates if the resource is persisted.

@see persist @return [Boolean]

# File lib/active_triples/persistable.rb, line 91
def persisted?
  persistence_strategy.persisted?
end
persistence_strategy() click to toggle source

Returns the persistence strategy object that handles this object's persistence

# File lib/active_triples/persistable.rb, line 44
def persistence_strategy
  @persistence_strategy || set_persistence_strategy(RepositoryStrategy)
end
reload() click to toggle source

Repopulates the graph according to the persistence strategy

@return [Boolean]

# File lib/active_triples/persistable.rb, line 99
def reload
  @term_cache ||= {}
  persistence_strategy.reload
end
set_persistence_strategy(klass) click to toggle source

Sets a persistence strategy

@param klass [Class] A class implementing the persistence strategy

interface
# File lib/active_triples/persistable.rb, line 53
def set_persistence_strategy(klass)
  @persistence_strategy = klass.new(self)
end