Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Incorporate suggestions from Adrien Thebo

Co-Authored-By: Adrien Thebo <[email protected]>
  • Loading branch information
reidmv and adrienthebo authored Apr 21, 2020
1 parent 2784df4 commit 9f4d3b0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/r10k/source/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class R10K::Source::Hash < R10K::Source::Base
# @return [Boolean] False if the hash is obviously invalid. A true return
# means _maybe_ it's valid.
def self.valid_environments_hash?(hash)
# TODO: more robust schema valiation
hash.is_a?(Hash)
# TODO: more robust schema valiation
hash.is_a?(Hash)
end

# @param name [String] The identifier for this source.
Expand All @@ -143,6 +143,10 @@ def initialize(name, basedir, options = {})
super(name, basedir, options)
end

# Set the environment hash for the source. The environment hash is what the
# source uses to generate enviroments.
# @param hash [Hash] The hash to sanitize and use as the source's environments.
# Should be formatted for use with R10K::Environment#from_hash.
def set_environments_hash(hash)
@environments_hash = hash.reduce({}) do |memo,(name,opts)|
R10K::Util::SymbolizeKeys.symbolize_keys!(opts)
Expand All @@ -155,8 +159,11 @@ def set_environments_hash(hash)
end
end

# Return the sanitized environments hash for this source. The environments
# hash should contain objects formatted for use with R10K::Environment#from_hash.
# If the hash does not exist it will be built based on @options.
def environments_hash
@environments_hash ||= set_environments_hash(@options.delete(:environments) || {})
@environments_hash ||= set_environments_hash(@options.fetch(:environments, {}))
end

def environments
Expand Down

0 comments on commit 9f4d3b0

Please sign in to comment.