h2ocube_rails_sunspot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/h2ocube_rails_sunspot.gemspec +22 -0
- data/lib/generators/h2ocube_rails_sunspot_generator.rb +19 -0
- data/lib/generators/source/sunspot.rb.erb +92 -0
- data/lib/generators/source/sunspot.yml.erb +16 -0
- data/lib/h2ocube_rails_sunspot.rb +8 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 840a9c483bd1d4cf1210432d104c0d17ae2904fe
|
4
|
+
data.tar.gz: 6aa8c8eb06ad60a83207422c68fc1716fcfc8555
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35ab326f4400b67aad723a66fa4dc6fb9c0794e312489bb33b7035dc3cd8910e487169a4c1e26ca58b853dd276d3dcf4696a6090a67cab0c148e3b78d18bdf6a
|
7
|
+
data.tar.gz: 2124b21e7a0dada07b030eaa08761bb43c2c77f69806763e77e54e288916bbcc0d5e7c96ecefeaba358fd4e0d49665d7ca194a778012d4e4988ada7a36e7a0a4
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 H2ocube.com
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# SUMMARY
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/h2ocube_rails_sunspot.png)](http://badge.fury.io/rb/h2ocube_rails_sunspot)
|
4
|
+
|
5
|
+
This is a plugin to add some useful tasks to rails.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'h2ocube_rails_sunspot'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
$ rails g h2ocube_rails_sunspot
|
18
|
+
|
19
|
+
Add sunspot to spec/spec_helper.rb
|
20
|
+
|
21
|
+
config.before(:all, search: true) do
|
22
|
+
SunspotTest.setup_solr
|
23
|
+
Sunspot.remove_all!
|
24
|
+
Sunspot.commit
|
25
|
+
end
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'h2ocube_rails_sunspot'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Ben']
|
9
|
+
s.email = ['ben@h2ocube.com']
|
10
|
+
s.homepage = 'https://github.com/h2ocube/h2ocube_rails_sunspot'
|
11
|
+
s.summary = %q{Easy way to use sunspot for rails}
|
12
|
+
s.description = %q{Easy way to use sunspot for rails}
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_dependency 'sunspot_rails'
|
21
|
+
s.add_dependency 'sunspot_solr'
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class H2ocubeRailsSunspotGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../source', __FILE__)
|
3
|
+
|
4
|
+
desc 'Creates config/sunspot.yml and spec/support/sunspot.rb.'
|
5
|
+
|
6
|
+
def copy_config_sunspot_rb
|
7
|
+
template 'sunspot.yml.erb', 'config/sunspot.yml'
|
8
|
+
end
|
9
|
+
|
10
|
+
def copy_spec_support_sunspot_yml
|
11
|
+
template 'sunspot.rb.erb', 'spec/support/sunspot.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def app_name
|
17
|
+
Rails.application.class.to_s.split('::').first.underscore
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'sunspot/rails'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
$original_sunspot_session = Sunspot.session
|
5
|
+
Sunspot.session = Sunspot::Rails::StubSessionProxy.new($original_sunspot_session)
|
6
|
+
|
7
|
+
module Sunspot
|
8
|
+
module Rails
|
9
|
+
module Searchable
|
10
|
+
module InstanceMethods
|
11
|
+
def solr_index
|
12
|
+
solr_index!
|
13
|
+
end
|
14
|
+
|
15
|
+
def solr_remove_from_index
|
16
|
+
solr_remove_from_index!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module SunspotTest
|
24
|
+
class TimeOutError < StandardError; end;
|
25
|
+
class << self
|
26
|
+
|
27
|
+
attr_writer :solr_startup_timeout
|
28
|
+
attr_writer :server
|
29
|
+
|
30
|
+
def solr_startup_timeout
|
31
|
+
@solr_startup_timeout || 15
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_solr
|
35
|
+
unstub
|
36
|
+
start_sunspot_server
|
37
|
+
end
|
38
|
+
|
39
|
+
def server
|
40
|
+
@server ||= Sunspot::Rails::Server.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def start_sunspot_server
|
44
|
+
unless solr_running?
|
45
|
+
pid = fork do
|
46
|
+
STDERR.reopen("/dev/null")
|
47
|
+
STDOUT.reopen("/dev/null")
|
48
|
+
server.run
|
49
|
+
end
|
50
|
+
|
51
|
+
at_exit { Process.kill("TERM", pid) }
|
52
|
+
|
53
|
+
wait_until_solr_starts
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Stubs Sunspot calls to Solr server
|
58
|
+
def stub
|
59
|
+
unless @session_stubbed
|
60
|
+
Sunspot.session = Sunspot::Rails::StubSessionProxy.new($original_sunspot_session)
|
61
|
+
@session_stubbed = true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Resets Sunspot to call Solr server, opposite of stub
|
66
|
+
def unstub
|
67
|
+
if @session_stubbed
|
68
|
+
Sunspot.session = Sunspot.session.original_session
|
69
|
+
@session_stubbed = false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def wait_until_solr_starts
|
75
|
+
(solr_startup_timeout * 10).times do
|
76
|
+
break if solr_running?
|
77
|
+
sleep(0.1)
|
78
|
+
end
|
79
|
+
raise TimeOutError, "Solr failed to start after #{solr_startup_timeout} seconds" unless solr_running?
|
80
|
+
end
|
81
|
+
|
82
|
+
def solr_running?
|
83
|
+
begin
|
84
|
+
solr_ping_uri = URI.parse("#{Sunspot.session.config.solr.url}/ping")
|
85
|
+
Net::HTTP.get(solr_ping_uri)
|
86
|
+
true # Solr Running
|
87
|
+
rescue
|
88
|
+
false # Solr Not Running
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
development:
|
2
|
+
solr:
|
3
|
+
hostname: localhost
|
4
|
+
port: 8982
|
5
|
+
test:
|
6
|
+
solr:
|
7
|
+
hostname: localhost
|
8
|
+
port: 8983
|
9
|
+
log_level: OFF
|
10
|
+
production:
|
11
|
+
solr:
|
12
|
+
hostname: localhost
|
13
|
+
port: 8983
|
14
|
+
log_level: WARNING
|
15
|
+
pid_path: /root/<%= app_name %>/shared/pids
|
16
|
+
data_path: /root/<%= app_name %>/shared/solr/data
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: h2ocube_rails_sunspot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sunspot_rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sunspot_solr
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Easy way to use sunspot for rails
|
42
|
+
email:
|
43
|
+
- ben@h2ocube.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- h2ocube_rails_sunspot.gemspec
|
53
|
+
- lib/generators/h2ocube_rails_sunspot_generator.rb
|
54
|
+
- lib/generators/source/sunspot.rb.erb
|
55
|
+
- lib/generators/source/sunspot.yml.erb
|
56
|
+
- lib/h2ocube_rails_sunspot.rb
|
57
|
+
homepage: https://github.com/h2ocube/h2ocube_rails_sunspot
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.1.11
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Easy way to use sunspot for rails
|
81
|
+
test_files: []
|