Class: Ballot::Generators::Standalone
- Inherits:
-
Object
- Object
- Ballot::Generators::Standalone
- Defined in:
- lib/generators/ballot/standalone.rb
Overview
The Ballot standalone generator.
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
The arguments provided to the Standalone generator.
Class Method Summary collapse
-
.run(argv) ⇒ Object
Create and run the standalone generator with the command-line arguments.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Standalone
constructor
Create the standalone generator.
-
#run ⇒ Object
Run the standalone generator.
Constructor Details
#initialize(argv) ⇒ Standalone
Create the standalone generator.
21 22 23 |
# File 'lib/generators/ballot/standalone.rb', line 21 def initialize(argv) @argv = argv end |
Instance Attribute Details
#argv ⇒ Object (readonly)
The arguments provided to the Standalone generator.
18 19 20 |
# File 'lib/generators/ballot/standalone.rb', line 18 def argv @argv end |
Class Method Details
.run(argv) ⇒ Object
Create and run the standalone generator with the command-line arguments.
13 14 15 |
# File 'lib/generators/ballot/standalone.rb', line 13 def self.run(argv) new(argv).run end |
Instance Method Details
#run ⇒ Object
Run the standalone generator.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/generators/ballot/standalone.rb', line 26 def run op = OptionParser.new { |opts| opts. = 'Usage: ballot_generator [options]' opts.on('--orm ORM', %w(active_record sequel), 'Select the ORM') do |orm| @orm = orm.to_sym end opts.on( '--install', '-I', Ballot::Generators::InstallGenerator.desc ) do if generator && !generator.kind_of?(Ballot::Generators::InstallGenerator) warn 'Can only select one generator to run.' $stderr.puts opts return 1 else self.generator = Ballot::Generators::InstallGenerator.new end end opts.on( '--summary NAME', '-S', Ballot::Generators::SummaryGenerator.desc ) do |name| if generator && !generator.kind_of?(Ballot::Generators::SummaryGenerator) warn 'Can only select one generator to run.' $stderr.puts opts return 1 else self.generator = Ballot::Generators::SummaryGenerator.new(name) end end opts.on('-h', '--help', 'Prints this help') do $stdout.puts opts return 1 end } op.parse!(argv) if generator generator.class.orm = @orm if @orm generator.create_migration_file else $stdout.puts op end 0 rescue => ex $stderr.puts ex. return 1 end |