Module: RubiGen::Options

### Home Classes Methods

### In Files

- lib/rubigen/options.rb

### Namespace

- MODULE RubiGen::Options::ClassMethods

### Methods

- ::included
- #add_general_options!
- #add_options!
- #banner
- #default_options
- #full_options
- #mandatory_options
- #options
- #parse!
- #usage
- #usage_message

### Files

- History.txt
- License.txt
- Manifest.txt
- Todo.txt
- README.txt
- index.txt
- version-raw.txt
- version.txt

### Class/Module Index

Quicksearch

- RubiGen
- RubiGen::AbstractGemSource
- RubiGen::Base
- RubiGen::Commands
- RubiGen::Commands::Base
- RubiGen::Commands::Create
- RubiGen::Commands::Destroy
- RubiGen::Commands::List
- RubiGen::Commands::RewindBase
- RubiGen::Commands::Update
- RubiGen::GemPathSource
- RubiGen::GeneratedAttribute
- RubiGen::GeneratorError
- RubiGen::GeneratorTestHelper
- RubiGen::Lookup
- RubiGen::Lookup::ClassMethods
- RubiGen::Manifest
- RubiGen::Options
- RubiGen::Options::ClassMethods
- RubiGen::PathFilteredSource
- RubiGen::PathSource
- RubiGen::Scripts
- RubiGen::Scripts::Base
- RubiGen::Scripts::Destroy
- RubiGen::Scripts::Generate
- RubiGen::Scripts::Update
- RubiGen::Source
- RubiGen::Spec
- RubiGen::UsageError
- Rubigen
- Rubigen::CLI
- Dir
- Object

No matching classes.

# RubiGen::Options

### Attributes

options[W]

### Public Class Methods

included(base) click to toggle source

    # File lib/rubigen/options.rb, line 5
    def self.included(base)
      base.extend(ClassMethods)
      class << base
        if respond_to?(:inherited)
          alias_method :inherited_without_options, :inherited
        end
        alias_method :inherited, :inherited_with_options
      end
    end

### Public Instance Methods

options() click to toggle source

Each instance has an options hash that's populated by parse.

    # File lib/rubigen/options.rb, line 48
    def options
      @options ||= {}
    end

### Protected Instance Methods

add_general_options!(opt) click to toggle source

Adds general options like -h and --quiet. Usually don't override.

    # File lib/rubigen/options.rb, line 118
    def add_general_options!(opt)
      opt.separator 'General Options:'

      opt.on('-h', '--help', 'Show this help message and quit.') { |v| options[:help] = v }
      opt.on('-p', '--pretend', 'Run but do not make any changes.') { |v| options[:pretend] = v }
      opt.on('-f', '--force', 'Overwrite files that already exist.') { options[:collision] = :force }
      opt.on('-s', '--skip', 'Skip files that already exist.') { options[:collision] = :skip }
      opt.on('-q', '--quiet', 'Suppress normal output.') { |v| options[:quiet] = v }
      opt.on('-t', '--backtrace', 'Debugging: show backtrace on errors.') { |v| options[:backtrace] = v }
      opt.on('-c', '--svn', 'Modify files with subversion. (Note: svn must be in path)') do
        options[:svn] = `svn status`.inject({}) do |opt, e|
          opt[e.chomp[7..-1]] = true
          opt
        end
      end
      opt.on('-g', '--git', 'Modify files with git. (Note: git must be in path)') do
        options[:git] = `git status`.inject({:new => {}, :modified => {}}) do |opt, e|
          opt[:new][e.chomp[14..-1]] = true if e =~ /new file:/
          opt[:modified][e.chomp[14..-1]] = true if e =~ /modified:/
          opt
        end
      end
    end

add_options!(opt) click to toggle source

Override to add your options to the parser:

    def add_options!(opt)
      opt.on('-v', '--verbose') { |value| options[:verbose] = value }
    end

    # File lib/rubigen/options.rb, line 114
    def add_options!(opt)
    end

banner() click to toggle source

Override with your own usage banner.

    # File lib/rubigen/options.rb, line 106
    def banner
      "Usage: #{$0} [options]"
    end

default_options() click to toggle source

Convenient access to class default options.

    # File lib/rubigen/options.rb, line 60
    def default_options
      self.class.default_options
    end

full_options(runtime_options = {}) click to toggle source

Merge together our instance options. In increasing precedence:

    default_options   (class default options)
    options           (instance options)
    runtime_options   (provided as argument)
    mandatory_options (class mandatory options)

    # File lib/rubigen/options.rb, line 69
    def full_options(runtime_options = {})
      self.class.full_options(options.merge(runtime_options))
    end

mandatory_options() click to toggle source

Convenient access to class mandatory options.

    # File lib/rubigen/options.rb, line 55
    def mandatory_options
      self.class.mandatory_options
    end

parse!(args, runtime_options = {}) click to toggle source

Parse arguments into the options hash. Classes may customize parsing behavior by overriding these methods:

    #banner                 Usage: ./script/generate [options]
    #add_options!           Options:
                              some options..
    #add_general_options!   General Options:
                              general options..

    # File lib/rubigen/options.rb, line 80
    def parse!(args, runtime_options = {})
      self.options = {}

      @option_parser = OptionParser.new do |opt|
        opt.banner = banner
        add_options!(opt)
        add_general_options!(opt)
        opt.parse!(args)
      end

      return args
    ensure
      self.options = full_options(runtime_options)
    end

usage(message = usage_message) click to toggle source

Raise a usage error. Override usage_message to provide a blurb after the option parser summary.

    # File lib/rubigen/options.rb, line 97
    def usage(message = usage_message)
      raise UsageError, "#{@option_parser}\n#{message}"
    end

usage_message() click to toggle source

    # File lib/rubigen/options.rb, line 101
    def usage_message
      ''
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.