zeiger 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23b194662e74f40eada24a6f9ce7e25efcaa34ac
4
- data.tar.gz: 5bb3af605cfc175cd66423aed69186124cd54f6e
3
+ metadata.gz: 442832a4d75e16a51b1e2027039324b7376468b3
4
+ data.tar.gz: 2604766d571fd65babebd7a45d3c036e80f3c05b
5
5
  SHA512:
6
- metadata.gz: 510a9d31b51b965f131411e08b682f817dd9f2571ba1dba99020696ed360825ba651933d6619d85fedb72fe393f321a496c3b88a4dc868b1a090db82e913da72
7
- data.tar.gz: 3a5f35825f6c516d7609623829fdaa248f989a446d739f37ef93a2ca6bdaa42022bf67d8e3868b9a3cb9405b9d8e4b5bd0dca41a3fdae5764083e436ec4a85d2
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
@@ -2,7 +2,18 @@ module Zeiger
2
2
  INDICES = { }
3
3
 
4
4
  class Index
5
- ROOT_FILES = %w{ .zeiger.yml .git .hg Makefile Rakefile Gemfile build.xml }
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 ROOT_FILES.any? { |f| File.exist?(File.join path, f) }
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| result = index[ngram] || [] }.reduce(&:&) ; end
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 exec_query Regexp.compile(Regexp.escape txt), txt.ngrams(NGRAM_SIZE)
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
@@ -13,7 +13,7 @@ module Zeiger
13
13
  puts "scanning #{index.name} at #{index.dir}"
14
14
  index.rescan
15
15
  end
16
- sleep 10
16
+ sleep 8
17
17
  end
18
18
  rescue Exception => e
19
19
  puts e.message
@@ -1,3 +1,3 @@
1
1
  module Zeiger
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2018-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler