Class: RakefileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/serverspec_launcher/generators/rakefile_generator.rb

Overview

Generates the rakefile that will bring in the serverspec tasks

Instance Method Summary collapse

Constructor Details

#initialize(root_path = nil) ⇒ RakefileGenerator

Returns a new instance of RakefileGenerator.



6
7
8
9
10
# File 'lib/serverspec_launcher/generators/rakefile_generator.rb', line 6

def initialize(root_path = nil)
  path = root_path ? "#{root_path}/" : ''
  @template_path = File.expand_path('../../../../templates', __FILE__)
  @rakefile = "#{path}Rakefile"
end

Instance Method Details

#generateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/serverspec_launcher/generators/rakefile_generator.rb', line 16

def generate
  if File.exist? @rakefile
    str = File.read(@rakefile)
    new_str = if str.include? "require 'serverspec_launcher/rake_tasks'"
                str
              else
                str.sub(/((require .*\n)+)/, "\\1require 'serverspec_launcher/rake_tasks'\n")
              end
    File.open(@rakefile, 'w') { |file| file.write new_str }
  else
    renderer = ERB.new rakefile_template
    File.open(@rakefile, 'w') { |file| file.write renderer.result }
  end

end

#rakefile_templateObject



12
13
14
# File 'lib/serverspec_launcher/generators/rakefile_generator.rb', line 12

def rakefile_template
  File.read "#{@template_path}/Rakefile.erb"
end