Module: Tripod::EagerLoading
Instance Attribute Summary collapse
-
#object_resources ⇒ Object
readonly
array of resources that represent the objects of the triples of this resource.
-
#predicate_resources ⇒ Object
readonly
array of resources that represent the predicates of the triples of this resource.
Instance Method Summary collapse
-
#eager_load_object_triples! ⇒ Object
get all the triples in the db where the object uri is their subject stick the results in this resource’s repo.
-
#eager_load_predicate_triples! ⇒ Object
get all the triples in the db where the predicate uri is their subject stick the results in this resource’s repo.
-
#get_related_resource(resource_uri, class_of_resource_to_create) ⇒ Object
get the resource that represents a particular uri.
Instance Attribute Details
#object_resources ⇒ Object (readonly)
array of resources that represent the objects of the triples of this resource
9 10 11 |
# File 'lib/tripod/eager_loading.rb', line 9 def object_resources @object_resources end |
#predicate_resources ⇒ Object (readonly)
array of resources that represent the predicates of the triples of this resource
6 7 8 |
# File 'lib/tripod/eager_loading.rb', line 6 def predicate_resources @predicate_resources end |
Instance Method Details
#eager_load_object_triples! ⇒ Object
get all the triples in the db where the object uri is their subject stick the results in this resource’s repo
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tripod/eager_loading.rb', line 20 def eager_load_object_triples! object_uris = [] self.get_triples_for_this_resource.each_statement do |statement| object_uris << statement.object if statement.object.uri? end object_uris = object_uris.uniq # in case an object appears > once. graph_of_triples = self.class.describe_uris(object_uris) self.class.add_data_to_repository(graph_of_triples, self.repository) end |
#eager_load_predicate_triples! ⇒ Object
get all the triples in the db where the predicate uri is their subject stick the results in this resource’s repo
13 14 15 16 |
# File 'lib/tripod/eager_loading.rb', line 13 def eager_load_predicate_triples! graph_of_triples = self.class.describe_uris(predicates) self.class.add_data_to_repository(graph_of_triples, self.repository) end |
#get_related_resource(resource_uri, class_of_resource_to_create) ⇒ Object
get the resource that represents a particular uri. If there’s triples in our repo where that uri is the subject, use that to hydrate a resource, otherwise justdo a find against the db.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tripod/eager_loading.rb', line 34 def (resource_uri, class_of_resource_to_create) data_graph = RDF::Graph.new self.repository.query( [ RDF::URI.new(resource_uri.to_s), :predicate, :object] ) do |stmt| data_graph << stmt end if data_graph.empty? r = nil else # it's in our eager loaded repo r = class_of_resource_to_create.new(resource_uri) r.hydrate!(:graph => data_graph) r.new_record = false r end r end |