Class: Reap::Application

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

Overview

Application

Application is the commandline interface to Project.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



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

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



59
60
61
62
63
64
# File 'lib/reap/application.rb', line 59

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.



12
13
14
# File 'lib/reap/application.rb', line 12

def manager
  @manager
end

Instance Method Details

#argumentsObject



37
38
39
# File 'lib/reap/application.rb', line 37

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

#argvObject



33
34
35
# File 'lib/reap/application.rb', line 33

def argv
  @argv ||= ARGV.dup
end

#optionsObject



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

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