Skip to content

Commit

Permalink
Merge pull request #232 from ActiveTriples/feature/rdf-source-specs
Browse files Browse the repository at this point in the history
Minor fixes to RDFSource & specs
  • Loading branch information
jcoyne committed Aug 8, 2016
2 parents 95dba72 + 6e1fa0b commit 3e11e8b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 89 deletions.
13 changes: 8 additions & 5 deletions lib/active_triples/rdf_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def attributes=(values)
if reflections.has_property?(key)
set_value(key, value)
elsif nested_attributes_options
.keys.find { |k| key == "#{k}_attributes" }
.keys.any? { |k| key == "#{k}_attributes" }
send("#{key}=".to_sym, value)
else
raise ArgumentError, "No association found for name `#{key}'. " \
Expand Down Expand Up @@ -249,7 +249,7 @@ def parent=(parent)
def rdf_subject
@rdf_subject ||= RDF::Node.new
end
alias_method :to_term, :rdf_subject
alias to_term rdf_subject

##
# Returns `nil` as the `graph_name`. This behavior mimics an `RDF::Graph`
Expand Down Expand Up @@ -366,7 +366,7 @@ def fetch(*args, &_block)
yield(self)
else
raise "#{self} is a blank node; " \
"Cannot fetch a resource without a URI" if node?
'Cannot fetch a resource without a URI' if node?
raise e
end
end
Expand Down Expand Up @@ -599,11 +599,14 @@ def rewrite_statement_uris(old_subject, new_subject)
# @raise [RuntimeError] no valid RDF term could be built
def get_uri(uri_or_str)
return uri_or_str.to_term if uri_or_str.respond_to? :to_term
return uri_or_str if uri_or_str.is_a? RDF::Node

uri_or_node = RDF::Resource.new(uri_or_str)
return uri_or_node if uri_or_node.valid?

uri_or_str = uri_or_str.to_s
return RDF::URI(base_uri.to_s) / uri_or_str if base_uri && !uri_or_str.start_with?(base_uri.to_s)
return RDF::URI(base_uri.to_s) / uri_or_str if
base_uri && !uri_or_str.start_with?(base_uri.to_s)

raise "could not make a valid RDF::URI from #{uri_or_str}"
end

Expand Down

0 comments on commit 3e11e8b

Please sign in to comment.