Class: Rpack::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Parser

Returns a new instance of Parser.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
# File 'lib/parser.rb', line 8

def initialize(argv)
   @options = []
   @parser  = nil
   @valid   = true
   @unpack  = false
   @full_options = %w(controller model view helper mailer migration 
                      unit functional integration performance fixture route)
   begin
      OptionParser.new do |opts|
         @parser = opts

         opts.banner = "Usage: rpack <name> [options]"
         opts.on("-a","--all")         { @options = @full_options  }
         opts.on("-c","--controller")  { @options << "controller" }
         opts.on("-m","--model")       { @options << "model"      }
         opts.on("-v","--view")        { @options << "view"       }
         opts.on("-h","--helper")      { @options << "helper"     }      
         opts.on("-l","--mailer")      { @options << "mailer"     }
         opts.on("-g","--migration")   { @options << "migration"  }
         opts.on("-u","--unit")        { @options << "unit"       }
         opts.on("-f","--functional")  { @options << "functional" }
         opts.on("-i","--integration") { @options << "integration"}
         opts.on("-o","--performance") { @options << "performance"}
         opts.on("-x","--fixture")     { @options << "fixture"    }
         opts.on("-r","--route")       { @options << "route"      }

         opts.on("-k","--unpack") do 
            @unpack = true
         end

         opts.on("-t","--inflections FILE") do |file|
            @inflections = File.expand_path(file.strip)
         end

         opts.on("-d","--dir DIR") do |dir|
            @basedir = dir.strip
         end

         opts.on("-p","--package FILE") do |file|
            @package = File.expand_path(file.strip)
         end
      end.parse! argv
      @options = @full_options if @options.size<1
   rescue => e
      puts "Error: #{e}"
      puts @parser
      @valid = false
   end
end

Instance Attribute Details

#basedirObject

Returns the value of attribute basedir.



5
6
7
# File 'lib/parser.rb', line 5

def basedir
  @basedir
end

#full_optionsObject (readonly)

Returns the value of attribute full_options.



6
7
8
# File 'lib/parser.rb', line 6

def full_options
  @full_options
end

#inflectionsObject

Returns the value of attribute inflections.



5
6
7
# File 'lib/parser.rb', line 5

def inflections
  @inflections
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/parser.rb', line 5

def options
  @options
end

#packageObject

Returns the value of attribute package.



5
6
7
# File 'lib/parser.rb', line 5

def package
  @package
end

#parserObject

Returns the value of attribute parser.



5
6
7
# File 'lib/parser.rb', line 5

def parser
  @parser
end

Instance Method Details

#unpack?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/parser.rb', line 62

def unpack?
   @unpack
end

#valid?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/parser.rb', line 58

def valid?
   @valid
end