picky 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Cacher
2
2
  module Partial
3
- Default = Substring.new :from => -3, :to => -1
3
+ Default = Substring.new from: -3, to: -1
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ module Cacher
6
6
 
7
7
  # Generate a partial index based on the given index.
8
8
  #
9
- def generate strategy = Partial::Substring.new(:from => 1)
9
+ def generate strategy = Partial::Substring.new(from: 1)
10
10
  strategy.generate_from self.index
11
11
  end
12
12
 
@@ -32,7 +32,7 @@ module Cacher
32
32
  # Generates an index for the given index (in exact index style).
33
33
  #
34
34
  # In the following form:
35
- # [:meier, :mueller, :peter, :pater] => { :MR => [:meier], :MLR => [:mueller], :PTR => [:peter, :pater] }
35
+ # [:meier, :mueller, :peter, :pater] => { MR: [:meier], MLR: [:mueller], PTR: [:peter, :pater] }
36
36
  #
37
37
  def generate_from index
38
38
  hash = hashify index.keys
@@ -44,7 +44,7 @@ module Picky
44
44
 
45
45
  def initialize
46
46
  @types = {
47
- :project => [Project, :project_name]
47
+ project: [Project, :project_name]
48
48
  }
49
49
  end
50
50
 
@@ -18,7 +18,7 @@ module Index
18
18
  #
19
19
  def backup
20
20
  prepare_backup backup_path
21
- FileUtils.cp cache_path, target, :verbose => true
21
+ FileUtils.cp cache_path, target, verbose: true
22
22
  end
23
23
  def backup_path
24
24
  ::File.join ::File.dirname(cache_path), 'backup'
@@ -30,7 +30,7 @@ module Index
30
30
  # Restore.
31
31
  #
32
32
  def restore
33
- FileUtils.cp backup_file_path_of(cache_path), cache_path, :verbose => true
33
+ FileUtils.cp backup_file_path_of(cache_path), cache_path, verbose: true
34
34
  end
35
35
  def backup_file_path_of path
36
36
  dir, name = ::File.split path
@@ -8,7 +8,7 @@ module Index
8
8
  :json
9
9
  end
10
10
  def load
11
- Yajl::Parser.parse ::File.open(cache_path, 'r'), :symbolize_keys => true
11
+ Yajl::Parser.parse ::File.open(cache_path, 'r'), symbolize_keys: true
12
12
  end
13
13
  def dump hash
14
14
  hash.dump_json cache_path
@@ -19,7 +19,7 @@ module Index
19
19
  @combinator = combinator_for categories, ignore_unassigned_tokens
20
20
  end
21
21
  def combinator_for categories, ignore_unassigned_tokens
22
- Query::Combinator.new @categories, :ignore_unassigned_tokens => ignore_unassigned_tokens
22
+ Query::Combinator.new @categories, ignore_unassigned_tokens: ignore_unassigned_tokens
23
23
  end
24
24
 
25
25
  #
@@ -40,7 +40,7 @@ module Indexers
40
40
 
41
41
  results.each do |indexed_id, *values|
42
42
  values.each &:downcase!
43
- documents << hashed(values).merge(:id => indexed_id, :type => type_name)
43
+ documents << hashed(values).merge(id: indexed_id, type: type_name)
44
44
  end
45
45
 
46
46
  solr.add documents
data/lib/picky/indexes.rb CHANGED
@@ -21,7 +21,7 @@ module Indexes
21
21
  # rake index:ordered
22
22
  #
23
23
  timed_exclaim "INDEXING USING #{Cores.max_processors} PROCESSORS, IN #{randomly ? 'RANDOM' : 'GIVEN'} ORDER."
24
- Cores.forked self.fields, { :randomly => randomly } do |field, cores|
24
+ Cores.forked self.fields, { randomly: randomly } do |field, cores|
25
25
  field.index
26
26
  field.cache
27
27
  end
@@ -42,7 +42,7 @@ module Query
42
42
 
43
43
  index_types.each do |index|
