picky 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -79,7 +79,7 @@ module Picky
79
79
  def dump
80
80
  exact.dump
81
81
  partial.dump
82
- timed_exclaim %Q{ "#{identifier}": Dumped -> #{index_directory.gsub("#{PICKY_ROOT}/", '')}/#{name}_*.}
82
+ Picky.logger.dump self
83
83
  end
84
84
 
85
85
  # Returns the backend.
@@ -7,7 +7,7 @@ module Picky
7
7
  # Loads the index from cache.
8
8
  #
9
9
  def load
10
- timed_exclaim %Q{ "#{identifier}": Loading index from cache.}
10
+ Picky.logger.load self
11
11
  clear_realtime # THINK Should we really explicitly clear the realtime? Or should it just be loaded?
12
12
  exact.load
13
13
  partial.load
@@ -1,5 +1,7 @@
1
1
  class Object # :nodoc:all
2
-
2
+
3
+ # TODO Remove.
4
+
3
5
  # Puts a text in the form:
4
6
  # 12:34:56: text here
5
7
  #
@@ -10,8 +12,8 @@ class Object # :nodoc:all
10
12
  # Just puts the given text.
11
13
  #
12
14
  def exclaim text
13
- STDOUT.puts text
14
- STDOUT.flush
15
+ Picky.logger.info text
16
+ Picky.logger.flush
15
17
  end
16
18
 
17
19
  # Puts a text that informs the user of a missing gem.
@@ -6,12 +6,10 @@ module Picky
6
6
  module Indexing
7
7
 
8
8
  include Measuring
9
-
10
- # Returns a duration in seconds.
11
- #
9
+
12
10
  def timed_indexing scheduler, &block
13
- timed_exclaim "Indexing using #{scheduler.fork? ? 'multiple processes' : 'a single process'}."
14
- timed_exclaim "Indexing finished after #{timed(&block).round}s."
11
+ Picky.logger.info "Picky is indexing using #{scheduler.fork? ? 'multiple processes' : 'a single process'}: "
12
+ Picky.logger.info " Done in #{timed(&block).round}s.\n"
15
13
  end
16
14
 
17
15
  end
@@ -40,7 +40,7 @@ module Picky
40
40
  end
41
41
 
42
42
  def notify_finished prepared_file
43
- timed_exclaim %Q{ "#{@index_or_category.identifier}": Tokenized -> #{prepared_file.path.gsub("#{PICKY_ROOT}/", '')}.}
43
+ Picky.logger.tokenize @index_or_category, prepared_file
44
44
  end
45
45
 
46
46
  end
@@ -26,7 +26,7 @@ module Picky
26
26
  indexes.each { |index| index.prepare scheduler }
27
27
  scheduler.finish
28
28
 
29
- timed_exclaim "Tokenizing finished, generating data for indexes from tokenized data."
29
+ # timed_exclaim "Tokenizing finished, generating data for indexes from tokenized data."
30
30
 
31
31
  indexes.each { |index| index.cache scheduler }
32
32
  scheduler.finish
data/lib/picky/loader.rb CHANGED
@@ -192,6 +192,13 @@ module Picky
192
192
  load_relative 'api/category/partial'
193
193
  load_relative 'api/category/similarity'
194
194
  load_relative 'api/search/boost'
195
+
196
+ # Loggers.
197
+ #
198
+ load_relative 'loggers/silent'
199
+ load_relative 'loggers/concise'
200
+ load_relative 'loggers/verbose'
201
+ load_relative 'loggers/default'
195
202
 
196
203
  # Tokenizer.
197
204
  #
@@ -0,0 +1,49 @@
1
+ module Picky
2
+
3
+ module Loggers
4
+
5
+ # The verbose logger outputs little information.
6
+ #
7
+ class Concise < Silent
8
+
9
+ attr_reader :tokenized,
10
+ :dumped,
11
+ :loaded
12
+
13
+ def initialize *args
14
+ 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
+ end
28
+
29
+ def tokenize(*)
30
+ progress 'T'
31
+ end
32
+
33
+ def dump(*)
34
+ progress 'D'
35
+ end
36
+
37
+ def load(*)
38
+ progress
39
+ end
40
+
41
+ def progress type = '.'
42
+ io.write type
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,10 @@
1
+ module Picky
2
+ module Loggers
3
+
4
+ # Default is the concise logger.
5
+ #
6
+ remove_const :Default if defined? Default
7
+ Default = Concise.new
8
+
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ module Picky
2
+
3
+ module Loggers
4
+
5
+ # The silent logger just gobbles up all information.
6
+ #
7
+ class Silent
8
+
9
+ attr_reader :io
10
+
11
+ def initialize io = STDOUT
12
+ @io = io
13
+ end
14
+
15
+ def info(*)
16
+
17
+ end
18
+
19
+ def tokenize(*)
20
+
21
+ end
22
+
23
+ def dump(*)
24
+
25
+ end
26
+
27
+ def load(*)
28
+
29
+ end
30
+
31
+ # Flush this logger.
32
+ #
33
+ def flush
34
+ io.flush
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,37 @@
1
+ module Picky
2
+
3
+ module Loggers
4
+
5
+ # The verbose logger outputs all information.
6
+ #
7
+ class Verbose < Silent
8
+
9
+ def info text
10
+ timed_exclaim text
11
+ end
12
+
13
+ def tokenize index_or_category, prepared_file
14
+ timed_exclaim %Q{ "#{index_or_category.identifier}": Tokenized -> #{prepared_file.path.gsub("#{PICKY_ROOT}/", '')}.}
15
+ end
16
+
17
+ def dump category
18
+ timed_exclaim %Q{ "#{category.identifier}": Dumped -> #{category.index_directory.gsub("#{PICKY_ROOT}/", '')}/#{category.name}_*.}
19
+ end
20
+
21
+ def load category
22
+ timed_exclaim %Q{ "#{category.identifier}": Loading index from cache.}
23
+ end
24
+
25
+ # Puts a text in the form:
26
+ # 12:34:56: text here
27
+ #
28
+ def timed_exclaim text
29
+ io.puts "#{Time.now.strftime("%H:%M:%S")}: #{text}"
30
+ flush
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
data/lib/picky.rb CHANGED
@@ -32,5 +32,7 @@ module Picky
32
32
  class << self
33
33
  attr_accessor :logger
34
34
  end
35
+
36
+ self.logger = Loggers::Default
35
37
 
36
38
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Loggers::Concise do
4
+
5
+ let(:io) { StringIO.new }
6
+ let(:logger) { described_class.new io }
7
+
8
+ describe 'more complicated test case' do
9
+ it 'is correct' do
10
+ logger.info 'Tokenizing '
11
+ logger.tokenize :some_category
12
+ logger.tokenize :some_category
13
+ logger.tokenize :some_category
14
+ logger.info ' Dumping '
15
+ logger.dump :some_category
16
+ logger.dump :some_category
17
+ logger.info ' Loading '
18
+ logger.load :some_category
19
+ logger.load :some_category
20
+ logger.load :some_category
21
+ logger.load :some_category
22
+
23
+ io.string.should == 'Tokenizing TTT Dumping DD Loading ....'
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Loggers::Silent do
4
+
5
+ let(:io) { StringIO.new }
6
+ let(:logger) { described_class.new io }
7
+
8
+ describe 'more complicated test case' do
9
+ it 'is correct' do
10
+ logger.info 'Tokenizing '
11
+ logger.tokenize :some_category
12
+ logger.tokenize :some_category
13
+ logger.tokenize :some_category
14
+ logger.info ' Dumping '
15
+ logger.dump :some_category
16
+ logger.dump :some_category
17
+ logger.info ' Loading '
18
+ logger.load :some_category
19
+ logger.load :some_category
20
+ logger.load :some_category
21
+ logger.load :some_category
22
+
23
+ io.string.should == ''
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Loggers::Verbose do
4
+
5
+ let(:io) { StringIO.new }
6
+ let(:logger) { described_class.new io }
7
+
8
+ describe 'more complicated test case' do
9
+ it 'is correct' do
10
+ index = Picky::Index.new :some_index
11
+ category = Picky::Category.new :some_category, index
12
+ file = stub :file, :path => 'some/path'
13
+
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
28
+
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
+
33
+ end
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.1.0
4
+ version: 4.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70259240903180 !ruby/object:Gem::Requirement
16
+ requirement: &70345542373860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70259240903180
24
+ version_requirements: *70345542373860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: picky-client
27
- requirement: &70259240902680 !ruby/object:Gem::Requirement
27
+ requirement: &70345542373360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 4.1.0
32
+ version: 4.2.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70259240902680
35
+ version_requirements: *70345542373360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: text
38
- requirement: &70259240902260 !ruby/object:Gem::Requirement
38
+ requirement: &70345542372920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70259240902260
46
+ version_requirements: *70345542372920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yajl-ruby
49
- requirement: &70259240901800 !ruby/object:Gem::Requirement
49
+ requirement: &70345542372440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70259240901800
57
+ version_requirements: *70345542372440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70259240901300 !ruby/object:Gem::Requirement
60
+ requirement: &70345542371940 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70259240901300
68
+ version_requirements: *70345542371940
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: procrastinate
71
- requirement: &70259240900800 !ruby/object:Gem::Requirement
71
+ requirement: &70345542371440 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.4'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70259240900800
79
+ version_requirements: *70345542371440
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rack_fast_escape
82
- requirement: &70259240900420 !ruby/object:Gem::Requirement
82
+ requirement: &70345542371000 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70259240900420
90
+ version_requirements: *70345542371000
91
91
  description: Fast Ruby semantic text search engine with comfortable single field interface.
92
92
  email: florian.hanke+picky@gmail.com
93
93
  executables:
@@ -197,6 +197,10 @@ files:
197
197
  - lib/picky/interfaces/live_parameters/master_child.rb
198
198
  - lib/picky/interfaces/live_parameters/unicorn.rb
199
199
  - lib/picky/loader.rb
200
+ - lib/picky/loggers/concise.rb
201
+ - lib/picky/loggers/default.rb
202
+ - lib/picky/loggers/silent.rb
203
+ - lib/picky/loggers/verbose.rb
200
204
  - lib/picky/migrations/from_30_to_31.rb
201
205
  - lib/picky/performant.rb
202
206
  - lib/picky/query/allocation.rb
@@ -333,6 +337,9 @@ files:
333
337
  - spec/lib/interfaces/live_parameters/master_child_spec.rb
334
338
  - spec/lib/interfaces/live_parameters/unicorn_spec.rb
335
339
  - spec/lib/loader_spec.rb
340
+ - spec/lib/loggers/concise_spec.rb
341
+ - spec/lib/loggers/silent_spec.rb
342
+ - spec/lib/loggers/verbose_spec.rb
336
343
  - spec/lib/query/allocation_spec.rb
337
344
  - spec/lib/query/allocations_spec.rb
338
345
  - spec/lib/query/boosts_spec.rb
@@ -479,6 +486,9 @@ test_files:
479
486
  - spec/lib/interfaces/live_parameters/master_child_spec.rb
480
487
  - spec/lib/interfaces/live_parameters/unicorn_spec.rb
481
488
  - spec/lib/loader_spec.rb
489
+ - spec/lib/loggers/concise_spec.rb
490
+ - spec/lib/loggers/silent_spec.rb
491
+ - spec/lib/loggers/verbose_spec.rb
482
492
  - spec/lib/query/allocation_spec.rb
483
493
  - spec/lib/query/allocations_spec.rb
484
494
  - spec/lib/query/boosts_spec.rb