Skip to content

Commit

Permalink
Add strict parameter to fromurl
Browse files Browse the repository at this point in the history
  • Loading branch information
neelsmith committed Jan 11, 2022
1 parent 40886ae commit 282c639
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CitableBase"
uuid = "d6f014bd-995c-41bd-9893-703339864534"
authors = ["Neel Smith <[email protected]>"]
version = "9.0.1"
version = "10.0.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/citable.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ The inverse of `cex` is `fromcex`. We need two essential pieces of information
```@example book
import CitableBase: fromcex
function fromcex(traitvalue::BookCex, cexsrc::AbstractString, T;
delimiter = "|", configuration = nothing)
delimiter = "|", configuration = nothing, strict = true)
fields = split(cexsrc, delimiter)
urn = Isbn10Urn(fields[1])
CitableBook(urn, fields[2], fields[3])
Expand Down
4 changes: 2 additions & 2 deletions docs/src/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ end
import CitableBase: fromcex
function fromcex(traitvalue::BookCex, cexsrc::AbstractString, T;
delimiter = "|", configuration = nothing)
delimiter = "|", configuration = nothing, strict = true)
fields = split(cexsrc, delimiter)
urn = Isbn10Urn(fields[1])
CitableBook(urn, fields[2], fields[3])
Expand Down Expand Up @@ -323,7 +323,7 @@ Recall from our experience implementing CEX serialization for `CitableBook`s tha

```@example collections
function fromcex(trait::ReadingListCex, cexsrc::AbstractString, T;
delimiter = "|", configuration = nothing)
delimiter = "|", configuration = nothing, strict = true)
lines = split(cexsrc, "\n")
datalines = filter(ln -> !isempty(ln), lines)
Expand Down
22 changes: 12 additions & 10 deletions src/cex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ end
$(SIGNATURES)
"""
function fromcex(cexsrc::AbstractString, T;
delimiter = "|", configuration = nothing)
delimiter = "|",
configuration = nothing,
strict = true)
fromcex(cextrait(T), cexsrc, T,
delimiter = delimiter, configuration = configuration)
delimiter = delimiter, configuration = configuration, strict = strict)
end


Expand All @@ -66,39 +68,39 @@ end
$(SIGNATURES)
"""
function fromcex(fname::AbstractString, T, freader::Type{FileReader};
delimiter = "|", configuration = nothing)
delimiter = "|", configuration = nothing, strict = true)
cexsrc = open(f->read(f, String), fname)
fromcex(cextrait(T), cexsrc, T,
delimiter = delimiter, configuration = configuration)
delimiter = delimiter, configuration = configuration, strict = strict)
end

"""Implement `fromcex` using first string parameter for a URL.
$(SIGNATURES)
"""
function fromcex(url::AbstractString, T, ureader::Type{UrlReader};
delimiter = "|", configuration = nothing)
delimiter = "|", configuration = nothing, strict = true)
cexsrc = HTTP.get(url).body |> String
fromcex(cextrait(T), cexsrc, T,
delimiter = delimiter, configuration = configuration)
delimiter = delimiter, configuration = configuration, strict = strict)
end

"""Implement `fromcex` using first string parameter for raw string data.
$(SIGNATURES)
"""
function fromcex(cexsrc::AbstractString, T, freader::Type{StringReader};
delimiter = "|", configuration = nothing)
delimiter = "|", configuration = nothing, strict = true)
fromcex(cextrait(T), cexsrc, T,
delimiter = delimiter, configuration = configuration)
delimiter = delimiter, configuration = configuration, strict = strict)
end

# Catch attempts to use fromex on NotCexSerializable or on types with out an implementation
"""It is an error to invoke the `fromcex` function on material that is not CEX serializable.
$(SIGNATURES)
"""
function fromcex(::NotCexSerializable, cex, T::Type{<: Any}; delimiter , configuration)
function fromcex(::NotCexSerializable, cex, T::Type{<: Any}; delimiter , configuration, strict)
throw(DomainError(T, "$(T) is not a CexSerializable type."))
end

Expand All @@ -108,6 +110,6 @@ unimplemented trait value.
$(SIGNATURES)
"""
function fromcex(traitvalue::TraitType, cexsrc::AbstractString, T;
delimiter, configuration) where {TraitType <: CexTrait}
delimiter, configuration, strict) where {TraitType <: CexTrait}
throw(DomainError(traitvalue, "`fromcex` is not implemented for trait $(traitvalue) on type $(T)."))
end

0 comments on commit 282c639

Please sign in to comment.