44
44
  begin
45
- response = server.select :q => new_query, :fq => "type:#{index.name}", :hl => true, :'hl.fl' => '*', :'hl.simple.pre' => '<', :'hl.simple.post' => '>', :facet => true
45
+ response = server.select q: new_query, fq: "type:#{index.name}", hl: true, :'hl.fl' => '*', :'hl.simple.pre' => '<', :'hl.simple.post' => '>', facet: true
46
46
  rescue RSolr::RequestError => re
47
47
  return results
48
48
  end
@@ -58,7 +58,7 @@ module Query
58
58
  similar[index.name] = possibilities unless possibilities.empty?
59
59
  end
60
60
 
61
- results.add :similar => similar
61
+ results.add similar: similar
62
62
  end
63
63
 
64
64
  # TODO
@@ -20,10 +20,10 @@ module Results
20
20
  #
21
21
  #
22
22
  def serialize
23
- { :allocations => allocations.to_result,
24
- :offset => offset,
25
- :duration => duration,
26
- :total => total }
23
+ { allocations: allocations.to_result,
24
+ offset: offset,
25
+ duration: duration,
26
+ total: total }
27
27
  end
28
28
  # The default format is json.
29
29
  #
data/lib/picky/routing.rb CHANGED
@@ -5,9 +5,9 @@ require 'rack/mount'
5
5
  class Routing
6
6
 
7
7
  @@defaults = {
8
- :query_key => 'query'.freeze,
9
- :offset_key => 'offset'.freeze,
10
- :content_type => 'application/octet-stream'.freeze
8
+ query_key: 'query'.freeze,
9
+ offset_key: 'offset'.freeze,
10
+ content_type: 'application/octet-stream'.freeze
11
11
  }
12
12
 
13
13
  def initialize
@@ -32,24 +32,6 @@ class Routing
32
32
  routes.call env
33
33
  end
34
34
 
35
- # # Set the defaults.
36
- # #
37
- # # Options are:
38
- # # * :query_key => :query # default
39
- # # * :offset_key => :offset # default
40
- # #
41
- # # * :tokenizer => Tokenizers::Query.new # default
42
- # #
43
- # def defaults options = {}
44
- # @defaults[:query_key] = options[:query_key].to_s if options[:query_key]
45
- # @defaults[:offset_key] = options[:offset_key].to_s if options[:offset_key]
46
- #
47
- # @defaults[:tokenizer] = options[:tokenizer] if options[:tokenizer]
48
- # @defaults[:content_type] = options[:content_type] if options[:content_type]
49
- #
50
- # @defaults
51
- # end
52
-
53
35
  #
54
36
  #
55
37
  def route options = {}
@@ -101,7 +83,7 @@ class Routing
101
83
  def default_options url, route_options = {}
102
84
  url = normalized url
103
85
 
104
- options = { :request_method => 'GET' }.merge route_options
86
+ options = { request_method: 'GET' }.merge route_options
105
87
 
106
88
  options[:path_info] = url if url
107
89
 
@@ -7,7 +7,7 @@ module Sources
7
7
 
8
8
  attr_reader :select_statement, :database, :connection_options
9
9
 
10
- def initialize select_statement, options = { :file => 'app/db.yml' }
10
+ def initialize select_statement, options = { file: 'app/db.yml' }
11
11
  @select_statement = select_statement
12
12
  @database = create_database_adapter
13
13
  @options = options
@@ -11,7 +11,7 @@ module Sources
11
11
  require 'www/delicious'
12
12
  rescue LoadError
13
13
  puts "Delicious gem missing!\nTo use the delicious source, you need to:\n 1. Add the following line to Gemfile:\n gem 'www-delicious'\n 2. Then, run:\n bundle update\n"
14
- exit(1)
14
+ exit 1
15
15
  end
16
16
 
17
17
  # Harvests the data to index.
@@ -30,12 +30,12 @@ module Sources
30
30
  #
31
31
  def get_data
