sunspot_padrino 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9afd03f8cd7b011bfe02a63f39779fa082ad253d
4
+ data.tar.gz: 8aec5a2fc5925f7e28f55a672b9809eb2223b5a5
5
+ SHA512:
6
+ metadata.gz: db929029d01de3f2f157509be0f55f2d7f906552ae1fad450045416587c65f157001cfced346a49e0fe08ad10ab9b224d48782a0fc40cdf54d42e23ec8423370
7
+ data.tar.gz: 31632484fe9f8c858d68b5da3d0bc0bd6b869fc80d56df895e395b790f4e42f0351f2545d4c1199537df04f1e3929485db2ead3aa1b9af7b82ff7d08c26f0c8a
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0.1"
13
+ gem "simplecov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.1.3)
9
+ docile (1.1.3)
10
+ faraday (0.9.0)
11
+ multipart-post (>= 1.2, < 3)
12
+ git (1.2.6)
13
+ github_api (0.11.3)
14
+ addressable (~> 2.3)
15
+ descendants_tracker (~> 0.0.1)
16
+ faraday (~> 0.8, < 0.10)
17
+ hashie (>= 1.2)
18
+ multi_json (>= 1.7.5, < 2.0)
19
+ nokogiri (~> 1.6.0)
20
+ oauth2
21
+ hashie (2.1.1)
22
+ highline (1.6.21)
23
+ jeweler (2.0.1)
24
+ builder
25
+ bundler (>= 1.0)
26
+ git (>= 1.2.5)
27
+ github_api
28
+ highline (>= 1.6.15)
29
+ nokogiri (>= 1.5.10)
30
+ rake
31
+ rdoc
32
+ json (1.8.1)
33
+ jwt (0.1.13)
34
+ multi_json (>= 1.5)
35
+ mini_portile (0.6.0)
36
+ multi_json (1.10.0)
37
+ multi_xml (0.5.5)
38
+ multipart-post (2.0.0)
39
+ nokogiri (1.6.2.1)
40
+ mini_portile (= 0.6.0)
41
+ oauth2 (0.9.3)
42
+ faraday (>= 0.8, < 0.10)
43
+ jwt (~> 0.1.8)
44
+ multi_json (~> 1.3)
45
+ multi_xml (~> 0.5)
46
+ rack (~> 1.2)
47
+ rack (1.5.2)
48
+ rake (10.3.2)
49
+ rdoc (3.12.2)
50
+ json (~> 1.4)
51
+ rspec (2.8.0)
52
+ rspec-core (~> 2.8.0)
53
+ rspec-expectations (~> 2.8.0)
54
+ rspec-mocks (~> 2.8.0)
55
+ rspec-core (2.8.0)
56
+ rspec-expectations (2.8.0)
57
+ diff-lcs (~> 1.1.2)
58
+ rspec-mocks (2.8.0)
59
+ simplecov (0.8.2)
60
+ docile (~> 1.1.0)
61
+ multi_json
62
+ simplecov-html (~> 0.8.0)
63
+ simplecov-html (0.8.0)
64
+ thread_safe (0.3.3)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 1.0)
71
+ jeweler (~> 2.0.1)
72
+ rdoc (~> 3.12)
73
+ rspec (~> 2.8.0)
74
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Jordan Yaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ = Sunspot::Padrino
2
+
3
+ Sunspot::Padrino is a derived plugin that provides drop-in integration of the
4
+ Sunspot[http://outoftime.github.com/sunspot] Solr search library with Padrino. It
5
+ is based on the original Sunspot::Rails library located at https://github.com/sunspot/sunspot.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "sunspot_padrino"
18
+ gem.homepage = "http://github.com/supportify/sunspot_padrino"
19
+ gem.license = "BSD"
20
+ gem.summary = %Q{Padrino integration for the Sunspot Solr search library}
21
+ gem.description = <<-TEXT
22
+ Sunspot::Padrino is a derived plugin that provides drop-in integration of the
23
+ Sunspot Solr search library with Padrino. It is based on the original Sunspot
24
+ ::Rails library located at https://github.com/sunspot/sunspot.
25
+ TEXT
26
+ gem.email = "help@supportify.io"
27
+ gem.authors = ["Jordan Yaker", "Supportify, Inc."]
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rspec/core'
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new(:spec) do |spec|
35
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ desc "Code coverage detail"
39
+ task :simplecov do
40
+ ENV['COVERAGE'] = "true"
41
+ Rake::Task['spec'].execute
42
+ end
43
+
44
+ task :default => :spec
45
+
46
+ require 'rdoc/task'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "sunspot_padrino #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,57 @@
1
+ module Padrino
2
+ module Generators
3
+ class SunspotGenerator < Thor::Group
4
+
5
+ Padrino::Generators.add_generator(:sunspot, self)
6
+
7
+ def self.source_root; File.expand_path(File.dirname(__FILE__)); end
8
+ def self.banner; "padrino-gen sunspot"; end
9
+
10
+ include Thor::Actions
11
+ include Padrino::Generators::Actions
12
+
13
+ desc "Description:\n\n\tpadrino-gen sunspot generates a default configuration for Sunspot"
14
+
15
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
16
+
17
+ ##
18
+ # Execute Sunspot config generation
19
+ #
20
+ def create_sunspot
21
+ return unless valid_config_for?
22
+
23
+ template 'templates/sunspot.yml', destination_root('config/sunspot.yml')
24
+ end
25
+
26
+ private
27
+
28
+ ##
29
+ # Validate model characteristics
30
+ # Alert if the configuration file already exists
31
+ #
32
+ def valid_config_for?
33
+ self.destination_root = options[:root]
34
+ return false unless correct_path?
35
+
36
+ return false if config_file_exists?
37
+
38
+ true
39
+ end
40
+
41
+ ##
42
+ # Check app path
43
+ #
44
+ def correct_path?
45
+ return true if in_app_root?
46
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
47
+ false
48
+ end
49
+
50
+ def config_file_exists?
51
+ return true unless File.exists? destination_root('config/sunspot.yml')
52
+ say 'An existing Sunspot configuration file was found!'
53
+ false
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,22 @@
1
+ production:
2
+ solr:
3
+ hostname: localhost
4
+ port: 8983
5
+ log_level: WARNING
6
+ path: /solr/production
7
+ read_timeout: 20
8
+ open_timeout: 1
9
+
10
+ development:
11
+ solr:
12
+ hostname: localhost
13
+ port: 8983
14
+ log_level: INFO
15
+ path: /solr/development
16
+
17
+ test:
18
+ solr:
19
+ hostname: localhost
20
+ port: 8983
21
+ log_level: WARNING
22
+ path: /solr/test
@@ -0,0 +1,73 @@
1
+ require 'sunspot'
2
+ require File.join(File.dirname(__FILE__), 'padrino', 'configuration')
3
+ require File.join(File.dirname(__FILE__), 'padrino', 'adapters')
4
+ require File.join(File.dirname(__FILE__), 'padrino', 'request_lifecycle')
5
+ require File.join(File.dirname(__FILE__), 'padrino', 'searchable')
6
+
7
+ module Sunspot #:nodoc:
8
+ module Padrino #:nodoc:
9
+ autoload :SolrInstrumentation, File.join(File.dirname(__FILE__), 'padrino', 'solr_instrumentation')
10
+ autoload :StubSessionProxy, File.join(File.dirname(__FILE__), 'padrino', 'stub_session_proxy')
11
+ begin
12
+ require 'sunspot_solr'
13
+ autoload :Server, File.join(File.dirname(__FILE__), 'padrino', 'server')
14
+ rescue LoadError
15
+ # We're fine
16
+ end
17
+
18
+ class <<self
19
+ attr_writer :configuration
20
+
21
+ def configuration
22
+ @configuration ||= Sunspot::Padrino::Configuration.new
23
+ end
24
+
25
+ def reset
26
+ @configuration = nil
27
+ end
28
+
29
+ def build_session(configuration = self.configuration)
30
+ if configuration.disabled?
31
+ StubSessionProxy.new(Sunspot.session)
32
+ elsif configuration.has_master?
33
+ SessionProxy::MasterSlaveSessionProxy.new(
34
+ SessionProxy::ThreadLocalSessionProxy.new(master_config(configuration)),
35
+ SessionProxy::ThreadLocalSessionProxy.new(slave_config(configuration))
36
+ )
37
+ else
38
+ SessionProxy::ThreadLocalSessionProxy.new(slave_config(configuration))
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def master_config(sunspot_padrino_configuration)
45
+ config = Sunspot::Configuration.build
46
+ builder = sunspot_padrino_configuration.scheme == 'http' ? URI::HTTP : URI::HTTPS
47
+ config.solr.url = builder.build(
48
+ :host => sunspot_padrino_configuration.master_hostname,
49
+ :port => sunspot_padrino_configuration.master_port,
50
+ :path => sunspot_padrino_configuration.master_path,
51
+ :userinfo => sunspot_padrino_configuration.userinfo
52
+ ).to_s
53
+ config.solr.read_timeout = sunspot_padrino_configuration.read_timeout
54
+ config.solr.open_timeout = sunspot_padrino_configuration.open_timeout
55
+ config
56
+ end
57
+
58
+ def slave_config(sunspot_padrino_configuration)
59
+ config = Sunspot::Configuration.build
60
+ builder = sunspot_padrino_configuration.scheme == 'http' ? URI::HTTP : URI::HTTPS
61
+ config.solr.url = builder.build(
62
+ :host => sunspot_padrino_configuration.hostname,
63
+ :port => sunspot_padrino_configuration.port,
64
+ :path => sunspot_padrino_configuration.path,
65
+ :userinfo => sunspot_padrino_configuration.userinfo
66
+ ).to_s
67
+ config.solr.read_timeout = sunspot_padrino_configuration.read_timeout
68
+ config.solr.open_timeout = sunspot_padrino_configuration.open_timeout
69
+ config
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,90 @@
1
+ module Sunspot #:nodoc:
2
+ module Padrino #:nodoc:
3
+ #
4
+ # This module provides Sunspot Adapter implementations for ActiveRecord
5
+ # models.
6
+ #
7
+ module Adapters
8
+ class ActiveRecordInstanceAdapter < Sunspot::Adapters::InstanceAdapter
9
+ #
10
+ # Return the primary key for the adapted instance
11
+ #
12
+ # ==== Returns
13
+ #
14
+ # Integer:: Database ID of model
15
+ #
16
+ def id
17
+ @instance.id
18
+ end
19
+ end
20
+
21
+ class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
22
+ # options for the find
23
+ attr_accessor :include
24
+ attr_reader :select
25
+
26
+ def initialize(clazz)
27
+ super(clazz)
28
+ @inherited_attributes = [:include, :select]
29
+ end
30
+
31
+ #
32
+ # Set the fields to select from the database. This will be passed
33
+ # to ActiveRecord.
34
+ #
35
+ # ==== Parameters
36
+ #
37
+ # value<Mixed>:: String of comma-separated columns or array of columns
38
+ #
39
+ def select=(value)
40
+ value = value.join(', ') if value.respond_to?(:join)
41
+ @select = value
42
+ end
43
+
44
+ #
45
+ # Get one ActiveRecord instance out of the database by ID
46
+ #
47
+ # ==== Parameters
48
+ #
49
+ # id<String>:: Database ID of model to retreive
50
+ #
51
+ # ==== Returns
52
+ #
53
+ # ActiveRecord::Base:: ActiveRecord model
54
+ #
55
+ def load(id)
56
+ @clazz.where(@clazz.primary_key => id).merge(scope_for_load).first
57
+ end
58
+
59
+ #
60
+ # Get a collection of ActiveRecord instances out of the database by ID
61
+ #
62
+ # ==== Parameters
63
+ #
64
+ # ids<Array>:: Database IDs of models to retrieve
65
+ #
66
+ # ==== Returns
67
+ #
68
+ # Array:: Collection of ActiveRecord models
69
+ #
70
+ def load_all(ids)
71
+ @clazz.where(@clazz.primary_key => ids).merge(scope_for_load)
72
+ end
73
+
74
+ private
75
+
76
+ def scope_for_load
77
+ scope = relation
78
+ scope = scope.includes(@include) if @include.present?
79
+ scope = scope.select(@select) if @select.present?
80
+ scope
81
+ end
82
+
83
+ # COMPATIBILITY: Padrino 4 has deprecated the 'scoped' method in favour of 'all'
84
+ def relation
85
+ @clazz.all
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end