Module: Tripod::Resource
Overview
module for all domain objects that need to be persisted to the database as resources
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#graph_uri ⇒ Object
readonly
Returns the value of attribute graph_uri.
-
#new_record ⇒ Object
readonly
Returns the value of attribute new_record.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes included from State
Attributes included from EagerLoading
#object_resources, #predicate_resources
Attributes included from Repository
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
default comparison is via the uri.
-
#==(other) ⇒ Object
performs equality checking on the uris.
-
#===(other) ⇒ Object
performs equality checking on the class.
-
#eql?(other) ⇒ Boolean
delegates to ==.
- #hash ⇒ Object
-
#identity ⇒ Object
a resource is absolutely identified by it’s class and id.
-
#initialize(uri, graph_uri = nil) ⇒ Resource
Instantiate a
Resource. - #to_a ⇒ Object
-
#to_key ⇒ Object
Return the key value for the resource.
Methods included from State
#destroyed?, #new_record?, #persisted?
Methods included from Serialization
#to_json, #to_nt, #to_rdf, #to_text, #to_ttl
Methods included from EagerLoading
#eager_load_object_triples!, #eager_load_predicate_triples!, #get_related_resource
Methods included from Repository
#get_triples_for_this_resource, #hydrate!, #repository_as_graph, #retrieve_triples_from_database
Methods included from Persistence
#destroy, #save, #save!, #update_attribute, #update_attributes
Methods included from Attributes
#read_attribute, #write_attribute
Methods included from Predicates
#append_to_predicate, #predicates, #read_predicate, #remove_predicate, #write_predicate
Instance Attribute Details
#graph_uri ⇒ Object (readonly)
Returns the value of attribute graph_uri.
23 24 25 |
# File 'lib/tripod/resource.rb', line 23 def graph_uri @graph_uri end |
#new_record ⇒ Object (readonly)
Returns the value of attribute new_record.
22 23 24 |
# File 'lib/tripod/resource.rb', line 22 def new_record @new_record end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
24 25 26 |
# File 'lib/tripod/resource.rb', line 24 def uri @uri end |
Instance Method Details
#<=>(other) ⇒ Object
default comparison is via the uri
49 50 51 |
# File 'lib/tripod/resource.rb', line 49 def <=>(other) uri.to_s <=> uri.to_s end |
#==(other) ⇒ Object
performs equality checking on the uris
54 55 56 57 |
# File 'lib/tripod/resource.rb', line 54 def ==(other) self.class == other.class && uri.to_s == uri.to_s end |
#===(other) ⇒ Object
performs equality checking on the class
60 61 62 |
# File 'lib/tripod/resource.rb', line 60 def ===(other) other.class == Class ? self.class === other : self == other end |
#eql?(other) ⇒ Boolean
delegates to ==
65 66 67 |
# File 'lib/tripod/resource.rb', line 65 def eql?(other) self == (other) end |
#hash ⇒ Object
69 70 71 |
# File 'lib/tripod/resource.rb', line 69 def hash identity.hash end |
#identity ⇒ Object
a resource is absolutely identified by it’s class and id.
74 75 76 |
# File 'lib/tripod/resource.rb', line 74 def identity [ self.class, self.uri.to_s ] end |
#initialize(uri, graph_uri = nil) ⇒ Resource
Instantiate a Resource.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tripod/resource.rb', line 35 def initialize(uri, graph_uri=nil) raise Tripod::Errors::UriNotSet.new('uri missing') unless uri @uri = RDF::URI(uri.to_s) @repository = RDF::Repository.new @new_record = true run_callbacks :initialize do graph_uri ||= self.class.get_graph_uri @graph_uri = RDF::URI(graph_uri) if graph_uri self.rdf_type = self.class.get_rdf_type if respond_to?(:rdf_type=) && self.class.get_rdf_type end end |
#to_a ⇒ Object
88 89 90 |
# File 'lib/tripod/resource.rb', line 88 def to_a [ self ] end |
#to_key ⇒ Object
Return the key value for the resource.
84 85 86 |
# File 'lib/tripod/resource.rb', line 84 def to_key (persisted? || destroyed?) ? [ uri.to_s ] : nil end |