32
32
  @generated_id ||= 0
33
- @posts ||= WWW::Delicious.new(@username, @password).posts_recent(:count => 100)
33
+ @posts ||= WWW::Delicious.new(@username, @password).posts_recent(count: 100)
34
34
  @posts.each do |post|
35
35
  data = {
36
- :title => post.title,
37
- :tags => post.tags.join(' '),
38
- :url => post.url.to_s
36
+ title: post.title,
37
+ tags: post.tags.join(' '),
38
+ url: post.url.to_s
39
39
  }
40
40
  @generated_id += 1
41
41
  yield @generated_id, data
data/lib/tasks/try.rake CHANGED
@@ -15,11 +15,7 @@ namespace :try do
15
15
  task :query, [:text] => :application do |_, options|
16
16
  text = options.text
17
17
 
18
- # TODO tokenize destroys the original text...
19
- #
20
- # TODO Use the Query Tokenizer.
21
- #
22
- puts "\"#{text}\" is query tokenized as #{Tokenizers::Default::Query.tokenize(text.dup).to_a.map(&:to_s).map(&:to_sym)}"
18
+ puts "\"#{text}\" is query tokenized as #{Tokenizers::Default::Query.tokenize(text).to_a.map(&:to_s).map(&:to_sym)}"
23
19
  end
24
20
 
25
21
  desc "Try the given text with both the index and the query (type:field optional)."
@@ -13,29 +13,29 @@ describe Cacher::Partial::Substring do
13
13
  end
14
14
  describe 'generate_from' do
15
15
  it 'should generate the right index' do
