Class: Reap::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/reap/application.rb

Overview

Application is the commandline interface.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/reap/application.rb', line 12

def initialize
  #vector  = ArgVector.new
  #arguments = vector.arguments
  #options   = vector.options

  opts = {}
  opts['dryrun']  = options.delete('dryrun')
  opts['trace']   = options.delete('trace')
  opts['force']   = options.delete('force')
  opts['verbose'] = options.delete('verbose')
  opts['debug']   = options.delete('debug')
  opts

  @manager = Project.new(opts)

  #@arguments = arguments
  #@options   = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(cmd, *args) ⇒ Object



57
58
59
60
61
62
# File 'lib/reap/application.rb', line 57

def method_missing(cmd, *args)
  opts = options.dup
  opts['arguments'] = arguments unless arguments.empty?
  args << opts
  manager.invoke(cmd, *args)
end

Instance Attribute Details

#managerObject (readonly)

Returns the value of attribute manager.



10
11
12
# File 'lib/reap/application.rb', line 10

def manager
  @manager
end

Instance Method Details

#argumentsObject



35
36
37
# File 'lib/reap/application.rb', line 35

def arguments
  @arguments ||= argv.select{ |e| e !~ /^-/ && e !~ /=/ }
end

#argvObject



31
32
33
# File 'lib/reap/application.rb', line 31

def argv
  @argv ||= ARGV.dup
end

#optionsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/reap/application.rb', line 39

def options
  @options ||= (
    pms = {}
    argv.select{ |e| /[=]/ =~ e }.each do |e|
      k,v = e.split('=')
      k = k.sub(/^[-]{1,2}/,'')
      pms.store(k,v)
    end
    argv.select{ |e| e =~ /^-/ && e !~ /=/ }.each do |k|
      k = k.sub(/^[-]{1,2}/,'')
      pms.store(k,true)
    end
    pms
  )
end