Class: BitClust::Searcher

Inherits:
Object show all
Includes:
NameUtils
Defined in:
lib/bitclust/searcher.rb

Overview

Body of bin/refe.

Constant Summary

Constants included from NameUtils

NameUtils::CHAR_TO_MARK, NameUtils::CHAR_TO_NAME, NameUtils::CLASS_NAME_RE, NameUtils::CLASS_PATH_RE, NameUtils::CONST_PATH_RE, NameUtils::CONST_RE, NameUtils::GVAR_RE, NameUtils::LIBNAME_RE, NameUtils::MARK_TO_CHAR, NameUtils::MARK_TO_NAME, NameUtils::METHOD_NAME_RE, NameUtils::METHOD_SPEC_RE, NameUtils::MID, NameUtils::NAME_TO_CHAR, NameUtils::NAME_TO_MARK, NameUtils::TYPEMARK_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NameUtils

build_method_id, classid2name, classname2id, classname?, decodeid, decodename_fs, decodename_url, display_typemark, encodeid, encodename_fs, encodename_rdocurl, encodename_url, functionname?, gvarname?, html_filename, libid2name, libname2id, libname?, method_spec?, methodid2classid, methodid2libid, methodid2mname, methodid2specparts, methodid2specstring, methodid2typechar, methodid2typemark, methodid2typename, methodname?, split_method_id, split_method_spec, typechar2mark, typechar2name, typechar?, typemark2char, typemark2name, typemark?, typename2char, typename2mark, typename?

Constructor Details

#initializeSearcher

Returns a new instance of Searcher.



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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/bitclust/searcher.rb', line 29

def initialize
  cmd = File.basename($0, '.*')
  @dblocation = nil
  @name = (/\Abitclust/ =~ cmd ? 'bitclust search' : 'refe')
  @describe_all = false
  @linep = false
  @encoding = nil
  @target_type = nil
  @listen_url = nil
  @foreground = false
  @parser = OptionParser.new {|parser|
    parser.banner = "Usage: #{@name} <pattern>"
    unless cmd == 'bitclust'
      parser.on('-d', '--database=URL', "Database location (default: #{dblocation_name()})") {|loc|
        @dblocation =
          if windows_drive_path?(loc)
            # "G:/Users/foo/.bitclust/db-2.2.0" のような Windows の
            # ドライブレター付きパスは "/:/ =~ loc" が真になってしまい
            # (":" がドライブレターの区切りに含まれるため)、既に URL
            # 形式だと誤認されて file:// を付けずに URI.parse に渡って
            # しまう。drive_path_uri で組み立てる
            drive_path_uri(loc)
          else
            url = (/:/ =~ loc) ? loc : "file://#{File.expand_path(loc)}"
            URI.parse(url)
          end
      }
      parser.on('--server=URL', 'Spawns BitClust database server and listen URL.  Requires --database option with local path.') {|url|
        require 'bitclust/server'   # require here for speed
        @listen_url = url
      }
      parser.on('--foreground', 'Do not become daemon (for debug)') {
        @foreground = true
      }
    end
    parser.on('-a', '--all', 'Prints descriptions for all matched entries.') {
      @describe_all = true
    }
    parser.on('-l', '--line', 'Prints one entry in one line.') {
      @linep = true
    }
    parser.on('-e', '--encoding=ENCODING', 'Select encoding.') {|enc|
      @encoding = enc
    }
    parser.on('--class', 'Search class or module.') {
      @target_type = :class
    }
    parser.on('--version', 'Prints version and quit.') {
      if cmd == 'bitclust'
        puts "BitClust -- Next generation reference manual interface"
        exit 1
      else
        puts "ReFe version 2"
        exit 1
      end
    }
    parser.on('--help', 'Prints this message and quit.') {
      puts parser.help
      exit 0
    }
  }
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



92
93
94
# File 'lib/bitclust/searcher.rb', line 92

def parser
  @parser
end

Instance Method Details

#exec(argv, options = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/bitclust/searcher.rb', line 103

def exec(argv, options = {})
  db = nil
  prefix = options[:prefix]
  if prefix
    if options[:capi]
      db = BitClust::FunctionDatabase.new(prefix)
    else
      db = BitClust::MethodDatabase.new(prefix)
    end
  end
  if @listen_url
    spawn_server db
  else
    search_pattern db, argv
  end
end

#helpObject



120
121
122
# File 'lib/bitclust/searcher.rb', line 120

def help
  @parser.help
end

#parse(argv) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/bitclust/searcher.rb', line 94

def parse(argv)
  @parser.parse! argv
  if @listen_url   # server mode
    server_mode_check argv
  else
    refe_mode_check argv
  end
end