lib/inspec/profile.rb in inspec-1.6.0 vs lib/inspec/profile.rb in inspec-1.7.0

- old
+ new

@@ -19,14 +19,13 @@ module Inspec class Profile # rubocop:disable Metrics/ClassLength extend Forwardable - def self.resolve_target(target, cache = nil) - c = cache || Cache.new - Inspec::Log.debug "Resolve #{target} into cache #{c.path}" - Inspec::CachedFetcher.new(target, cache || Cache.new) + def self.resolve_target(target, cache) + Inspec::Log.debug "Resolve #{target} into cache #{cache.path}" + Inspec::CachedFetcher.new(target, cache) end # Check if the profile contains a vendored cache, move content into global cache # TODO: use relative file provider # TODO: use source reader for Cache as well @@ -63,15 +62,17 @@ end new(reader, opts) end def self.for_fetcher(fetcher, opts) + opts[:cache] = opts[:cache] || Cache.new path, writable = fetcher.fetch for_path(path, opts.merge(target: fetcher.target, writable: writable)) end def self.for_target(target, opts = {}) + opts[:cache] = opts[:cache] || Cache.new fetcher = resolve_target(target, opts[:cache]) for_fetcher(fetcher, opts) end attr_reader :source_reader, :backend, :runner_context @@ -203,11 +204,11 @@ # add information about the required attributes res[:attributes] = res[:attributes].map(&:to_hash) unless res[:attributes].nil? || res[:attributes].empty? res end - # Check if the profile is internall well-structured. The logger will be + # Check if the profile is internally well-structured. The logger will be # used to print information on errors and warnings which are found. # # @return [Boolean] true if no errors were found, false otherwise def check # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength # initial values for response object @@ -340,11 +341,11 @@ def locked_dependencies @locked_dependencies ||= load_dependencies end def lockfile_exists? - File.exist?(lockfile_path) + @source_reader.target.files.include?('inspec.lock') end def lockfile_path File.join(cwd, 'inspec.lock') end @@ -358,10 +359,10 @@ @target.is_a?(String) && File.directory?(@target) ? @target : './' end def lockfile @lockfile ||= if lockfile_exists? - Inspec::Lockfile.from_file(lockfile_path) + Inspec::Lockfile.from_content(@source_reader.target.read('inspec.lock')) else generate_lockfile end end