Sha256: 5f85a03c898fc5e343eaa1e2c4b827295390da3bd2b38a39d46c45a48b2423b2

Contents?: true

Size: 990 Bytes

Versions: 14

Compression:

Stored size: 990 Bytes

Contents

# frozen_string_literal: true

# Is this Bolt::Pobs::Module?
module Bolt
  class Module
    MODULE_NAME_REGEX = /\A[a-z][a-z0-9_]*\z/.freeze

    def self.discover(modulepath)
      modulepath.each_with_object({}) do |path, mods|
        next unless File.exist?(path) && File.directory?(path)
        (Dir.entries(path) - %w[. ..])
          .map { |dir| File.join(path, dir) }
          .select { |dir| File.directory?(dir) }
          .each do |dir|
          module_name = File.basename(dir)
          if module_name =~ MODULE_NAME_REGEX
            # Puppet will load some objects from shadowed modules but this won't
            mods[module_name] ||= Bolt::Module.new(module_name, dir)
          end
        end
      end
    end

    attr_reader :name, :path

    def initialize(name, path)
      @name = name
      @path = path
    end

    def plugin_data_file
      File.join(path, 'bolt_plugin.json')
    end

    def plugin?
      File.exist?(plugin_data_file)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bolt-1.49.0 lib/bolt/module.rb
bolt-1.48.0 lib/bolt/module.rb
bolt-1.47.0 lib/bolt/module.rb
bolt-1.45.0 lib/bolt/module.rb
bolt-1.44.0 lib/bolt/module.rb
bolt-1.43.0 lib/bolt/module.rb
bolt-1.42.0 lib/bolt/module.rb
bolt-1.41.0 lib/bolt/module.rb
bolt-1.40.0 lib/bolt/module.rb
bolt-1.39.0 lib/bolt/module.rb
bolt-1.38.0 lib/bolt/module.rb
bolt-1.37.0 lib/bolt/module.rb
bolt-1.36.0 lib/bolt/module.rb
bolt-1.35.0 lib/bolt/module.rb