picky 4.9.0 → 4.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/extensions/object.rb +2 -2
- data/lib/picky/index_indexing.rb +1 -1
- data/lib/picky/loggers/concise.rb +27 -17
- data/lib/picky/loggers/silent.rb +37 -9
- data/lib/picky/loggers/verbose.rb +25 -6
- data/lib/picky/query/qualifier_category_mapper.rb +1 -1
- data/spec/functional/facets_spec.rb +2 -2
- data/spec/lib/extensions/symbol_spec.rb +1 -1
- data/spec/lib/loader_spec.rb +1 -1
- data/spec/lib/loggers/concise_spec.rb +40 -16
- data/spec/lib/loggers/silent_spec.rb +40 -17
- data/spec/lib/loggers/verbose_spec.rb +45 -21
- metadata +4 -4
@@ -7,7 +7,7 @@ class Object
|
|
7
7
|
exclaim "#{Time.now.strftime("%H:%M:%S")}: #{text}"
|
8
8
|
end
|
9
9
|
|
10
|
-
# Just
|
10
|
+
# Just outputs the given text to the logger.
|
11
11
|
#
|
12
12
|
def exclaim text
|
13
13
|
Picky.logger.info text
|
@@ -17,7 +17,7 @@ class Object
|
|
17
17
|
# Puts a text that informs the user of a missing gem.
|
18
18
|
#
|
19
19
|
def warn_gem_missing gem_name, message
|
20
|
-
warn "#{gem_name} gem missing!\nTo use #{message}, you need to:\n 1. Add the following line to Gemfile:\n gem '#{gem_name}'\n or\n require '#{gem_name}'\n for example at the top of your app.rb file.\n 2. Then, run:\n bundle update\n"
|
20
|
+
Picky.logger.warn "#{gem_name} gem missing!\nTo use #{message}, you need to:\n 1. Add the following line to Gemfile:\n gem '#{gem_name}'\n or\n require '#{gem_name}'\n for example at the top of your app.rb file.\n 2. Then, run:\n bundle update\n"
|
21
21
|
end
|
22
22
|
|
23
23
|
# Indents each line by <tt>amount=2</tt> spaces.
|
data/lib/picky/index_indexing.rb
CHANGED
@@ -40,7 +40,7 @@ module Picky
|
|
40
40
|
# user as early as possible.
|
41
41
|
#
|
42
42
|
def check_source_empty
|
43
|
-
warn %Q{\n\033[1mWarning\033[m, source for index "#{name}" is empty: #{source} (responds true to empty?).\n} if source.respond_to?(:empty?) && source.empty?
|
43
|
+
Picky.logger.warn %Q{\n\033[1mWarning\033[m, source for index "#{name}" is empty: #{source} (responds true to empty?).\n} if source.respond_to?(:empty?) && source.empty?
|
44
44
|
end
|
45
45
|
|
46
46
|
# Indexes the categories in parallel.
|
@@ -6,24 +6,8 @@ module Picky
|
|
6
6
|
#
|
7
7
|
class Concise < Silent
|
8
8
|
|
9
|
-
attr_reader :tokenized,
|
10
|
-
:dumped,
|
11
|
-
:loaded
|
12
|
-
|
13
9
|
def initialize *args
|
14
10
|
super *args
|
15
|
-
|
16
|
-
reset
|
17
|
-
end
|
18
|
-
|
19
|
-
def reset
|
20
|
-
@tokenized = false
|
21
|
-
@dumped = false
|
22
|
-
@loaded = false
|
23
|
-
end
|
24
|
-
|
25
|
-
def info text
|
26
|
-
io.write text
|
27
11
|
end
|
28
12
|
|
29
13
|
def tokenize(*)
|
@@ -39,7 +23,33 @@ module Picky
|
|
39
23
|
end
|
40
24
|
|
41
25
|
def progress type = '.'
|
42
|
-
|
26
|
+
write type
|
27
|
+
end
|
28
|
+
|
29
|
+
def adapt_for_logger
|
30
|
+
super
|
31
|
+
def info text
|
32
|
+
output.info text
|
33
|
+
end
|
34
|
+
def warn text
|
35
|
+
output.warn text
|
36
|
+
end
|
37
|
+
def write message
|
38
|
+
output << message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
def adapt_for_io
|
42
|
+
super
|
43
|
+
def info text
|
44
|
+
output.write text
|
45
|
+
end
|
46
|
+
def warn text
|
47
|
+
output.puts text
|
48
|
+
flush
|
49
|
+
end
|
50
|
+
def write message
|
51
|
+
output.write message
|
52
|
+
end
|
43
53
|
end
|
44
54
|
|
45
55
|
end
|
data/lib/picky/loggers/silent.rb
CHANGED
@@ -6,16 +6,50 @@ module Picky
|
|
6
6
|
#
|
7
7
|
class Silent
|
8
8
|
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :output
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
@
|
11
|
+
def initialize output = STDOUT
|
12
|
+
@output = output
|
13
|
+
adapt
|
14
|
+
end
|
15
|
+
|
16
|
+
# Is the output a logger?
|
17
|
+
#
|
18
|
+
def logger_output?
|
19
|
+
output.respond_to?(:fatal) &&
|
20
|
+
output.respond_to?(:error) &&
|
21
|
+
output.respond_to?(:warn) &&
|
22
|
+
output.respond_to?(:info) &&
|
23
|
+
output.respond_to?(:debug)
|
24
|
+
end
|
25
|
+
|
26
|
+
def adapt
|
27
|
+
logger_output? ? adapt_for_logger : adapt_for_io
|
28
|
+
end
|
29
|
+
|
30
|
+
def adapt_for_logger
|
31
|
+
def flush
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def adapt_for_io
|
36
|
+
def flush
|
37
|
+
output.flush
|
38
|
+
end
|
13
39
|
end
|
14
40
|
|
15
41
|
def info(*)
|
16
42
|
|
17
43
|
end
|
18
44
|
|
45
|
+
def warn(*)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def write(*)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
19
53
|
def tokenize(*)
|
20
54
|
|
21
55
|
end
|
@@ -28,12 +62,6 @@ module Picky
|
|
28
62
|
|
29
63
|
end
|
30
64
|
|
31
|
-
# Flush this logger.
|
32
|
-
#
|
33
|
-
def flush
|
34
|
-
io.flush
|
35
|
-
end
|
36
|
-
|
37
65
|
end
|
38
66
|
|
39
67
|
end
|
@@ -22,12 +22,31 @@ module Picky
|
|
22
22
|
timed_exclaim %Q{ "#{category.identifier}": Loading index from cache.}
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
def adapt_for_logger
|
26
|
+
super
|
27
|
+
def timed_exclaim text
|
28
|
+
output.info "#{Time.now.strftime("%H:%M:%S")}: #{text}"
|
29
|
+
end
|
30
|
+
def warn text
|
31
|
+
output.warn text
|
32
|
+
end
|
33
|
+
def write message
|
34
|
+
output << message
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def adapt_for_io
|
38
|
+
super
|
39
|
+
def timed_exclaim text
|
40
|
+
output.puts "#{Time.now.strftime("%H:%M:%S")}: #{text}"
|
41
|
+
flush
|
42
|
+
end
|
43
|
+
def warn text
|
44
|
+
output.puts text
|
45
|
+
flush
|
46
|
+
end
|
47
|
+
def write message
|
48
|
+
output.write message
|
49
|
+
end
|
31
50
|
end
|
32
51
|
|
33
52
|
end
|
@@ -26,7 +26,7 @@ module Picky
|
|
26
26
|
def add category
|
27
27
|
category.qualifiers.each do |qualifier|
|
28
28
|
sym_qualifier = qualifier.intern
|
29
|
-
warn %Q{Warning: Qualifier "#{qualifier}" already mapped to category #{mapping[sym_qualifier].identifier} (ambiguous qualifier mapping).} if mapping.has_key? sym_qualifier
|
29
|
+
Picky.logger.warn %Q{Warning: Qualifier "#{qualifier}" already mapped to category #{mapping[sym_qualifier].identifier} (ambiguous qualifier mapping).} if mapping.has_key? sym_qualifier
|
30
30
|
mapping[sym_qualifier] = category
|
31
31
|
end
|
32
32
|
end
|
@@ -139,7 +139,7 @@ describe 'facets' do
|
|
139
139
|
it 'is fast enough' do
|
140
140
|
performance_of {
|
141
141
|
10.times { finder.facets(:age_category, filter: 'surname:meier name:peter') }
|
142
|
-
}.should < 0.
|
142
|
+
}.should < 0.004
|
143
143
|
end
|
144
144
|
it 'has one filtered facet' do
|
145
145
|
# TODO Fix problems with alternative qualifiers (like :age).
|
@@ -169,7 +169,7 @@ describe 'facets' do
|
|
169
169
|
it 'is fast enough' do
|
170
170
|
performance_of {
|
171
171
|
10.times { finder.facets(:age_category, filter: 'surname:meier name:peter', counts: false) }
|
172
|
-
}.should < 0.
|
172
|
+
}.should < 0.004
|
173
173
|
end
|
174
174
|
it 'has one filtered facet' do
|
175
175
|
# TODO Fix problems with alternative qualifiers (like :age).
|
@@ -13,7 +13,7 @@ describe Symbol do
|
|
13
13
|
performance_of { @token.each_subtoken { |subtoken| } }.should < 0.00065
|
14
14
|
end
|
15
15
|
it 'is fast enough' do
|
16
|
-
performance_of { @token.each_intoken { |intoken| } }.should < 0.
|
16
|
+
performance_of { @token.each_intoken { |intoken| } }.should < 0.035 # THINK Is this too slow?
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/spec/lib/loader_spec.rb
CHANGED
@@ -3,24 +3,48 @@ require 'spec_helper'
|
|
3
3
|
describe Picky::Loggers::Concise do
|
4
4
|
|
5
5
|
let(:io) { StringIO.new }
|
6
|
-
let(:logger) { described_class.new
|
6
|
+
let(:logger) { described_class.new thing }
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
context 'with Logger' do
|
9
|
+
let(:thing) { Logger.new io }
|
10
|
+
describe 'more complicated test case' do
|
11
|
+
it 'is correct' do
|
12
|
+
logger.write 'Tokenizing '
|
13
|
+
logger.tokenize :some_category
|
14
|
+
logger.tokenize :some_category
|
15
|
+
logger.tokenize :some_category
|
16
|
+
logger.write ' Dumping '
|
17
|
+
logger.dump :some_category
|
18
|
+
logger.dump :some_category
|
19
|
+
logger.write ' Loading '
|
20
|
+
logger.load :some_category
|
21
|
+
logger.load :some_category
|
22
|
+
logger.load :some_category
|
23
|
+
logger.load :some_category
|
22
24
|
|
23
|
-
|
25
|
+
io.string.should == "Tokenizing TTT Dumping DD Loading ...."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'with IO' do
|
30
|
+
let(:thing) { io }
|
31
|
+
describe 'more complicated test case' do
|
32
|
+
it 'is correct' do
|
33
|
+
logger.write 'Tokenizing '
|
34
|
+
logger.tokenize :some_category
|
35
|
+
logger.tokenize :some_category
|
36
|
+
logger.tokenize :some_category
|
37
|
+
logger.write ' Dumping '
|
38
|
+
logger.dump :some_category
|
39
|
+
logger.dump :some_category
|
40
|
+
logger.write ' Loading '
|
41
|
+
logger.load :some_category
|
42
|
+
logger.load :some_category
|
43
|
+
logger.load :some_category
|
44
|
+
logger.load :some_category
|
45
|
+
|
46
|
+
io.string.should == 'Tokenizing TTT Dumping DD Loading ....'
|
47
|
+
end
|
24
48
|
end
|
25
49
|
end
|
26
50
|
|
@@ -3,24 +3,47 @@ require 'spec_helper'
|
|
3
3
|
describe Picky::Loggers::Silent do
|
4
4
|
|
5
5
|
let(:io) { StringIO.new }
|
6
|
-
let(:logger) { described_class.new
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
6
|
+
let(:logger) { described_class.new thing }
|
7
|
+
context 'with Logger' do
|
8
|
+
let(:thing) { Logger.new io }
|
9
|
+
describe 'more complicated test case' do
|
10
|
+
it 'is correct' do
|
11
|
+
logger.info 'Tokenizing '
|
12
|
+
logger.tokenize :some_category
|
13
|
+
logger.tokenize :some_category
|
14
|
+
logger.tokenize :some_category
|
15
|
+
logger.info ' Dumping '
|
16
|
+
logger.dump :some_category
|
17
|
+
logger.dump :some_category
|
18
|
+
logger.info ' Loading '
|
19
|
+
logger.load :some_category
|
20
|
+
logger.load :some_category
|
21
|
+
logger.load :some_category
|
22
|
+
logger.load :some_category
|
23
|
+
|
24
|
+
io.string.should == ''
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context 'with IO' do
|
29
|
+
let(:thing) { io }
|
30
|
+
describe 'more complicated test case' do
|
31
|
+
it 'is correct' do
|
32
|
+
logger.info 'Tokenizing '
|
33
|
+
logger.tokenize :some_category
|
34
|
+
logger.tokenize :some_category
|
35
|
+
logger.tokenize :some_category
|
36
|
+
logger.info ' Dumping '
|
37
|
+
logger.dump :some_category
|
38
|
+
logger.dump :some_category
|
39
|
+
logger.info ' Loading '
|
40
|
+
logger.load :some_category
|
41
|
+
logger.load :some_category
|
42
|
+
logger.load :some_category
|
43
|
+
logger.load :some_category
|
22
44
|
|
23
|
-
|
45
|
+
io.string.should == ''
|
46
|
+
end
|
24
47
|
end
|
25
48
|
end
|
26
49
|
|
@@ -2,31 +2,55 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Picky::Loggers::Verbose do
|
4
4
|
|
5
|
+
let(:index) { Picky::Index.new :some_index }
|
6
|
+
let(:category) { Picky::Category.new :some_category, index }
|
7
|
+
let(:file) { stub :file, :path => 'some/path' }
|
5
8
|
let(:io) { StringIO.new }
|
6
|
-
let(:logger) { described_class.new
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
let(:logger) { described_class.new thing }
|
10
|
+
context 'with Logger' do
|
11
|
+
let(:thing) { Logger.new io }
|
12
|
+
describe 'more complicated test case' do
|
13
|
+
it 'is correct' do
|
14
|
+
Time.stub! :now => Time.new('zeros')
|
15
|
+
|
16
|
+
logger.info 'Tokenizing '
|
17
|
+
logger.tokenize category, file
|
18
|
+
logger.tokenize category, file
|
19
|
+
logger.tokenize category, file
|
20
|
+
logger.info ' Dumping '
|
21
|
+
logger.dump category
|
22
|
+
logger.dump category
|
23
|
+
logger.info ' Loading '
|
24
|
+
logger.load category
|
25
|
+
logger.load category
|
26
|
+
logger.load category
|
27
|
+
logger.load category
|
13
28
|
|
14
|
-
|
29
|
+
io.string.should == "00:00:00: Tokenizing \n00:00:00: \"some_index:some_category\": Tokenized -> some/path.\n00:00:00: \"some_index:some_category\": Tokenized -> some/path.\n00:00:00: \"some_index:some_category\": Tokenized -> some/path.\n00:00:00: Dumping \n00:00:00: \"some_index:some_category\": Dumped -> index/test/some_index/some_category_*.\n00:00:00: \"some_index:some_category\": Dumped -> index/test/some_index/some_category_*.\n00:00:00: Loading \n00:00:00: \"some_index:some_category\": Loading index from cache.\n00:00:00: \"some_index:some_category\": Loading index from cache.\n00:00:00: \"some_index:some_category\": Loading index from cache.\n00:00:00: \"some_index:some_category\": Loading index from cache.\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'with IO' do
|
34
|
+
let(:thing) { io }
|
35
|
+
describe 'more complicated test case' do
|
36
|
+
it 'is correct' do
|
37
|
+
Time.stub! :now => Time.new('zeros')
|
15
38
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
39
|
+
logger.info 'Tokenizing '
|
40
|
+
logger.tokenize category, file
|
41
|
+
logger.tokenize category, file
|
42
|
+
logger.tokenize category, file
|
43
|
+
logger.info ' Dumping '
|
44
|
+
logger.dump category
|
45
|
+
logger.dump category
|
46
|
+
logger.info ' Loading '
|
47
|
+
logger.load category
|
48
|
+
logger.load category
|
49
|
+
logger.load category
|
50
|
+
logger.load category
|
28
51
|
|
29
|
-
|
52
|
+
io.string.should == "00:00:00: Tokenizing \n00:00:00: \"some_index:some_category\": Tokenized -> some/path.\n00:00:00: \"some_index:some_category\": Tokenized -> some/path.\n00:00:00: \"some_index:some_category\": Tokenized -> some/path.\n00:00:00: Dumping \n00:00:00: \"some_index:some_category\": Dumped -> index/test/some_index/some_category_*.\n00:00:00: \"some_index:some_category\": Dumped -> index/test/some_index/some_category_*.\n00:00:00: Loading \n00:00:00: \"some_index:some_category\": Loading index from cache.\n00:00:00: \"some_index:some_category\": Loading index from cache.\n00:00:00: \"some_index:some_category\": Loading index from cache.\n00:00:00: \"some_index:some_category\": Loading index from cache.\n"
|
53
|
+
end
|
30
54
|
end
|
31
55
|
end
|
32
56
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 4.
|
37
|
+
version: 4.10.0
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 4.
|
45
|
+
version: 4.10.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: text
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|