Sha256: e577d28d80bf8f90ee982a50be6bd01da69ef01a48bae073f2e9f5486584a484

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

# DeployRubygem - deploy a gem using rake
# Containing a class
module DeployRubygem
  # Using Project to deploy and manage Project
  class Project
    attr_reader :project_options, :cookbooks, :compliance_profile

    def initialize(new_project_options)
      @project_options = new_project_options
      @cookbooks = project_options[:cookbooks]&.map do |cookbook_name, cookbook_options|
        new_cookbook_option = cookbook_options.dup
        new_cookbook_option[:project_name] = cookbook_name
        new_cookbook_option[:chefrepo_path] = chefrepo_path
        Cookbook.new(new_cookbook_option)
      end
      @compliance_profile = Inspec.new(project_options[:compliance_profile])
    end

    def project_name
      project_options[__method__]
    end

    def binaries
      project_options[__method__]
    end

    def dependencies
      project_options[__method__]
    end

    def path
      project_options[__method__]
    end

    def git
      project_options[__method__]
    end

    def chefrepo_git
      project_options[__method__]
    end

    def chefrepo_path
      project_options[__method__]
    end

    def deploy_cookbooks
      cookbooks.each(&:deploy)
    end

    def release_cookbooks
      project_options[:cookbooks].each(&:release)
    end

    def change_to_directory(git_path, git_url)
      system("git clone #{git_url}") unless Dir.exist?(chefrepo_path)
      Dir.chdir(git_path)
      git_path
    end

    def change_to_project_folder
      change_to_directory(path, git)
    end

    def change_to_chefrepo
      change_to_directory(chefrepo_path, chefrepo_git)
    end

    def test_compliance
      change_to_chefrepo
      compliance_profile.update
      compliance_profile.apply
    end

    def git_commit
      system('git add .') || return
      system("git commit -m 'Self validated for version #{GVB.version}'") || return
      system('git push') || abort("Cannot push #{project_name} #{GVB.version}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deploy_rubygem-0.60.11 lib/deploy_rubygem/project.rb
deploy_rubygem-0.60.10 lib/deploy_rubygem/project.rb