zeiger 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/zeiger +1 -0
- data/lib/zeiger/index.rb +21 -4
- data/lib/zeiger/server.rb +1 -1
- data/lib/zeiger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 442832a4d75e16a51b1e2027039324b7376468b3
|
4
|
+
data.tar.gz: 2604766d571fd65babebd7a45d3c036e80f3c05b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53fac91ddc9b472842068ab533271d9ec89cfa66a32dd358f8b39185d4e79e001a63f7c089815bd5ec52d4c99187fec99e5d8a696a0c983b5d9474ccc84844b
|
7
|
+
data.tar.gz: e7574635be1aa14bb86a7a2a5b346fccca3599905eb39b61a8b2691127df67a78f1ef418217ed441f97ceac3af996e857b555e3ffd202cf4c2bdf56b38178c98
|
data/bin/zeiger
CHANGED
@@ -12,6 +12,7 @@ when "server" ; Zeiger::Server.new.run *$*
|
|
12
12
|
when "search" ; Zeiger::Client.new.send({ command: :search, pwd: pwd, search: query })
|
13
13
|
when "files" ; Zeiger::Client.new.send({ command: :files , pwd: pwd, files: query })
|
14
14
|
when "stats" ; Zeiger::Client.new.send({ command: :stats , pwd: pwd })
|
15
|
+
else puts "Zeiger version #{Zeiger::VERSION}, usage `zeiger server|search|files|stats`"
|
15
16
|
end
|
16
17
|
|
17
18
|
# define file groups
|
data/lib/zeiger/index.rb
CHANGED
@@ -2,7 +2,18 @@ module Zeiger
|
|
2
2
|
INDICES = { }
|
3
3
|
|
4
4
|
class Index
|
5
|
-
|
5
|
+
ROOT_GLOBS = [%w{ *.gemspec }]
|
6
|
+
ROOT_GROUPS = [%w{ .zeiger.yml },
|
7
|
+
%w{ .git },
|
8
|
+
%w{ .hg },
|
9
|
+
%w{ Makefile },
|
10
|
+
%w{ Rakefile },
|
11
|
+
%w{ Gemfile },
|
12
|
+
%w{ build.xml },
|
13
|
+
%w{ lib LICENSE },
|
14
|
+
%w{ lib spec },
|
15
|
+
%w{ lib MIT-LICENSE },
|
16
|
+
]
|
6
17
|
NGRAM_SIZE = 3
|
7
18
|
|
8
19
|
attr_accessor :index, :dir, :name, :includes, :ignore, :files, :config, :monitor, :stats
|
@@ -33,7 +44,8 @@ module Zeiger
|
|
33
44
|
raise "no path! #{path.inspect}" if path == nil || path.strip == ''
|
34
45
|
return INDICES[path] if INDICES[path]
|
35
46
|
return nil if path == '/'
|
36
|
-
return (INDICES[path] = new(path)) if
|
47
|
+
return (INDICES[path] = new(path)) if ROOT_GROUPS.any? { |rg| rg.all? { |f| File.exist?(File.join path, f) } }
|
48
|
+
return (INDICES[path] = new(path)) if ROOT_GLOBS.any? { |rg| rg.all? { |f| Dir.glob(File.join path, f).size > 0 } }
|
37
49
|
return from_path(File.dirname path)
|
38
50
|
end
|
39
51
|
|
@@ -62,13 +74,18 @@ module Zeiger
|
|
62
74
|
|
63
75
|
def glob pattern ; Dir.glob(File.join(dir, pattern)) ; end
|
64
76
|
def rescan ; monitor.build_index ; end
|
65
|
-
def get_ngram_lines ngrams ; ngrams.map { |ngram|
|
77
|
+
def get_ngram_lines ngrams ; ngrams.map { |ngram| index[ngram] || [] }.reduce(&:&) ; end
|
66
78
|
def exec_query regex, ngrams ; get_ngram_lines(ngrams).select { |line| line.matches? regex } ; end
|
67
79
|
def sort_by_filename lines ; lines.sort_by { |line| [line.file.local_filename, line.line_number] } ; end
|
80
|
+
def all_matching q ; index.keys.select { |k| k.match q }.map { |k| index[k] }.reduce(&:|) ; end
|
68
81
|
|
69
82
|
def query txt
|
70
83
|
puts "got query #{txt.inspect}"
|
71
|
-
sort_by_filename
|
84
|
+
sort_by_filename(if txt.length <= NGRAM_SIZE
|
85
|
+
all_matching Regexp.compile(Regexp.escape txt)
|
86
|
+
else
|
87
|
+
exec_query Regexp.compile(Regexp.escape txt), txt.ngrams(NGRAM_SIZE)
|
88
|
+
end)
|
72
89
|
end
|
73
90
|
|
74
91
|
def file_list name
|
data/lib/zeiger/server.rb
CHANGED
data/lib/zeiger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zeiger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- conanite
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|