Class: GemspecGenerator

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

Overview

Generates the rakefile that will bring in the serverspec tasks

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GemspecGenerator

Returns a new instance of GemspecGenerator.



7
8
9
10
11
12
13
14
15
# File 'lib/serverspec_launcher/generators/gemspec_generator.rb', line 7

def initialize(options = {})
  path = options[:root_path] ? "#{options[:root_path]}/" : ''
  @template_path = File.expand_path('../../../../templates', __FILE__)
  @project_name =  Dir.pwd.split('/')[-1]
  @gemspec_file = "#{path}#{@project_name}.gemspec"
  @gem_file = "#{path}Gemfile"
  @name = options[:name] || '<Your Name>'
  @email = options[:email] || '<Your email>'
end

Instance Method Details

#gemfile_templateObject



21
22
23
# File 'lib/serverspec_launcher/generators/gemspec_generator.rb', line 21

def gemfile_template
  File.read "#{@template_path}/Gemfile.erb"
end

#gemspec_templateObject



17
18
19
# File 'lib/serverspec_launcher/generators/gemspec_generator.rb', line 17

def gemspec_template
  File.read "#{@template_path}/gemspec.rb.erb"
end

#generateObject



26
27
28
29
30
31
# File 'lib/serverspec_launcher/generators/gemspec_generator.rb', line 26

def generate
  renderer = ERB.new gemspec_template
  File.open(@gemspec_file, 'w') { |file| file.write renderer.result(binding) } if Dir['*.gemspec'].empty?
  renderer = ERB.new gemfile_template
  File.open(@gem_file, 'w') { |file| file.write renderer.result(binding) } unless File.exists? @gem_file
end