16
- @cacher.generate_from( :florian => [1], :flavia => [2] ).should == {
17
- :florian => [1],
18
- :floria => [1],
19
- :flori => [1],
20
- :flor => [1],
21
- :flo => [1],
22
- :fl => [1, 2],
23
- :f => [1, 2],
24
- :flavia => [2],
25
- :flavi => [2],
26
- :flav => [2],
27
- :fla => [2]
16
+ @cacher.generate_from(florian: [1], flavia: [2]).should == {
17
+ florian: [1],
18
+ floria: [1],
19
+ flori: [1],
20
+ flor: [1],
21
+ flo: [1],
22
+ fl: [1, 2],
23
+ f: [1, 2],
24
+ flavia: [2],
25
+ flavi: [2],
26
+ flav: [2],
27
+ fla: [2]
28
28
  }
29
29
  end
30
30
  it "should be fast" do
31
- performance_of { @cacher.generate_from( :florian => [1], :flavia => [2] ) }.should < 0.0001
31
+ performance_of { @cacher.generate_from(florian: [1], flavia: [2]) }.should < 0.0001
32
32
  end
33
33
  it "should handle duplicate ids" do
34
- @cacher.generate_from( :flo => [1], :fla => [1] ).should == {
35
- :flo => [1],
36
- :fl => [1],
37
- :f => [1],
38
- :fla => [1]
34
+ @cacher.generate_from(flo: [1], fla: [1]).should == {
35
+ flo: [1],
36
+ fl: [1],
37
+ f: [1],
38
+ fla: [1]
39
39
  }
40
40
  end
41
41
  end
@@ -43,24 +43,24 @@ describe Cacher::Partial::Substring do
43
43
  context 'from set' do
44
44
  describe 'negative from' do
45
45
  before(:each) do
46
- @cacher = Cacher::Partial::Substring.new :from => -2
46
+ @cacher = Cacher::Partial::Substring.new from: -2
47
47
  end
48
48
  it 'should generate the right index' do
49
- @cacher.generate_from( :florian => [1], :flavia => [2] ).should == {
50
- :florian => [1],
51
- :floria => [1],
52
- :flavia => [2],
53
- :flavi => [2]
49
+ @cacher.generate_from(florian: [1], flavia: [2]).should == {
50
+ florian: [1],
51
+ floria: [1],
52
+ flavia: [2],
53
+ flavi: [2]
54
54
  }
55
55
  end
56
56
  end
57
57
  context "large from" do
58
58
  before(:each) do
59
- @cacher = Cacher::Partial::Substring.new :from => 10
59
+ @cacher = Cacher::Partial::Substring.new from: 10
60
60
  end
61
61
  describe 'generate_from' do
62
62
  it 'should generate the right index' do
63
- @cacher.generate_from( :florian => [1], :'01234567890' => [2] ).should == {
63
+ @cacher.generate_from(florian: [1], :'01234567890' => [2] ).should == {
64
64
  :florian => [1],
65
65
  :'01234567890' => [2],
66
66
  :'0123456789' => [2]
@@ -70,7 +70,7 @@ describe Cacher::Partial::Substring do
70
70
  end
71
71
  context 'default to' do
72
72
  before(:each) do
73
- @cacher = Cacher::Partial::Substring.new :from => 4
73
+ @cacher = Cacher::Partial::Substring.new from: 4
74
74
  end
75
75
  describe 'to' do
76
76
  it 'should return the right value' do
@@ -124,7 +124,7 @@ describe Cacher::Partial::Substring do
124
124
  end
125
125
  context 'to set' do
126
126
  before(:each) do
127
- @cacher = Cacher::Partial::Substring.new :from => 4, :to => -2
127
+ @cacher = Cacher::Partial::Substring.new from: 4, to: -2
128
128
  end
129
129
  describe 'to' do
130
130
  it 'should return the right value' do
@@ -150,7 +150,7 @@ describe Cacher::Partial::Substring do
150
150
  end
151
151
  context 'to set' do
152
152
  before(:each) do
153
- @cacher = Cacher::Partial::Substring.new :from => 4, :to => 0
153
+ @cacher = Cacher::Partial::Substring.new from: 4, to: 0
154
154
  end
155
155
  describe 'to' do
156
156
  it 'should return the right value' do
@@ -7,6 +7,14 @@ describe Query::Allocation do
7
7
  @allocation = Query::Allocation.new @combinations
8
8
  end
9
9
 
10
+ describe "eql?" do
11
+ # TODO This works, but is not acceptable.
12
+ #
13
+ it "returns true" do
14
+ @allocation.eql?(:anything).should == true
15
+ end
16
+ end
17
+
10
18
  describe "hash" do
11
19
  it "delegates to the combinations" do
12
20
  @combinations.should_receive(:hash).once.with
@@ -1,14 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # TODO Slow spec.
4
+ #
3
5
  describe Sources::Delicious do
4
6
 
5
7
  context "with file" do
6
8
 
7
9
  describe "check_gem" do
8
- # TODO How to actually test this?
9
- #
10
- it "checks if the gem is there" do
11
- lambda { Sources::Delicious.new(:username, :password) }.should_not raise_error
10
+ before(:each) do
11
+ @source = Sources::Delicious.allocate
12
+ end
13
+ context "doesn't find www/delicious" do
14
+ before(:each) do
15
+ @source.should_receive(:require).any_number_of_times.and_raise LoadError
16
+ end
17
+ it "puts & exits" do
18
+ @source.should_receive(:puts).once.with "Delicious gem missing!\nTo use the delicious source, you need to:\n 1. Add the following line to Gemfile:\n gem 'www-delicious'\n 2. Then, run:\n bundle update\n"
19
+ @source.should_receive(:exit).once.with 1
20
+
21
+ @source.check_gem
22
+ end
23
+ end
24
+ context "finds www/delicious" do
25
+ before(:each) do
26
+ @source.should_receive(:require).any_number_of_times.and_return
27
+ end
28
+ it "checks if the gem is there" do
29
+ lambda { @source.check_gem }.should_not raise_error
30
+ end
12
31
  end
13
32
  end
14
33
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 1
9
- version: 0.9.1
8
+ - 2
9
+ version: 0.9.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-27 00:00:00 +02:00
17
+ date: 2010-10-29 00:00:00 +02:00
18
18
  default_executable: picky
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency