zeiger 0.0.1 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.zeiger.yml +28 -7
- data/README.md +26 -15
- data/bin/zeiger +7 -5
- data/lib/zeiger.rb +5 -8
- data/lib/zeiger/{file_list_client.rb → client.rb} +6 -3
- data/lib/zeiger/file_info.rb +16 -4
- data/lib/zeiger/index.rb +76 -10
- data/lib/zeiger/line.rb +5 -3
- data/lib/zeiger/monitor.rb +11 -7
- data/lib/zeiger/server.rb +36 -19
- data/lib/zeiger/stats.rb +33 -0
- data/lib/zeiger/version.rb +1 -1
- data/zeiger.gemspec +1 -1
- metadata +9 -9
- data/lib/zeiger/query_client.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68b9dfc1fb8332bcba98e6add4af92cdde895c7d
|
4
|
+
data.tar.gz: 32df5d5004fc6fe5fe448c5b478d7b72d18feb1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6af416b2b517cf755fdd7304f7fc099b4a91aa115f95f011e54cbcb2f42bf9f3924ba3787e0a22e2873e54876133b72d9b45745866adf3044277fc1447bb6985
|
7
|
+
data.tar.gz: 6fd40c1ca39823a89c03a9eb36b3ee55463e9f0e2b3a67cbd19d7874171aca84e53c6d11b528cbc3bfc16c16653d04e3ec50f47a64c5c0771f37999b071700d8
|
data/.zeiger.yml
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
search:
|
2
|
-
-
|
3
|
-
-
|
2
|
+
- "app/**/*"
|
3
|
+
- "bin/**/*"
|
4
|
+
- "lib/**/*"
|
4
5
|
ignore:
|
5
|
-
-
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
6
|
+
- "\\.gz$"
|
7
|
+
- "\\.png$"
|
8
|
+
- "\\.gif$"
|
9
|
+
- "\\.zip$"
|
10
|
+
- "\\.jpg$"
|
11
|
+
stats:
|
12
|
+
code:
|
13
|
+
- "bin/.*"
|
14
|
+
- "lib/.*\\.rb$"
|
15
|
+
test:
|
16
|
+
- "spec/.*"
|
17
|
+
- "test/.*"
|
18
|
+
other:
|
19
|
+
- ".*\\.yml$"
|
20
|
+
comments:
|
21
|
+
"\\.yml$":
|
22
|
+
- "^\\s*#"
|
23
|
+
"\\.rb$":
|
24
|
+
- "^\\s*#"
|
25
|
+
"\\.nydp$":
|
26
|
+
- "^\\s*;"
|
27
|
+
"\\.arc$":
|
28
|
+
- "^\\s*;"
|
29
|
+
"\\.c$":
|
30
|
+
- "^\\s*//"
|
data/README.md
CHANGED
@@ -1,42 +1,43 @@
|
|
1
1
|
# Zeiger
|
2
2
|
|
3
|
-
Zeiger is the German word for "pointer", "indicator", "index", "locator". This gem is built in the "index" sense
|
3
|
+
Zeiger is the German word for "pointer", "indicator", "index", "locator". This gem is built in the "index" sense. To install,
|
4
4
|
|
5
5
|
```
|
6
|
-
|
7
|
-
zeiger server
|
6
|
+
gem install zeiger
|
8
7
|
```
|
9
8
|
|
10
|
-
|
9
|
+
In a terminal, run
|
11
10
|
|
12
|
-
|
11
|
+
```
|
12
|
+
zeiger server
|
13
|
+
```
|
14
|
+
|
15
|
+
Zeiger will open a unix-socket under `/tmp` and listen for search and file-list requests. Run this in a terminal:
|
13
16
|
|
14
17
|
```
|
15
18
|
cd myproject
|
16
19
|
zeiger search "muppets"
|
17
20
|
```
|
18
21
|
|
19
|
-
|
22
|
+
(Replace "myproject" with something meaningful!)
|
20
23
|
|
21
|
-
|
24
|
+
Zeiger will index the current directory if it is not already indexed, then search for lines containing "muppets". Output is in the same format as `grep` (so you can hook it up with your emacs for quick project browsing).
|
25
|
+
|
26
|
+
Zeiger will rescan files in the current directory every ten seconds so the index is mostly up-to-date.
|
22
27
|
|
23
|
-
```
|
24
|
-
gem install 'zeiger'
|
25
|
-
```
|
26
28
|
|
27
|
-
This is built as a standalone commandline tool ; I don't have any use-cases for integrating it directly into a larger project. But if you do, I'm all ears.
|
28
29
|
|
29
30
|
## Usage
|
30
31
|
|
31
|
-
`zeiger server` runs the server and opens a unix filesystem socket called
|
32
|
+
`zeiger server` runs the server and opens a unix filesystem socket called `/tmp/zeiger-index`
|
32
33
|
|
33
34
|
`zeiger search "foo"` writes the query to the socket and displays the result
|
34
35
|
|
35
|
-
`zeiger files "xed"` asks for the list of filenames corresponding to the argument ("xed"). With no argument, return all filenames.
|
36
|
+
`zeiger files "xed"` asks for the list of filenames corresponding to the argument ("xed"). With no argument, return all filenames. Files are sorted by length of filename. This sounds odd, but works nicely with 'completing-read in emacs: you will find the file you want in fewer keystrokes.
|
36
37
|
|
37
|
-
By default, Zeiger searches only in these subdirectories :
|
38
|
+
By default, Zeiger searches only in these subdirectories : `%w{ app bin config lib spec test }`, and excludes filenames matching these patterns: `%w{ .gz$ .png$ .jpg$ .pdf$ }`.
|
38
39
|
|
39
|
-
To override, create a file in your
|
40
|
+
To override, create a file called `.zeiger.yml` in your project root with the following format:
|
40
41
|
|
41
42
|
```yaml
|
42
43
|
search:
|
@@ -49,10 +50,20 @@ ignore:
|
|
49
50
|
- .gif$
|
50
51
|
- .zip$
|
51
52
|
- .jpg$
|
53
|
+
- .ico$
|
52
54
|
- .xcf$
|
53
55
|
- .mpg$
|
54
56
|
```
|
55
57
|
|
58
|
+
You should change the contents to suit your indexing needs. The `search` key is a list of regexps, zeiger will index only those files whose name matches at least one of these regexps. The `ignore` key is likewise a list of regexps, zeiger will not index any file whose name matches any of these regexps. The `ignore` rule supercedes the `search` rule.
|
59
|
+
|
60
|
+
When you invoke `zeiger search ...` or `zeiger files ...`, zeiger will consider whether an index already exists for the current directory. If not, and the current directory is a project root, it will create an index for the current directory. If there is no index, and the current directory is not a project root, it moves up one directory and tries again.
|
61
|
+
|
62
|
+
Zeiger considers a project root any directory containing any one of the following: `%w{ .zeiger.yml .git .hg Makefile Rakefile Gemfile build.xml }` (see `ROOT_FILES` constant in `index.rb`)
|
63
|
+
|
64
|
+
## TODO
|
65
|
+
|
66
|
+
Use `Listen` gem instead of manual filesystem scan
|
56
67
|
|
57
68
|
## Contributing
|
58
69
|
|
data/bin/zeiger
CHANGED
@@ -3,14 +3,16 @@
|
|
3
3
|
require 'socket'
|
4
4
|
require 'zeiger'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
pwd = `pwd`.strip
|
8
7
|
command = $*[0]
|
8
|
+
query = $*[1]
|
9
9
|
|
10
10
|
case command
|
11
|
-
when "server" ; Zeiger::Server.run *$*
|
12
|
-
when "search" ; Zeiger::
|
13
|
-
when "files" ; Zeiger::
|
11
|
+
when "server" ; Zeiger::Server.new.run *$*
|
12
|
+
when "search" ; Zeiger::Client.new.send({ command: :search, pwd: pwd, search: query })
|
13
|
+
when "files" ; Zeiger::Client.new.send({ command: :files , pwd: pwd, files: query })
|
14
|
+
when "stats" ; Zeiger::Client.new.send({ command: :stats , pwd: pwd })
|
15
|
+
else puts "Zeiger version #{Zeiger::VERSION}, usage `zeiger server|search|files|stats`"
|
14
16
|
end
|
15
17
|
|
16
18
|
# define file groups
|
data/lib/zeiger.rb
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
require "set"
|
2
2
|
require 'yaml'
|
3
|
-
require 'zeiger/
|
4
|
-
require 'zeiger/file_list_client'
|
3
|
+
require 'zeiger/client'
|
5
4
|
require 'zeiger/server'
|
6
5
|
require "zeiger/version"
|
7
6
|
require 'zeiger/monitor'
|
7
|
+
require 'zeiger/stats'
|
8
8
|
require 'zeiger/file_info'
|
9
9
|
require 'zeiger/index'
|
10
10
|
require 'zeiger/line'
|
11
11
|
|
12
12
|
class String
|
13
13
|
def ngrams size
|
14
|
-
|
15
|
-
txt = self
|
16
|
-
ngrams = Hash.new { |h,k| h[k] = 0 }
|
17
|
-
regex = Regexp.compile("." * size)
|
14
|
+
s = size - 1
|
18
15
|
|
19
16
|
result = []
|
20
17
|
|
21
|
-
(
|
22
|
-
result <<
|
18
|
+
(length - s).times do |i|
|
19
|
+
result << self[i..(i + s)]
|
23
20
|
end
|
24
21
|
|
25
22
|
result
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module Zeiger
|
2
|
-
class
|
3
|
-
def
|
2
|
+
class Client
|
3
|
+
def send data
|
4
4
|
Socket.unix(SOCKET_NAME) { |sock|
|
5
|
-
|
5
|
+
s = YAML.dump(data)
|
6
|
+
sock.write([s.bytesize].pack("I"))
|
7
|
+
sock.write(s)
|
8
|
+
|
6
9
|
while !sock.eof?
|
7
10
|
puts sock.readline
|
8
11
|
end
|
data/lib/zeiger/file_info.rb
CHANGED
@@ -2,14 +2,17 @@ require 'set'
|
|
2
2
|
|
3
3
|
module Zeiger
|
4
4
|
class FileInfo
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :index, :filename, :ngrams, :lines, :stats_group, :comment_regexes, :nc_nb_line_count
|
6
6
|
|
7
|
-
def initialize
|
8
|
-
@
|
7
|
+
def initialize index, filename, stats
|
8
|
+
@index, @filename, @ngrams, @lines = index, filename, Set.new, []
|
9
|
+
@stats_group = stats.stats_group filename
|
10
|
+
@comment_regexes = stats.comment_rules(filename)
|
11
|
+
@nc_nb_line_count = 0
|
9
12
|
end
|
10
13
|
|
11
14
|
def local_filename
|
12
|
-
filename.gsub(/^#{Regexp.escape dir}\//, "")
|
15
|
+
@_local_filename ||= filename.gsub(/^#{Regexp.escape index.dir}\//, "")
|
13
16
|
end
|
14
17
|
|
15
18
|
def match regex
|
@@ -19,5 +22,14 @@ module Zeiger
|
|
19
22
|
def add_ngram ngram
|
20
23
|
@ngrams << ngram
|
21
24
|
end
|
25
|
+
|
26
|
+
def add_line line
|
27
|
+
lines << line
|
28
|
+
@nc_nb_line_count += 1 unless line.blank? || (comment_regexes.any? { |regex| line.matches? regex })
|
29
|
+
end
|
30
|
+
|
31
|
+
def summary
|
32
|
+
"[#{index.name}] #{stats_group}\t#{nc_nb_line_count}/#{lines.count}\t: #{local_filename}"
|
33
|
+
end
|
22
34
|
end
|
23
35
|
end
|
data/lib/zeiger/index.rb
CHANGED
@@ -1,14 +1,53 @@
|
|
1
1
|
module Zeiger
|
2
|
+
INDICES = { }
|
3
|
+
|
2
4
|
class Index
|
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
|
+
%w{ lib README.md },
|
17
|
+
]
|
3
18
|
NGRAM_SIZE = 3
|
4
19
|
|
5
|
-
attr_accessor :index, :dir, :includes, :ignore, :files
|
20
|
+
attr_accessor :index, :dir, :name, :includes, :ignore, :files, :config, :monitor, :stats
|
6
21
|
|
7
22
|
def initialize dir
|
8
23
|
attrs = File.exist?(".zeiger.yml") ? YAML.load(File.read ".zeiger.yml") : { }
|
9
24
|
self.dir = File.expand_path dir
|
25
|
+
self.name = File.basename self.dir
|
26
|
+
self.config = load_config
|
10
27
|
self.index = Hash.new { |h, k| h[k] = [] }
|
11
28
|
self.files = Hash.new
|
29
|
+
self.monitor = Monitor.new dir, self, config
|
30
|
+
self.stats = Stats.new self, config
|
31
|
+
rescan
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_config
|
35
|
+
conf_file = File.join dir, ".zeiger.yml"
|
36
|
+
if File.exist?(conf_file)
|
37
|
+
puts "reading config from #{conf_file.inspect}"
|
38
|
+
YAML.load(File.read conf_file)
|
39
|
+
else
|
40
|
+
{ }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.from_path path
|
45
|
+
raise "no path! #{path.inspect}" if path == nil || path.strip == ''
|
46
|
+
return INDICES[path] if INDICES[path]
|
47
|
+
return nil if path == '/'
|
48
|
+
return (INDICES[path] = new(path)) if ROOT_GROUPS.any? { |rg| rg.all? { |f| File.exist?(File.join path, f) } }
|
49
|
+
return (INDICES[path] = new(path)) if ROOT_GLOBS.any? { |rg| rg.all? { |f| Dir.glob(File.join path, f).size > 0 } }
|
50
|
+
return from_path(File.dirname path)
|
12
51
|
end
|
13
52
|
|
14
53
|
def remove_from_index file
|
@@ -22,29 +61,56 @@ module Zeiger
|
|
22
61
|
end
|
23
62
|
|
24
63
|
def add_to_index file
|
25
|
-
info = files[file] = FileInfo.new(
|
64
|
+
info = files[file] = FileInfo.new(self, file, stats)
|
26
65
|
|
27
66
|
File.read(file).split(/\n/).each_with_index { |txt, line|
|
28
|
-
Line.new(info, line + 1, txt).ngrams(NGRAM_SIZE) do |trig, line|
|
67
|
+
line = Line.new(info, line + 1, txt).ngrams(NGRAM_SIZE) do |trig, line|
|
29
68
|
index[trig] << line
|
30
69
|
info.add_ngram trig
|
31
70
|
end
|
32
71
|
}
|
33
|
-
end
|
34
72
|
|
35
|
-
|
36
|
-
|
73
|
+
puts "#{info.summary} : re-index"
|
74
|
+
rescue Exception => e
|
75
|
+
puts "Not able to read #{file}"
|
76
|
+
while e
|
77
|
+
puts e.message
|
78
|
+
puts e.backtrace.join("\n")
|
79
|
+
puts
|
80
|
+
e = e.cause
|
81
|
+
end
|
37
82
|
end
|
38
83
|
|
84
|
+
def glob pattern ; Dir.glob(File.join(dir, pattern)) ; end
|
85
|
+
def rescan ; monitor.build_index ; end
|
86
|
+
def get_ngram_lines ngrams ; ngrams.map { |ngram| index[ngram] || [] }.reduce(&:&) ; end
|
87
|
+
def exec_query regex, ngrams ; get_ngram_lines(ngrams).select { |line| line.matches? regex } ; end
|
88
|
+
def sort_by_filename lines ; lines.sort_by { |line| [line.file.local_filename, line.line_number] } ; end
|
89
|
+
def all_matching q ; index.keys.select { |k| k.match q }.map { |k| index[k] }.reduce(&:|) ; end
|
90
|
+
|
39
91
|
def query txt
|
40
92
|
puts "got query #{txt.inspect}"
|
41
|
-
|
93
|
+
|
94
|
+
lines = if (txt.strip.to_s == '')
|
95
|
+
puts "empty query, not searching!"
|
96
|
+
return []
|
97
|
+
elsif txt.length <= NGRAM_SIZE
|
98
|
+
all_matching Regexp.compile(Regexp.escape txt)
|
99
|
+
else
|
100
|
+
exec_query Regexp.compile(Regexp.escape txt), txt.ngrams(NGRAM_SIZE)
|
101
|
+
end
|
102
|
+
|
103
|
+
sort_by_filename(lines)
|
42
104
|
end
|
43
105
|
|
44
106
|
def file_list name
|
45
|
-
|
46
|
-
|
47
|
-
|
107
|
+
if name
|
108
|
+
r = Regexp.compile name
|
109
|
+
puts "file names matching #{r.inspect}"
|
110
|
+
files.values.select { |f| f.match r }
|
111
|
+
else
|
112
|
+
files.values
|
113
|
+
end.sort_by { |f| f.local_filename.length }
|
48
114
|
end
|
49
115
|
end
|
50
116
|
end
|
data/lib/zeiger/line.rb
CHANGED
@@ -6,12 +6,14 @@ module Zeiger
|
|
6
6
|
def initialize file, line_number, content
|
7
7
|
@file, @line_number, @content = file, line_number, content
|
8
8
|
@hash = "#{file.filename}##{line_number}".hash
|
9
|
+
file.add_line self
|
9
10
|
end
|
10
11
|
|
11
12
|
def to_s ; "#{file.local_filename}:#{line_number}:#{content}" ; end
|
12
|
-
def
|
13
|
+
def blank? ; content.strip == '' ; end
|
14
|
+
def matches? regex ; content.match regex ; end
|
13
15
|
def ngram_list size ; @ngrams ||= content.ngrams(size) ; end
|
14
|
-
def ngrams
|
15
|
-
def ==
|
16
|
+
def ngrams size ; ngram_list(size).each { |ngram| yield ngram, self } ; end
|
17
|
+
def == other ; self.file == other.file && self.line_number == other.line_number ; end
|
16
18
|
end
|
17
19
|
end
|
data/lib/zeiger/monitor.rb
CHANGED
@@ -2,11 +2,10 @@ module Zeiger
|
|
2
2
|
class Monitor
|
3
3
|
attr_accessor :dir, :index, :stat, :includes, :ignore
|
4
4
|
|
5
|
-
def initialize dir, index
|
5
|
+
def initialize dir, index, attrs
|
6
6
|
@dir, @index, @stat = dir, index, Hash.new
|
7
|
-
|
8
|
-
@
|
9
|
-
@ignore = attrs["ignore"] || %w{ .gz$ .png$ .jpg$ .pdf$ }
|
7
|
+
@includes = attrs["search"] || %w{ app/**/* bin/**/* config/**/* lib/**/* spec/**/* test/**/* }
|
8
|
+
@ignore = attrs["ignore"] || %w{ .gz$ .png$ .jpg$ .pdf$ .ico$ }
|
10
9
|
end
|
11
10
|
|
12
11
|
def ignore? filename
|
@@ -21,12 +20,11 @@ module Zeiger
|
|
21
20
|
started = Time.now
|
22
21
|
files = Set.new
|
23
22
|
includes.each do |inc|
|
24
|
-
|
23
|
+
index.glob(inc).sort.each do |file|
|
25
24
|
if File.file?(file) && !ignore?(file)
|
26
25
|
files << file
|
27
26
|
mtime = File.stat(file).mtime
|
28
27
|
if !uptodate?(file, mtime)
|
29
|
-
puts "re-indexing #{file}"
|
30
28
|
index.remove_from_index file
|
31
29
|
index.add_to_index file
|
32
30
|
stat[file] = mtime
|
@@ -34,7 +32,13 @@ module Zeiger
|
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
37
|
-
(Set.new(stat.keys) - files).each { |f|
|
35
|
+
(Set.new(stat.keys) - files).each { |f|
|
36
|
+
info = index.files[f]
|
37
|
+
index.remove_from_index f
|
38
|
+
stat.delete f
|
39
|
+
help = info ? info.summary : "[#{index.name}] #{f}"
|
40
|
+
puts "#{help} : deleted"
|
41
|
+
}
|
38
42
|
finished = Time.now
|
39
43
|
puts "ngrams : #{index.index.length}"
|
40
44
|
puts "files : #{index.files.length}"
|
data/lib/zeiger/server.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Zeiger
|
2
|
-
|
3
|
-
def self.run command, *args
|
4
|
-
dir = File.expand_path(".")
|
5
|
-
z = Zeiger::Index.new dir
|
4
|
+
SOCKET_NAME = "/tmp/zeiger-index"
|
6
5
|
|
6
|
+
class Server
|
7
|
+
def run command, sleepytime=nil, *args
|
8
|
+
sleepytime = (sleepytime || 10).to_f
|
9
|
+
raise "sleep time must be greater than zero, got #{sleepytime.inspect}" unless sleepytime > 0.0
|
10
|
+
puts "starting server with sleep interval of #{sleepytime} seconds"
|
7
11
|
Thread.new do
|
8
12
|
begin
|
9
|
-
puts "monitor thread"
|
10
|
-
monitor = Zeiger::Monitor.new dir, z
|
11
|
-
puts "created monitor"
|
12
13
|
while true do
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
indices = Zeiger::INDICES.values
|
15
|
+
indices.each do |index|
|
16
|
+
puts "#{Time.now} scanning #{index.name} at #{index.dir}"
|
17
|
+
index.rescan
|
18
|
+
end
|
19
|
+
sleep sleepytime
|
16
20
|
end
|
17
21
|
rescue Exception => e
|
18
22
|
puts e.message
|
@@ -20,18 +24,31 @@ module Zeiger
|
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
23
|
-
puts "query thread..."
|
24
|
-
|
25
27
|
Socket.unix_server_loop(SOCKET_NAME) { |sock, client|
|
26
|
-
puts "query thread: server loop"
|
27
28
|
begin
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
length = sock.read(4).unpack("I")[0]
|
30
|
+
query = sock.read(length)
|
31
|
+
incoming = YAML.load(query)
|
32
|
+
puts incoming.to_yaml
|
33
|
+
|
34
|
+
index = Index.from_path incoming[:pwd]
|
35
|
+
|
36
|
+
if index
|
37
|
+
puts "querying index #{index.name}"
|
38
|
+
|
39
|
+
case incoming[:command]
|
40
|
+
when :search
|
41
|
+
index.query(incoming[:search]).each { |res| sock.puts res.to_s }
|
42
|
+
when :stats
|
43
|
+
sock.puts index.stats.stats.to_yaml
|
44
|
+
when :files
|
45
|
+
index.file_list(incoming[:files]).each { |f| sock.puts f.local_filename }
|
46
|
+
end
|
47
|
+
|
48
|
+
else
|
49
|
+
puts "no index found for path #{incoming[:pwd].inspect}"
|
34
50
|
end
|
51
|
+
|
35
52
|
ensure
|
36
53
|
sock.close
|
37
54
|
end
|
data/lib/zeiger/stats.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Zeiger
|
2
|
+
class Stats
|
3
|
+
attr_accessor :index, :group_cfg, :comment_cfg
|
4
|
+
|
5
|
+
def initialize index, config
|
6
|
+
@index = index
|
7
|
+
@group_cfg = config["stats"]
|
8
|
+
@comment_cfg = compile_comment_cfg config["comments"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def compile_comment_cfg cfg
|
12
|
+
(cfg || { }).each_with_object({ }) do |(file_pattern, regex_list), result|
|
13
|
+
result[Regexp.compile(file_pattern)] = regex_list.map { |r| Regexp.compile r }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def stats_group filename
|
18
|
+
(group_cfg || []).each { |group, regexes| return group if regexes.any? { |r| filename.match r } }
|
19
|
+
"undefined"
|
20
|
+
end
|
21
|
+
|
22
|
+
def comment_rules filename
|
23
|
+
file_type = comment_cfg.keys.detect { |rxp| filename.match rxp }
|
24
|
+
comment_cfg[file_type] || []
|
25
|
+
end
|
26
|
+
|
27
|
+
def stats
|
28
|
+
index.files.values.each_with_object(Hash.new { |h,k| h[k] = 0 }) do |file, results|
|
29
|
+
results[file.stats_group] += file.nc_nb_line_count
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/zeiger/version.rb
CHANGED
data/zeiger.gemspec
CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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.6
|
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: 2021-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,13 +55,13 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- bin/zeiger
|
57
57
|
- lib/zeiger.rb
|
58
|
+
- lib/zeiger/client.rb
|
58
59
|
- lib/zeiger/file_info.rb
|
59
|
-
- lib/zeiger/file_list_client.rb
|
60
60
|
- lib/zeiger/index.rb
|
61
61
|
- lib/zeiger/line.rb
|
62
62
|
- lib/zeiger/monitor.rb
|
63
|
-
- lib/zeiger/query_client.rb
|
64
63
|
- lib/zeiger/server.rb
|
64
|
+
- lib/zeiger/stats.rb
|
65
65
|
- lib/zeiger/version.rb
|
66
66
|
- zeiger.gemspec
|
67
67
|
homepage: https://github.com/conanite/zeiger
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.2.
|
87
|
+
rubygems_version: 2.5.2.3
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Provide text index of files in current directory tree and a unix socket to
|