Class: BitClust::Subcommands::ClassesCommand

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

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#error, #help, #option_error, #srcdir_root

Constructor Details

#initializeClassesCommand

Returns a new instance of ClassesCommand.


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bitclust/subcommands/classes_command.rb', line 11

def initialize
  super
  @rejects = []
  @verbose = false
  @parser.banner = "Usage: #{File.basename($0, '.*')} [-r<lib>] <lib>"
  @parser.on('-r', '--reject=LIB', 'Reject library LIB') {|lib|
    @rejects.concat lib.split(',')
  }
  @parser.on('-v', '--verbose', 'Show all ruby version.') {
    @verbose = true
  }
end

Instance Method Details

#defined_classes(ruby, lib, rejects) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bitclust/subcommands/classes_command.rb', line 34

def defined_classes(ruby, lib, rejects)
  script = <<-SCRIPT
    def class_extent
      result = []
      ObjectSpace.each_object(Module) do |c|
        result.push c
      end
      result
    end

    %w(#{rejects.join(" ")}).each do |lib|
      begin
        require lib
      rescue LoadError
      end
    end
    if "#{lib}" == "_builtin"
      class_extent().each do |c|
        puts c
      end
    else
      before = class_extent()
      begin
        require "#{lib}"
      rescue LoadError
        $stderr.puts "\#{RUBY_VERSION} (\#{RUBY_RELEASE_DATE}): library not exist: #{lib}"
        exit
      end
      after = class_extent()
      (after - before).each do |c|
        puts c
      end
    end
  SCRIPT
  output = `#{ruby} -e '#{script}'`
  output.split
end

#exec(argv, options) ⇒ Object


29
30
31
32
# File 'lib/bitclust/subcommands/classes_command.rb', line 29

def exec(argv, options)
  lib = argv[0]
  print_crossruby_table {|ruby| defined_classes(ruby, lib, @rejects) }
end

#parse(argv) ⇒ Object


24
25
26
27
# File 'lib/bitclust/subcommands/classes_command.rb', line 24

def parse(argv)
  super
  option_error('wrong number of arguments') unless argv.size == 1
end