Skip to content
Snippets Groups Projects
Commit 2aba521c authored by Eric Franz's avatar Eric Franz
Browse files

simplify initialization of manifest attrs

add defaults, merge with provided hash, but use default if a hash value
is  nil
parent 69905c4e
No related branches found
No related tags found
No related merge requests found
......@@ -50,14 +50,20 @@ documentation: |
InvalidManifest.new(e)
end
def defaults
{"name" => "", "provider" => "", "description" => "", "documentation" => ""}
end
def initialize(opts)
raise InvalidContentError.new unless(opts && opts.respond_to?(:fetch))
raise InvalidContentError.new unless(opts && opts.is_a?(Hash))
# merge with defaults, ignoring nil
opts = defaults.merge(opts) { |key, oldval, newval| newval || oldval }
#FIXME: add sensible default for app name?
@name = (opts.fetch("name", "") || "")
@provider = (opts.fetch("provider", "") || "")
@description = (opts.fetch("description", "") || "")
@documentation = (opts.fetch("documentation", "") || "")
@name = opts.fetch("name")
@provider = opts.fetch("provider")
@description = opts.fetch("description")
@documentation = opts.fetch("documentation")
end
def valid?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment