Sha256: 3440d96efafbf8b2bc2139f8bc1a3fc787b8cb522c8a53964f8845c77f03db78

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

# This generator creates a new 'scenario'
class ScenarioGenerator < Rails::Generator::Base

  attr_accessor :name_of_scenario_to_create, :name_of_scenario_file_to_create

  # `./script/generate scenario foo` will result in:
  #
  #   runtime_args: ['foo']
  #   runtime_options: {:quiet=>false, :generator=>"scenario", :command=>:create, :collision=>:ask}
  #
  def initialize(runtime_args, runtime_options = {})
    setup_rails_to_run_scenarios
    @name_of_scenario_to_create      = runtime_args.join(' ')
    @name_of_scenario_file_to_create = runtime_args.join('_').downcase
    super
  end

  # this should be done by ./script/generate blackbox
  def setup_rails_to_run_scenarios
    rakefile = File.join RAILS_ROOT, 'Rakefile'
    if File.file? rakefile
      source = File.read rakefile
      unless source =~ /require .scenarios.tasks./
        File.open( rakefile, 'a' ) do |f|
          f << %[require 'scenarios/tasks']
        end
      end
    end
  end

  def manifest
    record do |m|
      m.directory 'scenarios'
      m.template 'scenario.erb', "scenarios/#{ name_of_scenario_file_to_create }.rb"
    end
  end
 
protected
 
  def banner
    "Usage: #{$0} _scenario Name of Scenario to Create"
  end
 
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
openrain-scenarios-0.1.2 rails_generators/scenario/scenario_generator.rb
openrain-scenarios-0.2.1 rails_generators/scenario/scenario_generator.rb
openrain-scenarios-0.2.2 rails_generators/scenario/scenario_generator.rb
openrain-scenarios-0.3.2 rails_generators/scenario/scenario_generator.rb
remi-scenarios-0.1.2 rails_generators/scenario/scenario_generator.rb
eol_scenarios-0.3.4 rails_generators/scenario/scenario_generator.rb
eol_scenarios-0.3.3 rails_generators/scenario/scenario_generator.rb