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, 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.


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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bitclust/searcher.rb', line 28

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|
        url = (/:/ =~ loc) ? loc : "file://#{File.expand_path(loc)}"
        @dblocation = URI.parse(url)
      }
      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


81
82
83
# File 'lib/bitclust/searcher.rb', line 81

def parser
  @parser
end

Instance Method Details

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


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

def exec(argv, options = {})
  db = nil
  if @listen_url
    spawn_server db
  else
    search_pattern db, argv
  end
end

#helpObject


101
102
103
# File 'lib/bitclust/searcher.rb', line 101

def help
  @parser.help
end

#parse(argv) ⇒ Object


83
84
85
86
87
88
89
90
# File 'lib/bitclust/searcher.rb', line 83

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