Skip to content

Commit 67e5483

Browse files
authored
Merge pull request #27 from oxinabox/ox/show_load
Show load and file_extensions in accessors
2 parents a2e4441 + 8073ccb commit 67e5483

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

docs/src/utilities.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import AbstractFBCModels as A
1212

1313
A.accessors()
1414

15-
@test length(A.accessors()) == 35 #src
15+
@test length(A.accessors()) == 37 #src
1616

17-
@test length(A.required_accessors()) == 11 #src
17+
@test length(A.required_accessors()) == 13 #src
1818

1919
# You do not need to overload all of them (e.g., if you model does not have any
2020
# genes you can completely omit all gene-related functions). The main required

src/utils.jl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,12 @@ end
2828
unimplemented(t::Type, x::Symbol) =
2929
error("AbstractFBCModels interface method $x is not implemented for type $t")
3030

31+
3132
"""
3233
$(TYPEDSIGNATURES)
3334
3435
Provide a `methodswith`-style listing of accessors that the model implementors
3536
may implement.
36-
37-
For typesystem reasons, the list **will not contain** methods for
38-
[`load`](@ref) and [`filename_extensions`](@ref) that dispatch on type objects.
39-
You should implement these as well.
40-
41-
See also [`required_accessors`](@ref) for the minimal list that must be implemented.
4237
"""
4338
function accessors()
4439
ms = Method[]
@@ -48,9 +43,29 @@ function accessors()
4843
methodswith(AbstractFBCModels.AbstractFBCModel, f, ms)
4944
end
5045
end
46+
47+
append!(ms, _type_accessors())
48+
return ms
49+
end
50+
51+
function _type_accessors()
52+
# special case: some "accessors" take the Type argument instead of actual instance
53+
ms = Method[]
54+
for f in (AbstractFBCModels.load, AbstractFBCModels.filename_extensions)
55+
for m in methods(f)
56+
m.sig isa UnionAll || continue
57+
# Deep magic: basically this matches on `f(::Type{A},...) where A<:AbstractFBCModel`
58+
type_param = Base.unwrap_unionall(m.sig).parameters[2].parameters[1].ub
59+
if type_param == AbstractFBCModels.AbstractFBCModel
60+
push!(ms, m)
61+
end
62+
end
63+
end
64+
5165
return ms
5266
end
5367

68+
5469
"""
5570
$(TYPEDSIGNATURES)
5671
@@ -70,6 +85,7 @@ function required_accessors()
7085
for f in REQUIRED_ACCESSORS
7186
methodswith(AbstractFBCModels.AbstractFBCModel, f, ms)
7287
end
88+
append!(ms, _type_accessors())
7389
return ms
7490
end
7591

0 commit comments

Comments
 (0)