Class: BitClust::Subcommands::AncestorsCommand

Inherits:
BitClust::Subcommand show all
Includes:
CrossRubyUtils
Defined in:
lib/bitclust/subcommands/ancestors_command.rb

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#error, #help, #option_error, #parse, #srcdir_root

Constructor Details

#initializeAncestorsCommand

Returns a new instance of AncestorsCommand.


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
# File 'lib/bitclust/subcommands/ancestors_command.rb', line 13

def initialize
  super
  @prefix = nil
  @requires = []
  @version = RUBY_VERSION
  @all = false
  @verbose = false
  @parser.banner = <<-BANNER
Usage: #{File.basename($0, '.*')} ancestors [-r<lib>] [--ruby=<VER>] --db=PATH <classname>
 #{File.basename($0, '.*')} ancestors [-r<lib>] [--ruby=<VER>] --db=PATH --all
NG Sample:
  $ #{File.basename($0, '.*')} ancestors -rfoo --ruby=1.9.1 --db=./db Foo
  NG : Foo
  + FooModule (The Ruby have this class/module in ancestors of the class)
  - BarModule (The Database have this class/module in ancestors of the class)
Options:
  BANNER
  @parser.on('-d', '--database=PATH', 'Database prefix.') {|path|
    @prefix = path
  }
  @parser.on('-r LIB', 'Requires library LIB') {|lib|
    @requires.push lib
  }
  @parser.on('--ruby=[VER]', "The version of Ruby interpreter"){|ver|
    @version = ver
  }
  @parser.on('-v', '--verbose', 'Show differences'){
    @verbose = true
  }
  @parser.on('--all', 'Check anccestors for all classes'){
    @all = true
  }
end

Instance Method Details

#exec(argv, options) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bitclust/subcommands/ancestors_command.rb', line 47

def exec(argv, options)
  classname = argv[0]
  db = MethodDatabase.new(@prefix)
  ruby = get_ruby(@version)
  if classname && !@all
    check_ancestors(db, ruby, @requires, classname)
  else
    $stderr.puts 'check all...'
    check_all_ancestors(db, ruby, @requires)
  end
end