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, opts = {}) ⇒ 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, #has_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
60 61 62 |
# File 'lib/tripod/resource.rb', line 60 def <=>(other) uri.to_s <=> uri.to_s end |
#==(other) ⇒ Object
performs equality checking on the uris
65 66 67 68 |
# File 'lib/tripod/resource.rb', line 65 def ==(other) self.class == other.class && uri.to_s == other.uri.to_s end |
#===(other) ⇒ Object
performs equality checking on the class
71 72 73 |
# File 'lib/tripod/resource.rb', line 71 def ===(other) other.class == Class ? self.class === other : self == other end |
#eql?(other) ⇒ Boolean
delegates to ==
76 77 78 |
# File 'lib/tripod/resource.rb', line 76 def eql?(other) self == (other) end |
#hash ⇒ Object
80 81 82 |
# File 'lib/tripod/resource.rb', line 80 def hash identity.hash end |
#identity ⇒ Object
a resource is absolutely identified by it’s class and id.
85 86 87 |
# File 'lib/tripod/resource.rb', line 85 def identity [ self.class, self.uri.to_s ] end |
#initialize(uri, opts = {}) ⇒ Resource
Instantiate a Resource.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tripod/resource.rb', line 39 def initialize(uri, opts={}) if opts.is_a?(Hash) graph_uri = opts.fetch(:graph_uri, nil) ignore_graph = opts.fetch(:ignore_graph, false) else graph_uri = opts end 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 unless ignore_graph @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
99 100 101 |
# File 'lib/tripod/resource.rb', line 99 def to_a [ self ] end |
#to_key ⇒ Object
Return the key value for the resource.
95 96 97 |
# File 'lib/tripod/resource.rb', line 95 def to_key (persisted? || destroyed?) ? [ uri.to_s ] : nil end |