Add top-level functions for the two boolean RDF.Literal values

This commit is contained in:
Marcel Otto 2018-05-26 02:51:28 +02:00
parent 9b48908e5d
commit 3e5db97ce4
4 changed files with 24 additions and 0 deletions

View file

@ -10,6 +10,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
### Added
- top-level alias functions for constructors of the basic datatypes
- top-level constant functions `RDF.true` and `RDF.false` for the two boolean
RDF.Literal values
[Compare v0.4.1...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.4.1...HEAD)

View file

@ -151,6 +151,9 @@ defmodule RDF do
defdelegate unquote(term)(s, o1, o2, o3, o4, o5), to: RDF.NS.RDF
end
defdelegate unquote(:true)(), to: RDF.Boolean.Value
defdelegate unquote(:false)(), to: RDF.Boolean.Value
defdelegate langString(), to: RDF.NS.RDF
defdelegate unquote(nil)(), to: RDF.NS.RDF

View file

@ -25,3 +25,18 @@ defmodule RDF.Boolean do
def convert(value, opts), do: super(value, opts)
end
defmodule RDF.Boolean.Value do
@moduledoc false
# This module holds the two boolean value literals, so they can be accessed
# directly without needing to construct them every time. They can't
# be defined in the RDF.Boolean module, because we can not use the
# `RDF.Boolean.new` function without having it compiled first.
@xsd_true RDF.Boolean.new(true)
@xsd_false RDF.Boolean.new(false)
def unquote(:true)(), do: @xsd_true
def unquote(:false)(), do: @xsd_false
end

View file

@ -11,4 +11,8 @@ defmodule RDFTest do
end)
end
test "true and false aliases" do
assert RDF.true == RDF.Boolean.new(true)
assert RDF.false == RDF.Boolean.new(false)
end
end