Sha256: ba8c6a7491857cecd7ab95504348d0e6b3db0daffd99f536486bb172a1e4e9d6

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

module R10K
  module Util

    # Utility mixin for classes that need to implement caches
    #
    # @abstract Classes using this mixin need to implement {#managed_directory} and
    #   {#desired_contents}
    module Cacheable

      # Provide a default cachedir location. This is consumed by R10K::Settings
      # for appropriate global default values.
      #
      # @return [String] Path to the default cache directory
      def self.default_cachedir(basename = 'cache')
        if R10K::Util::Platform.windows?
          File.join(ENV['LOCALAPPDATA'], 'r10k', basename)
        else
          File.join(ENV['HOME'] || '/root', '.r10k', basename)
        end
      end

      # Reformat a string into something that can be used as a directory
      #
      # @param string [String] An identifier to create a sanitized dirname for
      # @return [String] A sanitized dirname for the given string
      def sanitized_dirname(string)
        string.gsub(/(\w+:\/\/)(.*)(@)/, '\1').gsub(/[^@\w\.-]/, '-')
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
r10k-5.0.0 lib/r10k/util/cacheable.rb
r10k-4.1.0 lib/r10k/util/cacheable.rb
r10k-4.0.2 lib/r10k/util/cacheable.rb
r10k-4.0.1 lib/r10k/util/cacheable.rb
r10k-4.0.0 lib/r10k/util/cacheable.rb
r10k-4.0.0.pre lib/r10k/util/cacheable.rb
r10k-3.16.0 lib/r10k/util/cacheable.rb
r10k-3.15.4 lib/r10k/util/cacheable.rb
r10k-3.15.3 lib/r10k/util/cacheable.rb
r10k-3.15.2 lib/r10k/util/cacheable.rb
r10k-3.15.1 lib/r10k/util/cacheable.rb
r10k-3.15.0 lib/r10k/util/cacheable.rb
akerl-r10k-3.14.2.1 lib/r10k/util/cacheable.rb
r10k-3.14.2 lib/r10k/util/cacheable.rb
r10k-3.14.1 lib/r10k/util/cacheable.rb
r10k-3.14.0 lib/r10k/util/cacheable.rb