searcher 0.0.6 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4eb69651c6c8a4237406d4bd25f47fcfa10d59679ed5b0e07a71ffbc742f20cf
4
+ data.tar.gz: 8733222ec9ade3fb808cb0e9a7dae0059fba5a0ba7da22437188fb7042a6cb7c
5
+ SHA512:
6
+ metadata.gz: 6cd72fc4ff1e9423740822169365aaeaae03003dd11b182295f84676dc3ada69f22c0913b2373decd029c20c746347954ae19fc3e9c91d562c4157c037212a68
7
+ data.tar.gz: 8e3743a5c5f3d759b6d132fcaf847c0f643de2ded548a06974ffb1a0bf6a08a845f872f0bf6d2288fca0ade0ff4234fe5288137c2ba540862a75533d2bc1d2dc
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
- source :gemcutter
1
+ source 'https://rubygems.org'
2
2
 
3
3
  group(:test) do
4
- gem 'sqlite3-ruby'
4
+ gem 'sqlite3'
5
5
  gem 'rspec'
6
6
  end
7
7
 
data/Gemfile.lock CHANGED
@@ -1,46 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searcher (0.0.3)
5
- activerecord (~> 3.0.0)
4
+ searcher (0.0.7)
5
+ activerecord (~> 6.0)
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (3.0.0)
11
- activesupport (= 3.0.0)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.4.1)
14
- activerecord (3.0.0)
15
- activemodel (= 3.0.0)
16
- activesupport (= 3.0.0)
17
- arel (~> 1.0.0)
18
- tzinfo (~> 0.3.23)
19
- activesupport (3.0.0)
20
- arel (1.0.1)
21
- activesupport (~> 3.0.0)
22
- builder (2.1.2)
23
- diff-lcs (1.1.2)
24
- i18n (0.4.1)
25
- rspec (2.0.0.beta.22)
26
- rspec-core (= 2.0.0.beta.22)
27
- rspec-expectations (= 2.0.0.beta.22)
28
- rspec-mocks (= 2.0.0.beta.22)
29
- rspec-core (2.0.0.beta.22)
30
- rspec-expectations (2.0.0.beta.22)
31
- diff-lcs (>= 1.1.2)
32
- rspec-mocks (2.0.0.beta.22)
33
- rspec-core (= 2.0.0.beta.22)
34
- rspec-expectations (= 2.0.0.beta.22)
35
- sqlite3-ruby (1.3.1)
36
- tzinfo (0.3.23)
10
+ activemodel (6.0.2.2)
11
+ activesupport (= 6.0.2.2)
12
+ activerecord (6.0.2.2)
13
+ activemodel (= 6.0.2.2)
14
+ activesupport (= 6.0.2.2)
15
+ activesupport (6.0.2.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2)
21
+ coderay (1.1.2)
22
+ concurrent-ruby (1.1.6)
23
+ diff-lcs (1.3)
24
+ i18n (1.8.2)
25
+ concurrent-ruby (~> 1.0)
26
+ method_source (1.0.0)
27
+ minitest (5.14.0)
28
+ pry (0.13.0)
29
+ coderay (~> 1.1)
30
+ method_source (~> 1.0)
31
+ rspec (3.9.0)
32
+ rspec-core (~> 3.9.0)
33
+ rspec-expectations (~> 3.9.0)
34
+ rspec-mocks (~> 3.9.0)
35
+ rspec-core (3.9.1)
36
+ rspec-support (~> 3.9.1)
37
+ rspec-expectations (3.9.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-mocks (3.9.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-support (3.9.2)
44
+ sqlite3 (1.4.2)
45
+ thread_safe (0.3.6)
46
+ tzinfo (1.2.7)
47
+ thread_safe (~> 0.1)
48
+ zeitwerk (2.3.0)
37
49
 
38
50
  PLATFORMS
39
51
  ruby
40
52
 
41
53
  DEPENDENCIES
42
- activerecord (~> 3.0.0)
43
54
  bundler (>= 1.0.0)
55
+ pry
44
56
  rspec
45
57
  searcher!
46
- sqlite3-ruby
58
+ sqlite3
59
+
60
+ BUNDLED WITH
61
+ 2.1.4
data/lib/searcher.rb CHANGED
@@ -2,25 +2,14 @@ require 'active_record'
2
2
  require 'searcher/class_methods'
3
3
 
4
4
  module Searcher
5
- mattr_accessor :classes
5
+ def self.classes=(klass_list)
6
+ @@classes = klass_list
7
+ end
8
+
6
9
  def self.classes
7
- @classes ||= []
10
+ @@classes ||= []
8
11
  end
9
12
  end
10
13
 
11
14
  ActiveRecord::Base.extend(Searcher::ClassMethods)
12
15
 
13
- ActiveSupport.on_load(:after_initialize) do
14
- Dir[Rails.root + "app/models/**/*.rb"].each { |f| require f } if Rails.env.development?
15
- Searcher.classes.each do |klass|
16
- table = klass.arel_table
17
- klass.searcher[:labels].each do |name, config|
18
- association = klass.reflect_on_association(config[:from])
19
- association_table = association.klass.arel_table
20
- if [:has_and_belongs_to_many, :belongs_to].include?(association.macro)
21
- scope = lambda { |q, field| klass.joins(config[:from]).where(association_table[field].eq(q)) }
22
- klass.scope "by_#{name}", scope
23
- end
24
- end
25
- end
26
- end
@@ -4,22 +4,36 @@ module Searcher
4
4
  module ClassMethods
5
5
  def searcher(&block)
6
6
  Searcher.classes << self unless Searcher.classes.include?(self)
7
- @config ||= Searcher::Config.new.instance_exec(&block)
7
+ @config = Searcher::Config.new.instance_exec(&block)
8
+ @config[:labels].each do |name, config|
9
+ association = reflect_on_association(config[:from])
10
+ association_table = association.klass.arel_table
11
+
12
+ next unless %i[has_and_belongs_to_many belongs_to].include?(association.macro)
13
+
14
+ scope = lambda do |q, field|
15
+ joins(config[:from])
16
+ .where(association_table[field].eq(q))
17
+ end
18
+ self.scope "by_#{name}", scope
19
+ end
8
20
  end
9
-
21
+
10
22
  def search(query)
11
23
  klass = self
12
24
 
13
- result = query.split(" ").inject(klass) do |k, piece|
14
- if piece.include?(":")
15
- name, q = piece.split(":")
16
- label = @config[:labels][name.to_sym]
17
- next unless label
18
- send("by_#{name}", q, label[:field])
19
- end
25
+ result = query.split(' ').inject(klass) do |kls, piece|
26
+ next kls unless piece.include?(':')
27
+
28
+ name, q = piece.split(':')
29
+ label = @config[:labels][name.to_sym]
30
+
31
+ next kls unless label
32
+
33
+ kls.send("by_#{name}", q, label[:field])
20
34
  end
21
-
22
- result || klass.all
35
+
36
+ result.all
23
37
  end
24
38
  end
25
- end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Searcher
2
- VERSION = "0.0.6"
2
+ VERSION = "6.0.0"
3
3
  end
data/license.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2011 Ryan Bigg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/searcher.gemspec CHANGED
@@ -5,18 +5,18 @@ Gem::Specification.new do |s|
5
5
  s.name = "searcher"
6
6
  s.version = Searcher::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = []
9
- s.email = []
8
+ s.authors = ["Ryan Bigg"]
9
+ s.email = ["radarlistener@gmail.com"]
10
10
  s.homepage = "http://rubygems.org/gems/searcher"
11
11
  s.summary = "Label-based straight-SQL searcher"
12
12
  s.description = "Label-based straight-SQL searcher"
13
13
 
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
- s.rubyforge_project = "searcher"
16
15
 
17
16
  s.add_development_dependency "bundler", ">= 1.0.0"
18
-
19
- s.add_dependency "activerecord", "~> 3.0"
17
+ s.add_development_dependency "pry"
18
+
19
+ s.add_dependency "activerecord", "~> 6.0"
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
data/searcher.sqlite3 CHANGED
Binary file
@@ -1,3 +1,11 @@
1
+ class Tag < ActiveRecord::Base
2
+ has_and_belongs_to_many :tickets
3
+ end
4
+
5
+ class State < ActiveRecord::Base
6
+ has_many :tickets
7
+ end
8
+
1
9
  class Ticket < ActiveRecord::Base
2
10
  has_and_belongs_to_many :tags
3
11
  belongs_to :state
@@ -8,14 +16,6 @@ class Ticket < ActiveRecord::Base
8
16
  end
9
17
  end
10
18
 
11
- class Tag < ActiveRecord::Base
12
- has_and_belongs_to_many :tickets
13
- end
14
-
15
- class State < ActiveRecord::Base
16
- has_many :tickets
17
- end
18
-
19
19
  #############
20
20
  ### SEEDS ###
21
21
  #############
@@ -4,7 +4,7 @@ ActiveRecord::Schema.define do
4
4
  create_table :tickets, :force => true do |t|
5
5
  t.string :description
6
6
  t.integer :state_id
7
- t.timestamps
7
+ t.timestamps null: false
8
8
  end
9
9
 
10
10
  create_table :tags_tickets, :force => true, :id => false do |t|
@@ -19,4 +19,4 @@ ActiveRecord::Schema.define do
19
19
  t.string :name
20
20
  end
21
21
 
22
- end
22
+ end
@@ -3,25 +3,39 @@ require 'spec_helper'
3
3
  describe Searcher do
4
4
  let(:search_results) { subject }
5
5
  let(:first_result) { subject.first }
6
-
7
- context "habtm label search" do
6
+
7
+ context "habtm label search" do
8
8
  subject { Ticket.search("tag:bug") }
9
9
  it "finds a ticket" do
10
- first_result.description.should eql("Hello world! You are awesome.")
10
+ expect(first_result.description).to eq("Hello world! You are awesome.")
11
11
  end
12
12
  end
13
-
13
+
14
14
  context "belongs_to label search" do
15
15
  subject { Ticket.search("state:Open") }
16
16
  it "finds a ticket" do
17
- first_result.description.should eql("Hello world! You are awesome.")
17
+ expect(first_result.description).to eq("Hello world! You are awesome.")
18
+ end
19
+ end
20
+
21
+ context "combined search" do
22
+ subject { Ticket.search("tag:bug state:Open") }
23
+ it "finds a ticket" do
24
+ expect(first_result.description).to eq("Hello world! You are awesome.")
18
25
  end
19
26
  end
20
-
27
+
28
+ context "no tickets with tag feature" do
29
+ subject { Ticket.search("tag:feature state:Open") }
30
+ it "finds a ticket" do
31
+ expect(first_result).to be_nil
32
+ end
33
+ end
34
+
21
35
  context "undefined label search" do
22
36
  subject { Ticket.search("undefined:true") }
23
37
  it "returns all the records" do
24
- search_results.should eql(Ticket.all)
38
+ expect(search_results).to eq(Ticket.all)
25
39
  end
26
40
  end
27
41
  end
metadata CHANGED
@@ -1,65 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: searcher
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 6
10
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 6.0.0
11
5
  platform: ruby
12
- authors: []
13
-
6
+ authors:
7
+ - Ryan Bigg
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-01-30 00:00:00 +11:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :development
23
21
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
27
24
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
25
+ - !ruby/object:Gem::Version
34
26
  version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
35
34
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: activerecord
39
35
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 7
46
- segments:
47
- - 3
48
- - 0
49
- version: "3.0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.0'
50
48
  type: :runtime
51
- version_requirements: *id002
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6.0'
52
55
  description: Label-based straight-SQL searcher
53
- email: []
54
-
56
+ email:
57
+ - radarlistener@gmail.com
55
58
  executables: []
56
-
57
59
  extensions: []
58
-
59
60
  extra_rdoc_files: []
60
-
61
- files:
62
- - .gitignore
61
+ files:
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - Gemfile.lock
65
65
  - README.md
@@ -68,6 +68,7 @@ files:
68
68
  - lib/searcher/class_methods.rb
69
69
  - lib/searcher/config.rb
70
70
  - lib/searcher/version.rb
71
+ - license.txt
71
72
  - searcher.gemspec
72
73
  - searcher.sqlite3
73
74
  - spec/fixtures/models.rb
@@ -75,41 +76,26 @@ files:
75
76
  - spec/searcher_spec.rb
76
77
  - spec/spec_helper.rb
77
78
  - tmp/.gitkeep
78
- has_rdoc: true
79
79
  homepage: http://rubygems.org/gems/searcher
80
80
  licenses: []
81
-
81
+ metadata: {}
82
82
  post_install_message:
83
83
  rdoc_options: []
84
-
85
- require_paths:
84
+ require_paths:
86
85
  - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
- requirements:
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
90
88
  - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
- version: "0"
96
- required_rubygems_version: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
99
93
  - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 23
102
- segments:
103
- - 1
104
- - 3
105
- - 6
94
+ - !ruby/object:Gem::Version
106
95
  version: 1.3.6
107
96
  requirements: []
108
-
109
- rubyforge_project: searcher
110
- rubygems_version: 1.3.7
97
+ rubygems_version: 3.0.3
111
98
  signing_key:
112
- specification_version: 3
99
+ specification_version: 4
113
100
  summary: Label-based straight-SQL searcher
114
101
  test_files: []
115
-