Class: PoolParty::Optioner

Inherits:
Object show all
Includes:
Configurable
Defined in:
lib/poolparty/helpers/optioner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configurable

included

Constructor Details

#initialize(args = [], opts = {}, &block) ⇒ Optioner

Returns a new instance of Optioner.



12
13
14
15
16
17
18
19
# File 'lib/poolparty/helpers/optioner.rb', line 12

def initialize(args=[], opts={}, &block)
  @arguments = args
  @parse_options = opts[:parse_options] ? opts[:parse_options] : true
  
  set_default_options
  parse_options(&block) if @parse_options
  self
end

Instance Attribute Details

#options ⇒ Object (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/poolparty/helpers/optioner.rb', line 10

def options
  @options
end

Instance Method Details

#output_version ⇒ Object



56
57
58
# File 'lib/poolparty/helpers/optioner.rb', line 56

def output_version
  puts version
end

#parse_options(&blk) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/poolparty/helpers/optioner.rb', line 28

def parse_options(&blk)
  opts = OptionParser.new 
  opts.banner = "Usage: pool [command] [options]"

  opts.separator ""
  opts.separator "Options:"
  
  opts.on('-V', '--version', 'Display the version')    { output_version ; exit 0 }
  opts.on('-v', '--verbose', 'Be verbose')    { @options[:verbose] = true }  
  opts.on('-s [file]', '--spec-file [file]', 'Set the spec file')      { |file| self.spec file }
  opts.on('-t', '--test', 'Testing mode')    { self.testing "true" }
              
  blk.call(opts, self) if blk
  
  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end
  
  opts.parse!(@arguments)
  
  process_options      
  output_options if verbose
end

#process_options ⇒ Object



52
53
54
# File 'lib/poolparty/helpers/optioner.rb', line 52

def process_options
  @options[:verbose] = false if @options[:quiet]
end

#set_default_options ⇒ Object



21
22
23
24
25
26
# File 'lib/poolparty/helpers/optioner.rb', line 21

def set_default_options
  @options = {}
  @options[:verbose] = false
  @options[:quiet] = false
  @options[:version] = PoolParty::VERSION::STRING
end