Skip to content

Commit

Permalink
Temporal solution: find loads attributes (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
msalvadores committed Jan 29, 2013
1 parent a4005f6 commit 05a24e3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 3 additions & 6 deletions lib/goo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def self.where(*args)
return items.values
end

def self.find(param, store_name=nil)
def self.find(param, load_attributes=true, store_name=nil)

if (self.goop_settings[:unique][:fields].nil? or
self.goop_settings[:unique][:fields].length != 1)
Expand All @@ -424,18 +424,15 @@ def self.find(param, store_name=nil)
"Inconsistent model behaviour. There are #{ins.length} instance with #{key_attribute} => #{param}"
end
return nil if ins.length == 0
ins[0].load if load_attributes
return ins[0]
elsif param.kind_of? RDF::IRI
iri = param
inst = self.new
inst.internals.lazy_loaded
inst.resource_id = param
return inst
else
raise ArgumentError,
"#{self.class.name}.find only accepts String or RDF::IRI as input."
end
return self.load(iri,store_name,false)
return self.load(iri,store_name,load_attributes)
end

def self.load(resource_id, store_name=nil,load_attributes=true)
Expand Down
2 changes: 0 additions & 2 deletions test/test_model_find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,12 @@ def test_where_with_nested
def test_find
create_toy_parts()
white = Color.find("white")
white.load unless white.loaded?
assert_instance_of Color, white
assert white.resource_id.value.end_with? "white"
assert_equal "white", white.code

iri_blue = Color.prefix + "blue"
blue = Color.find(RDF::IRI.new(iri_blue))
blue.load unless blue.loaded?
assert_instance_of Color, blue
assert blue.resource_id.value.end_with? "blue"
assert_equal "blue", blue.code
Expand Down

0 comments on commit 05a24e3

Please sign in to comment.