Class: Berkshelf::InitGenerator

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

Constant Summary

Constants inherited from BaseGenerator

BaseGenerator::PATTERNS

Instance Method Summary collapse

Methods included from Mixin::Git

#git

Methods inherited from BaseGenerator

source_root

Constructor Details

#initialize(*args) ⇒ InitGenerator

Returns a new instance of InitGenerator.


9
10
11
12
13
14
# File 'lib/berkshelf/init_generator.rb', line 9

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

Instance Method Details

#generateObject


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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/berkshelf/init_generator.rb', line 63

def generate
  validate_cookbook
  validate_configuration
  check_option_support

  template 'Berksfile.erb', target.join('Berksfile')
  template 'Thorfile.erb', target.join('Thorfile')

  if options[:chefignore]
    copy_file 'chefignore', target.join(Ridley::Chef::Chefignore::FILENAME)
  end

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

    unless File.exists?(target.join('.git'))
      inside target do
        git 'init'
      end
    end
  end

  if options[:chef_minitest]
    empty_directory target.join('files/default/tests/minitest/support')
    template 'default_test.rb.erb', target.join('files/default/tests/minitest/default_test.rb')
    template 'helpers.rb.erb', target.join('files/default/tests/minitest/support/helpers.rb')
  end

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

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

  if defined?(Kitchen::Generator::Init)
    unless options[:skip_test_kitchen]
      Kitchen::Generator::Init.new([], {}, destination_root: target).invoke_all
    end
  end

  unless options[:skip_vagrant]
    template 'Vagrantfile.erb', target.join('Vagrantfile')
  end
end