sunspot-null_result 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/sunspot/null_result.rb +63 -0
- data/lib/sunspot/null_result/version.rb +5 -0
- data/sunspot-null_result.gemspec +25 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 522194f37eda68fdd70d0fc7e78c8032041e5d1e
|
4
|
+
data.tar.gz: 1f15a77e1fb20f036af4fd9ac10c09283ddf2c1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28d335ae27055ecabfbfe3de64ab5b6ea1cd93111e4104df36656bb2ad264b8d7f1a22ba1a8e0cdcae1cb35b23cd37ed78ff46d122561aa94a041b98added1c0
|
7
|
+
data.tar.gz: 86fc219514fb27d947ab701b21d940874af44dadc246d2f42025f25198911cb639660acd5192c649cf3c5a0a2109a2c87a504f899177073892a450c4c22d4b06
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sunspot-null_result
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
rvm:
|
4
|
+
- 2.2.2
|
5
|
+
before_install: gem install bundler -v 1.10.5
|
6
|
+
cache:
|
7
|
+
bundler: true
|
8
|
+
notifications:
|
9
|
+
webhooks:
|
10
|
+
secure: bp5A92/Do0Ux/LkWxmnM3XlG7JjjPfodiwXgpbPsnKKhA6gLd3uMl9n3HADczI3fiMdyM0bcUme4ULN6uMa4H1Ofss6VD5MW/1hqZvVkUwnu4YsCbevAUs+wcaoJwlzjzvX7LiKUvNFk9oJoFgDItVrKrekD+BuU2vtfzcJq/cxY6+XUrvwjAdTLJmeNo7jcRuVTdkZ4938URSlQp53Ivs47XS26peJWDwvKEW2Nfc8r6Ts7JzFMpf8pZSoinlNUL7zEM3+DyvPjA+UNIx0CwL0JMTDLIhloGePlNwoXclurt4+UOMhLgAlCWDUxBJ18zhDGrUEfFSDz0zjzLYpKTqGKY3fB4YPLISJ402msFmqVVdQotZJ/y5w+bvyiRDktnjHCTdONSzW2n1dtKTUGhnenYfC+btZVuik9mWsNoemCLsC8XXMY/JOywEkdLDeoe2ksiTJPqpW/IyCkZX+qbkwRi5sYlhm+7/8GjDqz8F40aM5qn24y6h2sF+z0vnj4pioTa+6fPjIC7T8rv+VeCpiBlffUVqB6TveR3Wv2O89xQllZNDwpKdCxbNqJQflcM/xb4kBo8nkAWXqPOk43zrSOHTmyBjod7wZRHq1zdsp1+PCBVT2XAXk+JaxSWFWs7jHsa+PCESIs01LMoScfgyQ9LXqcMvjQ6Kzzgre9ktc=
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Sunspot::NullResult [![Build Status](https://travis-ci.org/Absolventa/sunspot_null-result.svg?branch=master)](https://travis-ci.org/Absolventa/sunspot_null-result)
|
2
|
+
|
3
|
+
Interface taken from `Sunspot::Rails::StubSessionProxy::PaginatesCollection` of
|
4
|
+
[sunspot-rails](https://github.com/sunspot/sunspot/tree/master/sunspot_rails).
|
5
|
+
|
6
|
+
It adds the option to inject records to mimic actual search results (and yes,
|
7
|
+
thus making fun of the "Null" gem name).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'sunspot-null_result'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install sunspot-null_result
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
RSpec case:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
RSpec.describe 'stubbed Solr result' do
|
31
|
+
let(:search) { Sunspot::NullResult.new(records) }
|
32
|
+
before { allow(MyModel).to receive(:search).and_return(search) }
|
33
|
+
|
34
|
+
context 'with no records' do
|
35
|
+
let(:records) { [] }
|
36
|
+
# …
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with some records' do
|
40
|
+
let(:records) { [MyModel.new, MyModel.new] }
|
41
|
+
# …
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Rescue case for unavailable Solr server, e.g. Websolr having issues.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
class ApplicationController < ActionController::Base
|
50
|
+
|
51
|
+
rescue_from RSolr::Error::Http do |exception|
|
52
|
+
# Handle exception so that a complete server shutdown
|
53
|
+
# doesn't go unnoticed. Your app may still work using:
|
54
|
+
|
55
|
+
failover_records = MyModel.last(10)
|
56
|
+
Sunspot::NullResult.new(failover_records)
|
57
|
+
end
|
58
|
+
|
59
|
+
# …
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Changelog
|
64
|
+
|
65
|
+
### HEAD (not yet released)
|
66
|
+
|
67
|
+
### v0.1.0
|
68
|
+
* Initial working release
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as free and open source software under the terms of the
|
74
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
75
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sunspot/null_result"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "sunspot/null_result/version"
|
2
|
+
|
3
|
+
module Sunspot
|
4
|
+
class NullResult
|
5
|
+
attr_reader :collection
|
6
|
+
|
7
|
+
def initialize(collection = [])
|
8
|
+
@collection = collection
|
9
|
+
end
|
10
|
+
|
11
|
+
# Implements the interface of
|
12
|
+
# https://github.com/sunspot/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/stub_session_proxy.rb
|
13
|
+
class PaginatedNullArray < Array
|
14
|
+
|
15
|
+
alias total_count size
|
16
|
+
|
17
|
+
def current_page
|
18
|
+
1
|
19
|
+
end
|
20
|
+
|
21
|
+
def total_pages
|
22
|
+
1
|
23
|
+
end
|
24
|
+
alias num_pages total_pages
|
25
|
+
|
26
|
+
def per_page
|
27
|
+
1
|
28
|
+
end
|
29
|
+
alias limit_value per_page
|
30
|
+
|
31
|
+
def previous_page
|
32
|
+
end
|
33
|
+
|
34
|
+
def next_page
|
35
|
+
end
|
36
|
+
|
37
|
+
def first_page?
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def last_page?
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def out_of_bounds?
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def offset
|
50
|
+
0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def hits
|
55
|
+
PaginatedNullArray.new(collection)
|
56
|
+
end
|
57
|
+
|
58
|
+
def results
|
59
|
+
PaginatedNullArray.new(collection)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sunspot/null_result/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sunspot-null_result"
|
8
|
+
spec.version = Sunspot::NullResult::VERSION
|
9
|
+
spec.authors = ["Carsten Zimmermann"]
|
10
|
+
spec.email = ["cz@aegisnet.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides a standalone mock result for Solr searches}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/Absolventa/sunspot-null_result"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sunspot-null_result
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carsten Zimmermann
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- cz@aegisnet.de
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/sunspot/null_result.rb
|
74
|
+
- lib/sunspot/null_result/version.rb
|
75
|
+
- sunspot-null_result.gemspec
|
76
|
+
homepage: https://github.com/Absolventa/sunspot-null_result
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.5.1
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Provides a standalone mock result for Solr searches
|
100
|
+
test_files: []
|