Class: Berkshelf::InitGenerator

Inherits:
BaseGenerator show all
Defined in:
lib/berkshelf/init_generator.rb

Overview

Author:

Instance Method Summary collapse

Methods inherited from BaseGenerator

source_root

Constructor Details

#initialize(*args) ⇒ InitGenerator

Returns a new instance of InitGenerator.



5
6
7
8
9
10
# File 'lib/berkshelf/init_generator.rb', line 5

def initialize(*args)
  super(*args)
  if @options[:cookbook_name]
    @cookbook_name = @options[:cookbook_name]
  end
end

Instance Method Details

#generateObject

Generate the cookbook



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/berkshelf/init_generator.rb', line 52

def generate
  validate_configuration
  check_option_support

  template "Berksfile.erb", target.join("Berksfile")

  if options[:chefignore]
    copy_file "chefignore", target.join("chefignore")
  end

  unless options[:skip_git]
    template "gitignore.erb", target.join(".gitignore")

    unless File.exists?(target.join(".git"))
      inside target do
        run "git init", capture: true
      end
    end
  end

  if options[:foodcritic] || options[:scmversion]
    template "Thorfile.erb", target.join("Thorfile")
  end

  if options[:scmversion]
    create_file target.join("VERSION"), "0.1.0"
  end

  unless options[:no_bundler]
    template "Gemfile.erb", target.join("Gemfile")
  end

  unless options[:skip_vagrant]
    template "Vagrantfile.erb", target.join("Vagrantfile")
    ::Berkshelf::Cli.new([], berksfile: target.join("Berksfile")).invoke(:install)
  end
end