vinova_sunspot_mongoid 0.3.4

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jugyo
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,58 @@
1
+ sunspot_mongoid
2
+ ====
3
+
4
+ A Sunspot wrapper for Mongoid.
5
+
6
+ Install
7
+ ----
8
+
9
+ gem install sunspot_mongoid
10
+
11
+ Examples
12
+ ----
13
+
14
+ class Post
15
+ include Mongoid::Document
16
+ field :title
17
+
18
+ include Sunspot::Mongoid
19
+ searchable do
20
+ text :title
21
+ end
22
+ end
23
+
24
+ For Rails3
25
+ ----
26
+
27
+ ### as gem:
28
+
29
+ add a gem to Gemfile as following,
30
+
31
+ gem 'vinova_sunspot_mongoid', :require => 'sunspot_mongoid'
32
+
33
+ create config/initializers/sunspot_mongoid.rb,
34
+
35
+ Sunspot.session = Sunspot::Rails.build_session
36
+ ActionController::Base.module_eval { include(Sunspot::Rails::RequestLifecycle) }
37
+
38
+ ### as plugin:
39
+
40
+ add gems to Gemfile as following,
41
+
42
+ gem 'sunspot'
43
+ gem 'sunspot_rails'
44
+
45
+ and install sunspot_mongoid as rails plugin,
46
+
47
+ rails plugin install git://github.com/vinova/sunspot_mongoid.git
48
+
49
+ Links
50
+ ----
51
+
52
+ * [sunspot](http://github.com/outoftime/sunspot)
53
+ * [sunspot_rails](http://github.com/outoftime/sunspot/tree/master/sunspot_rails/)
54
+
55
+ Copyright
56
+ ----
57
+
58
+ Copyright (c) 2010 jugyo. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "vinova_sunspot_mongoid"
8
+ gem.summary = %Q{A Sunspot wrapper for Mongoid.}
9
+ gem.description = %Q{A Sunspot wrapper for Mongoid that is like sunspot_rails.}
10
+ gem.email = "jugyo.org@gmail.com"
11
+ gem.homepage = "http://github.com/jugyo/sunspot_mongoid"
12
+ gem.authors = ["jugyo"]
13
+ gem.add_runtime_dependency "mongoid", ">= 2.0.0.beta.15"
14
+ gem.add_runtime_dependency "sunspot", ">= 1.1.0"
15
+ gem.add_runtime_dependency "sunspot_rails", ">= 1.1.0"
16
+ gem.add_development_dependency "shoulda", ">= 0"
17
+ gem.add_development_dependency "rr", ">= 0"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/test_*.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "sunspot_mongoid #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.4
@@ -0,0 +1,36 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'sunspot_mongoid'
3
+
4
+ Mongoid.configure do |config|
5
+ config.master = Mongo::Connection.new.db('sunspot-mongoid-test')
6
+ end
7
+
8
+ # model
9
+ class Post
10
+ include Mongoid::Document
11
+ field :title
12
+
13
+ include Sunspot::Mongoid
14
+ searchable do
15
+ text :title
16
+ end
17
+ end
18
+
19
+ # remove old indexes
20
+ Post.destroy_all
21
+
22
+ # indexing
23
+ Post.create(:title => 'foo')
24
+ Post.create(:title => 'foo bar')
25
+ Post.create(:title => 'bar baz')
26
+
27
+ # commit
28
+ Sunspot.commit
29
+
30
+ # search
31
+ search = Post.search do
32
+ keywords 'foo'
33
+ end
34
+ search.each_hit_with_result do |hit, post|
35
+ p post
36
+ end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'sunspot_mongoid'
2
+ Sunspot.session = Sunspot::Rails.build_session
3
+ ActionController::Base.module_eval { include(Sunspot::Rails::RequestLifecycle) }
@@ -0,0 +1,51 @@
1
+ require 'sunspot'
2
+ require 'mongoid'
3
+ require 'sunspot/rails'
4
+
5
+ # == Examples:
6
+ #
7
+ # class Post
8
+ # include Mongoid::Document
9
+ # field :title
10
+ #
11
+ # include Sunspot::Mongoid
12
+ # searchable do
13
+ # text :title
14
+ # end
15
+ # end
16
+ #
17
+ module Sunspot
18
+ module Mongoid
19
+ def self.included(base)
20
+ base.class_eval do
21
+ extend Sunspot::Rails::Searchable::ActsAsMethods
22
+ Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
23
+ Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
24
+ end
25
+ end
26
+
27
+ class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
28
+ def id
29
+ @instance.id
30
+ end
31
+ end
32
+
33
+ class DataAccessor < Sunspot::Adapters::DataAccessor
34
+ def load(id)
35
+ @clazz.find(id) rescue nil
36
+ end
37
+
38
+ def load_all(ids)
39
+ bson_object_ids = []
40
+ ids.each do |id|
41
+ if BSON::ObjectID.legal?(id)
42
+ bson_object_ids << BSON::ObjectID(id)
43
+ end
44
+ end
45
+
46
+ # Find object using both id string and BSON::OBjectID initilized from id string
47
+ @clazz.where(:_id.in => bson_object_ids + ids )
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1 @@
1
+ require 'sunspot/mongoid'
data/test/helper.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'rr'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'sunspot_mongoid'
9
+
10
+ class Test::Unit::TestCase
11
+ include RR::Adapters::TestUnit
12
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ #
4
+ # NOTE: I think tests are too few...
5
+ #
6
+ class TestSunspotMongoid < Test::Unit::TestCase
7
+ class Foo
8
+ include Mongoid::Document
9
+ field :title
10
+
11
+ include Sunspot::Mongoid
12
+ searchable do
13
+ text :title
14
+ end
15
+ end
16
+
17
+ class Bar
18
+ include Mongoid::Document
19
+ field :title
20
+
21
+ include Sunspot::Mongoid
22
+ searchable(:auto_index => false, :auto_remove => false) do
23
+ text :title
24
+ end
25
+ end
26
+
27
+ context 'default' do
28
+ should 'sunspot_options is specified' do
29
+ assert Foo.sunspot_options == {:include => []}
30
+ assert Bar.sunspot_options == {:auto_index=>false, :auto_remove=>false, :include=>[]}
31
+ end
32
+
33
+ should 'be called Sunspot.setup when call Foo.searchable' do
34
+ mock(Sunspot).setup(Foo)
35
+ Foo.searchable
36
+ end
37
+
38
+ should 'get as text_fields from Sunspot::Setup' do
39
+ text_field = Sunspot::Setup.for(Foo).all_text_fields.first
40
+ assert text_field.type == Sunspot::Type::TextType.instance
41
+ assert text_field.name == :title
42
+ end
43
+
44
+ should 'search' do
45
+ options = {}
46
+ mock.proxy(Foo).solr_execute_search(options)
47
+ mock(Sunspot).new_search(Foo) { mock(Object.new).execute }
48
+ Foo.search(options)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{vinova_sunspot_mongoid}
8
+ s.version = "0.3.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jugyo"]
12
+ s.date = %q{2010-08-22}
13
+ s.description = %q{A Sunspot wrapper for Mongoid that is like sunspot_rails.}
14
+ s.email = %q{jugyo.org@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "examples/example.rb",
27
+ "init.rb",
28
+ "lib/sunspot/mongoid.rb",
29
+ "lib/sunspot_mongoid.rb",
30
+ "test/helper.rb",
31
+ "test/test_sunspot_mongoid.rb",
32
+ "vinova_sunspot_mongoid.gemspec"
33
+ ]
34
+ s.homepage = %q{http://github.com/jugyo/sunspot_mongoid}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{A Sunspot wrapper for Mongoid.}
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_sunspot_mongoid.rb",
42
+ "examples/example.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<mongoid>, [">= 2.0.0.beta.15"])
51
+ s.add_runtime_dependency(%q<sunspot>, [">= 1.1.0"])
52
+ s.add_runtime_dependency(%q<sunspot_rails>, [">= 1.1.0"])
53
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_development_dependency(%q<rr>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.15"])
57
+ s.add_dependency(%q<sunspot>, [">= 1.1.0"])
58
+ s.add_dependency(%q<sunspot_rails>, [">= 1.1.0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<rr>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.15"])
64
+ s.add_dependency(%q<sunspot>, [">= 1.1.0"])
65
+ s.add_dependency(%q<sunspot_rails>, [">= 1.1.0"])
66
+ s.add_dependency(%q<shoulda>, [">= 0"])
67
+ s.add_dependency(%q<rr>, [">= 0"])
68
+ end
69
+ end
70
+
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vinova_sunspot_mongoid
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 4
10
+ version: 0.3.4
11
+ platform: ruby
12
+ authors:
13
+ - jugyo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-22 00:00:00 +07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: mongoid
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 62196477
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ - beta
35
+ - 15
36
+ version: 2.0.0.beta.15
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: sunspot
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 19
48
+ segments:
49
+ - 1
50
+ - 1
51
+ - 0
52
+ version: 1.1.0
53
+ type: :runtime
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: sunspot_rails
57
+ prerelease: false
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 19
64
+ segments:
65
+ - 1
66
+ - 1
67
+ - 0
68
+ version: 1.1.0
69
+ type: :runtime
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ name: shoulda
73
+ prerelease: false
74
+ requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: rr
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ version_requirements: *id005
99
+ description: A Sunspot wrapper for Mongoid that is like sunspot_rails.
100
+ email: jugyo.org@gmail.com
101
+ executables: []
102
+
103
+ extensions: []
104
+
105
+ extra_rdoc_files:
106
+ - LICENSE
107
+ - README.md
108
+ files:
109
+ - .document
110
+ - .gitignore
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - VERSION
115
+ - examples/example.rb
116
+ - init.rb
117
+ - lib/sunspot/mongoid.rb
118
+ - lib/sunspot_mongoid.rb
119
+ - test/helper.rb
120
+ - test/test_sunspot_mongoid.rb
121
+ - vinova_sunspot_mongoid.gemspec
122
+ has_rdoc: true
123
+ homepage: http://github.com/jugyo/sunspot_mongoid
124
+ licenses: []
125
+
126
+ post_install_message:
127
+ rdoc_options:
128
+ - --charset=UTF-8
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ requirements: []
150
+
151
+ rubyforge_project:
152
+ rubygems_version: 1.3.7
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: A Sunspot wrapper for Mongoid.
156
+ test_files:
157
+ - test/helper.rb
158
+ - test/test_sunspot_mongoid.rb
159
+ - examples/example.rb