Class: CucumberOffRails::Generator
- Inherits:
-
Object
- Object
- CucumberOffRails::Generator
- Defined in:
- lib/cucumber_off_rails/generator.rb,
lib/cucumber_off_rails/generator/application.rb
Defined Under Namespace
Classes: Application
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#remote_site ⇒ Object
Returns the value of attribute remote_site.
-
#target_dir ⇒ Object
Returns the value of attribute target_dir.
Instance Method Summary collapse
- #create_files ⇒ Object
-
#initialize(options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #mkdir_in_target(directory) ⇒ Object
- #output_template_in_target(source, destination = source) ⇒ Object
- #render_template(source) ⇒ Object
- #run ⇒ Object
- #template_dir ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
12 13 14 15 16 17 |
# File 'lib/cucumber_off_rails/generator.rb', line 12 def initialize( = {}) self. = self.remote_site = [:remote_site] || "http://www.google.com" self.project_name = [:project_name] self.target_dir = [:directory] || self.project_name || "cucumber_off_rails_project" end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/cucumber_off_rails/generator.rb', line 10 def @options end |
#project_name ⇒ Object
Returns the value of attribute project_name.
10 11 12 |
# File 'lib/cucumber_off_rails/generator.rb', line 10 def project_name @project_name end |
#remote_site ⇒ Object
Returns the value of attribute remote_site.
10 11 12 |
# File 'lib/cucumber_off_rails/generator.rb', line 10 def remote_site @remote_site end |
#target_dir ⇒ Object
Returns the value of attribute target_dir.
10 11 12 |
# File 'lib/cucumber_off_rails/generator.rb', line 10 def target_dir @target_dir end |
Instance Method Details
#create_files ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cucumber_off_rails/generator.rb', line 23 def create_files unless File.exists?(target_dir) || File.directory?(target_dir) FileUtils.mkdir target_dir else raise "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?" end output_template_in_target "Gemfile" output_template_in_target "Rakefile" mkdir_in_target "features" output_template_in_target File.join("features", "sample.feature") mkdir_in_target "features/step_definitions" output_template_in_target File.join("features", "step_definitions", "debugging_steps.rb") output_template_in_target File.join("features", "step_definitions", "linking_steps.rb") output_template_in_target File.join("features", "step_definitions", "login_steps.rb") output_template_in_target File.join("features", "step_definitions", "selector_steps.rb") output_template_in_target File.join("features", "step_definitions", "validation_steps.rb") mkdir_in_target "features/support" output_template_in_target File.join("features", "support", "env.rb") output_template_in_target File.join("features", "support", "hooks.rb") output_template_in_target File.join("features", "support", "paths.rb") output_template_in_target File.join("features", "support", "selectors.rb") end |
#mkdir_in_target(directory) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/cucumber_off_rails/generator.rb', line 69 def mkdir_in_target(directory) final_destination = File.join(target_dir, directory) FileUtils.mkdir final_destination $stdout.puts "\tcreate\t#{directory}" end |
#output_template_in_target(source, destination = source) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/cucumber_off_rails/generator.rb', line 48 def output_template_in_target(source, destination = source) final_destination = File.join(target_dir, destination) template_result = render_template(source) File.open(final_destination, 'w') {|file| file.write(template_result)} $stdout.puts "\tcreate\t#{destination}" end |
#render_template(source) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/cucumber_off_rails/generator.rb', line 57 def render_template(source) template_contents = File.read(File.join(template_dir, source)) template = ERB.new(template_contents, nil, '<>') # squish extraneous whitespace from some of the conditionals template.result(binding).gsub(/\n\n\n+/, "\n\n") end |
#run ⇒ Object
19 20 21 |
# File 'lib/cucumber_off_rails/generator.rb', line 19 def run create_files end |
#template_dir ⇒ Object
65 66 67 |
# File 'lib/cucumber_off_rails/generator.rb', line 65 def template_dir File.join(File.dirname(__FILE__), 'templates') end |