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 Graphs
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
#build_multifield_query, #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 Dirty
#attribute_change, #attribute_changed?, #attribute_will_change!, #changed, #changed_attributes, #changes, #post_persist
Methods included from Embeds
#embedded_are_valid, #get_embeds
Methods included from Fields
Methods included from Persistence
#destroy, #save, #save!, #update_attribute, #update_attributes
Methods included from RdfType
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.
21 22 23 |
# File 'lib/tripod/resource.rb', line 21 def graph_uri @graph_uri end |
#new_record ⇒ Object (readonly)
Returns the value of attribute new_record.
20 21 22 |
# File 'lib/tripod/resource.rb', line 20 def new_record @new_record end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
22 23 24 |
# File 'lib/tripod/resource.rb', line 22 def uri @uri end |
Instance Method Details
#<=>(other) ⇒ Object
default comparison is via the uri
58 59 60 |
# File 'lib/tripod/resource.rb', line 58 def <=>(other) uri.to_s <=> other.uri.to_s end |
#==(other) ⇒ Object
performs equality checking on the uris
63 64 65 66 |
# File 'lib/tripod/resource.rb', line 63 def ==(other) self.class == other.class && uri.to_s == other.uri.to_s end |
#===(other) ⇒ Object
performs equality checking on the class
69 70 71 |
# File 'lib/tripod/resource.rb', line 69 def ===(other) other.class == Class ? self.class === other : self == other end |
#eql?(other) ⇒ Boolean
delegates to ==
74 75 76 |
# File 'lib/tripod/resource.rb', line 74 def eql?(other) self == (other) end |
#hash ⇒ Object
78 79 80 |
# File 'lib/tripod/resource.rb', line 78 def hash identity.hash end |
#identity ⇒ Object
a resource is absolutely identified by it’s class and id.
83 84 85 |
# File 'lib/tripod/resource.rb', line 83 def identity [ self.class, self.uri.to_s ] end |
#initialize(uri, opts = {}) ⇒ Resource
Instantiate a Resource
.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tripod/resource.rb', line 37 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 set_rdf_type end end |
#to_a ⇒ Object
97 98 99 |
# File 'lib/tripod/resource.rb', line 97 def to_a [ self ] end |
#to_key ⇒ Object
Return the key value for the resource.
93 94 95 |
# File 'lib/tripod/resource.rb', line 93 def to_key (persisted? || destroyed?) ? [ uri.to_s ] : nil end |