Skip to content

Commit

Permalink
Simplification of setconfig! methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tisztamo committed Sep 2, 2020
1 parent 942c6b1 commit 0d5cc67
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions src/Configs.jl
Expand Up @@ -13,7 +13,7 @@ module Configs
"default.json",
"custom-environment-variables.json"
]

function initconfig(;deployment_key = "DEPLOYMENT", configs_directory = "configs")::NamedTuple
global configs = Dict{String, Any}()
configs_order = copy(configs_defaultorder)
Expand All @@ -31,7 +31,7 @@ module Configs
if file === "custom-environment-variables.json"
parsecustomenv!(newtree)
end
override!(configs, newtree)
override!(configs, newtree)
end
end
(; configs_directory = configs_directory, deployment_key = deployment_key, configs_order = configs_order)
Expand All @@ -50,39 +50,19 @@ module Configs
end
end


function setconfig!(path::String, value::String)
try
value = JSON.parse(value)
value = JSON.parse(value)
catch err
end
value = pathtodict(path, value)
setconfig!(value)
end
function setconfig!(path::String, value::Number)
value = pathtodict(path, value)
setconfig!(value)
end
function setconfig!(path::String, value::Bool)
value = pathtodict(path, value)
setconfig!(value)
end
function setconfig!(path::String, value::Tuple)
value = json(value) |> JSON.parse
value = pathtodict(path, value)
setconfig!(value)
end
function setconfig!(path::String, value::Array)
value = json(value) |> JSON.parse
function setconfig!(path::String, value)
value = pathtodict(path, value)
setconfig!(value)
end
function setconfig!(path::String, value::NamedTuple)
value = json(value) |> JSON.parse
value = pathtodict(path, value)
setconfig!(value)
end
function setconfig!(path::String, value::Dict)
function setconfig!(path::String, value::Union{Tuple, AbstractArray, NamedTuple, Dict})
value = json(value) |> JSON.parse
value = pathtodict(path, value)
setconfig!(value)
Expand All @@ -99,13 +79,13 @@ module Configs
subpaths = split(path, ".")
ref = configs
for i in eachindex(subpaths)
subpath = Symbol(subpaths[i])
subpath = Symbol(subpaths[i])
if haskey(ref, subpath)
length(subpaths) === i && return true
ref = ref[subpath]
else
return false
end
end
end
end
end
end

0 comments on commit 0d5cc67

Please sign in to comment.