Sha256: be4b1f8d97f5df1a334c3173f64785682b79f16d444abd3befab67e255d4fcd6

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'pathname'

module Bolt
  class Boltdir
    BOLTDIR_NAME = 'Boltdir'

    attr_reader :path, :config_file, :inventory_file, :modulepath, :hiera_config, :puppetfile, :rerunfile

    def self.default_boltdir
      Boltdir.new(File.join('~', '.puppetlabs', 'bolt'))
    end

    # Search recursively up the directory hierarchy for the Boltdir. Look for a
    # directory called Boltdir or a file called bolt.yaml (for a control repo
    # type Boltdir). Otherwise, repeat the check on each directory up the
    # hierarchy, falling back to the default if we reach the root.
    def self.find_boltdir(dir)
      dir = Pathname.new(dir)
      if (dir + BOLTDIR_NAME).directory?
        new(dir + BOLTDIR_NAME)
      elsif (dir + 'bolt.yaml').file?
        new(dir)
      elsif dir.root?
        default_boltdir
      else
        find_boltdir(dir.parent)
      end
    end

    def initialize(path)
      @path = Pathname.new(path).expand_path
      @config_file = @path + 'bolt.yaml'
      @inventory_file = @path + 'inventory.yaml'
      @modulepath = [(@path + 'modules').to_s, (@path + 'site-modules').to_s, (@path + 'site').to_s]
      @hiera_config = @path + 'hiera.yaml'
      @puppetfile = @path + 'Puppetfile'
      @rerunfile = @path + '.rerun.json'
    end

    def to_s
      @path.to_s
    end

    def eql?(other)
      path == other.path
    end
    alias == eql?
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bolt-1.26.0 lib/bolt/boltdir.rb
bolt-1.25.0 lib/bolt/boltdir.rb
bolt-1.24.0 lib/bolt/boltdir.rb
bolt-1.23.0 lib/bolt/boltdir.rb
bolt-1.22.0 lib/bolt/boltdir.rb
bolt-1.21.0 lib/bolt/boltdir.rb
bolt-1.20.0 lib/bolt/boltdir.rb
bolt-1.19.0 lib/bolt/boltdir.rb
bolt-1.18.0 lib/bolt/boltdir.rb
bolt-1.17.0 lib/bolt/boltdir.rb