Fix RDF.resource?/1 to not fail when called with unresolvable atoms

This commit is contained in:
Marcel Otto 2018-09-16 22:28:46 +02:00
parent f4877bbc65
commit dfb88ac65e
2 changed files with 20 additions and 2 deletions

View file

@ -33,6 +33,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
### Changed
- Elixir versions < 1.6 are no longer supported
- `RDF.resource?/1` does not fail anymore when called with unresolvable atoms
but returns `false` instead
- `RDF.String.new/2` and `RDF.String.new!/2` produce a `rdf:langString` when
given a language tag
- `RDF.IRI.absolute/2` returns `nil` if the given base is not absolute, instead

View file

@ -55,10 +55,16 @@ defmodule RDF do
## Examples
Supposed `EX` is a `RDF.Vocabulary.Namespace` and `Foo` is not.
iex> RDF.resource?(RDF.iri("http://example.com/resource"))
true
iex> RDF.resource?(EX.resource)
true
iex> RDF.resource?(EX.Resource)
true
iex> RDF.resource?(Foo.Resource)
false
iex> RDF.resource?(RDF.bnode)
true
iex> RDF.resource?(RDF.integer(42))
@ -69,8 +75,12 @@ defmodule RDF do
def resource?(value)
def resource?(%IRI{}), do: true
def resource?(%BlankNode{}), do: true
def resource?(atom) when is_atom(atom) and atom not in ~w[true false nil]a,
do: resource?(Namespace.resolve_term(atom))
def resource?(atom) when is_atom(atom) and atom not in ~w[true false nil]a do
resource?(Namespace.resolve_term(atom))
rescue
RDF.Namespace.UndefinedTermError -> false
end
def resource?(_), do: false
@doc """
@ -78,10 +88,16 @@ defmodule RDF do
## Examples
Supposed `EX` is a `RDF.Vocabulary.Namespace` and `Foo` is not.
iex> RDF.term?(RDF.iri("http://example.com/resource"))
true
iex> RDF.term?(EX.resource)
true
iex> RDF.term?(EX.Resource)
true
iex> RDF.term?(Foo.Resource)
false
iex> RDF.term?(RDF.bnode)
true
iex> RDF.term?(RDF.integer(42))