sherpa99-thinking-sphinx 1.1.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/LICENCE +20 -0
- data/README +107 -0
- data/README.textile +107 -0
- data/Rakefile +4 -0
- data/contribute.rb +328 -0
- data/cucumber.yml +1 -0
- data/features/a.rb +17 -0
- data/features/attribute_transformation.feature +22 -0
- data/features/datetime_deltas.feature +55 -0
- data/features/delayed_delta_indexing.feature +37 -0
- data/features/deleting_instances.feature +52 -0
- data/features/facets.feature +26 -0
- data/features/handling_edits.feature +67 -0
- data/features/retry_stale_indexes.feature +24 -0
- data/features/searching_across_models.feature +20 -0
- data/features/searching_by_model.feature +118 -0
- data/features/searching_with_find_arguments.feature +56 -0
- data/features/sphinx_detection.feature +16 -0
- data/features/step_definitions/alpha_steps.rb +3 -0
- data/features/step_definitions/beta_steps.rb +11 -0
- data/features/step_definitions/cat_steps.rb +3 -0
- data/features/step_definitions/common_steps.rb +154 -0
- data/features/step_definitions/datetime_delta_steps.rb +11 -0
- data/features/step_definitions/delayed_delta_indexing_steps.rb +7 -0
- data/features/step_definitions/facet_steps.rb +30 -0
- data/features/step_definitions/find_arguments_steps.rb +36 -0
- data/features/step_definitions/gamma_steps.rb +15 -0
- data/features/step_definitions/search_steps.rb +66 -0
- data/features/step_definitions/sphinx_steps.rb +23 -0
- data/features/support/db/active_record.rb +40 -0
- data/features/support/db/database.example.yml +4 -0
- data/features/support/db/migrations/create_alphas.rb +18 -0
- data/features/support/db/migrations/create_animals.rb +9 -0
- data/features/support/db/migrations/create_betas.rb +15 -0
- data/features/support/db/migrations/create_boxes.rb +13 -0
- data/features/support/db/migrations/create_comments.rb +13 -0
- data/features/support/db/migrations/create_delayed_betas.rb +28 -0
- data/features/support/db/migrations/create_developers.rb +39 -0
- data/features/support/db/migrations/create_gammas.rb +14 -0
- data/features/support/db/migrations/create_people.rb +1014 -0
- data/features/support/db/migrations/create_posts.rb +6 -0
- data/features/support/db/migrations/create_thetas.rb +16 -0
- data/features/support/db/mysql.rb +4 -0
- data/features/support/db/postgresql.rb +4 -0
- data/features/support/env.rb +6 -0
- data/features/support/models/alpha.rb +9 -0
- data/features/support/models/animal.rb +5 -0
- data/features/support/models/beta.rb +7 -0
- data/features/support/models/box.rb +8 -0
- data/features/support/models/cat.rb +3 -0
- data/features/support/models/comment.rb +3 -0
- data/features/support/models/delayed_beta.rb +7 -0
- data/features/support/models/developer.rb +8 -0
- data/features/support/models/gamma.rb +5 -0
- data/features/support/models/person.rb +8 -0
- data/features/support/models/post.rb +8 -0
- data/features/support/models/theta.rb +7 -0
- data/features/support/post_database.rb +37 -0
- data/features/support/z.rb +19 -0
- data/ginger_scenarios.rb +24 -0
- data/init.rb +12 -0
- data/lib/thinking_sphinx.rb +144 -0
- data/lib/thinking_sphinx/active_record.rb +245 -0
- data/lib/thinking_sphinx/active_record/delta.rb +74 -0
- data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
- data/lib/thinking_sphinx/active_record/search.rb +57 -0
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +34 -0
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +53 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +129 -0
- data/lib/thinking_sphinx/association.rb +144 -0
- data/lib/thinking_sphinx/attribute.rb +258 -0
- data/lib/thinking_sphinx/collection.rb +142 -0
- data/lib/thinking_sphinx/configuration.rb +236 -0
- data/lib/thinking_sphinx/core/string.rb +22 -0
- data/lib/thinking_sphinx/deltas.rb +22 -0
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +65 -0
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +25 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
- data/lib/thinking_sphinx/facet.rb +58 -0
- data/lib/thinking_sphinx/facet_collection.rb +44 -0
- data/lib/thinking_sphinx/field.rb +172 -0
- data/lib/thinking_sphinx/index.rb +414 -0
- data/lib/thinking_sphinx/index/builder.rb +233 -0
- data/lib/thinking_sphinx/index/faux_column.rb +110 -0
- data/lib/thinking_sphinx/rails_additions.rb +133 -0
- data/lib/thinking_sphinx/search.rb +638 -0
- data/lib/thinking_sphinx/tasks.rb +128 -0
- data/rails/init.rb +6 -0
- data/spec/fixtures/data.sql +32 -0
- data/spec/fixtures/database.yml.default +3 -0
- data/spec/fixtures/models.rb +81 -0
- data/spec/fixtures/structure.sql +84 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/sphinx_helper.rb +109 -0
- data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +136 -0
- data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +53 -0
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +107 -0
- data/spec/unit/thinking_sphinx/active_record_spec.rb +256 -0
- data/spec/unit/thinking_sphinx/association_spec.rb +247 -0
- data/spec/unit/thinking_sphinx/attribute_spec.rb +212 -0
- data/spec/unit/thinking_sphinx/collection_spec.rb +14 -0
- data/spec/unit/thinking_sphinx/configuration_spec.rb +136 -0
- data/spec/unit/thinking_sphinx/core/string_spec.rb +9 -0
- data/spec/unit/thinking_sphinx/field_spec.rb +145 -0
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +5 -0
- data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +30 -0
- data/spec/unit/thinking_sphinx/index_spec.rb +54 -0
- data/spec/unit/thinking_sphinx/search_spec.rb +59 -0
- data/spec/unit/thinking_sphinx_spec.rb +129 -0
- data/tasks/distribution.rb +48 -0
- data/tasks/rails.rake +1 -0
- data/tasks/testing.rb +86 -0
- data/thinking-sphinx.gemspec +232 -0
- data/vendor/after_commit/LICENSE +20 -0
- data/vendor/after_commit/README +16 -0
- data/vendor/after_commit/Rakefile +22 -0
- data/vendor/after_commit/init.rb +5 -0
- data/vendor/after_commit/lib/after_commit.rb +42 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +91 -0
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
- data/vendor/after_commit/test/after_commit_test.rb +53 -0
- data/vendor/delayed_job/lib/delayed/job.rb +251 -0
- data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
- data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
- data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
- data/vendor/riddle/lib/riddle.rb +30 -0
- data/vendor/riddle/lib/riddle/client.rb +619 -0
- data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
- data/vendor/riddle/lib/riddle/client/message.rb +65 -0
- data/vendor/riddle/lib/riddle/client/response.rb +84 -0
- data/vendor/riddle/lib/riddle/configuration.rb +33 -0
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
- data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +37 -0
- data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
- data/vendor/riddle/lib/riddle/controller.rb +44 -0
- metadata +248 -0
data/LICENCE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Pat Allan
|
|
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
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
= Thinking Sphinx
|
|
2
|
+
|
|
3
|
+
== Usage
|
|
4
|
+
|
|
5
|
+
First, if you haven't done so already, check out the main usage[http://ts.freelancing-gods.com/usage.html] page. Once you've done that, the next place to look for information is the specific method docs - ThinkingSphinx::Search and ThinkingSphinx::Index::Builder in particular.
|
|
6
|
+
|
|
7
|
+
Keep in mind that while Thinking Sphinx works for ActiveRecord with Merb, it doesn't yet support DataMapper (although that is planned).
|
|
8
|
+
|
|
9
|
+
== Contributing
|
|
10
|
+
|
|
11
|
+
Fork on GitHub and after you've committed tested patches, send a pull request.
|
|
12
|
+
|
|
13
|
+
To get the spec suite running, you will need to install the not-a-mock gem if you don't already have it:
|
|
14
|
+
|
|
15
|
+
git clone git://github.com/freelancing-god/not-a-mock.git
|
|
16
|
+
cd not-a-mock
|
|
17
|
+
rake gem
|
|
18
|
+
gem install pkg/not_a_mock-1.1.0.gem
|
|
19
|
+
|
|
20
|
+
Then install the ginger gem. The steps are the same, except that you might need to sudo the gem install:
|
|
21
|
+
|
|
22
|
+
git clone git://github.com/freelancing-god/ginger.git
|
|
23
|
+
cd ginger
|
|
24
|
+
rake gem
|
|
25
|
+
sudo gem install pkg/ginger-1.1.0.gem
|
|
26
|
+
|
|
27
|
+
Then set up your database:
|
|
28
|
+
|
|
29
|
+
cp spec/fixtures/database.yml.default spec/fixtures/database.yml
|
|
30
|
+
mysqladmin -u root create thinking_sphinx
|
|
31
|
+
|
|
32
|
+
Make sure you don't have another Sphinx daemon (searchd) running. If you do, quit it with "rake ts:stop"
|
|
33
|
+
in the app root.
|
|
34
|
+
|
|
35
|
+
You should now have a passing test suite from which to build your patch on.
|
|
36
|
+
|
|
37
|
+
rake spec
|
|
38
|
+
|
|
39
|
+
If you get the message "Failed to start searchd daemon", run the spec with sudo:
|
|
40
|
+
|
|
41
|
+
sudo rake spec
|
|
42
|
+
|
|
43
|
+
If you quit the spec suite before it's completed, you may be left with data in the test
|
|
44
|
+
database, causing the next run to have failures. Let that run complete and then try again.
|
|
45
|
+
|
|
46
|
+
== Contributors
|
|
47
|
+
|
|
48
|
+
Since I first released this library, there's been quite a few people who have submitted patches, to my immense gratitude. Others have suggested syntax changes and general improvements. So my thanks to the following people:
|
|
49
|
+
|
|
50
|
+
- Joost Hietbrink
|
|
51
|
+
- Jonathan Conway
|
|
52
|
+
- Gregory Mirzayantz
|
|
53
|
+
- Tung Nguyen
|
|
54
|
+
- Sean Cribbs
|
|
55
|
+
- Benoit Caccinolo
|
|
56
|
+
- John Barton
|
|
57
|
+
- Oliver Beddows
|
|
58
|
+
- Arthur Zapparoli
|
|
59
|
+
- Dusty Doris
|
|
60
|
+
- Marcus Crafter
|
|
61
|
+
- Patrick Lenz
|
|
62
|
+
- Björn Andreasson
|
|
63
|
+
- James Healy
|
|
64
|
+
- Jae-Jun Hwang
|
|
65
|
+
- Xavier Shay
|
|
66
|
+
- Jason Rust
|
|
67
|
+
- Gopal Patel
|
|
68
|
+
- Chris Heald
|
|
69
|
+
- Peter Vandenberk
|
|
70
|
+
- Josh French
|
|
71
|
+
- Andrew Bennett
|
|
72
|
+
- Jordan Fowler
|
|
73
|
+
- Seth Walker
|
|
74
|
+
- Joe Noon
|
|
75
|
+
- Wolfgang Postler
|
|
76
|
+
- Rick Olson
|
|
77
|
+
- Killian Murphy
|
|
78
|
+
- Morten Primdahl
|
|
79
|
+
- Ryan Bates
|
|
80
|
+
- David Eisinger
|
|
81
|
+
- Shay Arnett
|
|
82
|
+
- Minh Tran
|
|
83
|
+
- Jeremy Durham
|
|
84
|
+
- Piotr Sarnacki
|
|
85
|
+
- Matt Johnson
|
|
86
|
+
- Nicolas Blanco
|
|
87
|
+
- Max Lapshin
|
|
88
|
+
- Josh Natanson
|
|
89
|
+
- Philip Hallstrom
|
|
90
|
+
- Christian Rishøj
|
|
91
|
+
- Mike Flester
|
|
92
|
+
- Jim Remsik
|
|
93
|
+
- Kennon Ballou
|
|
94
|
+
- Henrik Nyh
|
|
95
|
+
- Emil Tin
|
|
96
|
+
- Doug Cole
|
|
97
|
+
- Ed Hickey
|
|
98
|
+
- Evan Weaver
|
|
99
|
+
- Thibaut Barrere
|
|
100
|
+
- Kristopher Chambers
|
|
101
|
+
- Dmitrij Smalko
|
|
102
|
+
- Aleksey Yeschenko
|
|
103
|
+
- Lachie Cox
|
|
104
|
+
- Lourens Naude
|
|
105
|
+
- Tom Davies
|
|
106
|
+
- Dan Pickett
|
|
107
|
+
- Alex Caudill
|
data/README.textile
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
h1. Thinking Sphinx
|
|
2
|
+
|
|
3
|
+
h2. Usage
|
|
4
|
+
|
|
5
|
+
First, if you haven't done so already, check out the main "usage":http://ts.freelancing-gods.com/usage.html page. Once you've done that, the next place to look for information is the specific method docs - ThinkingSphinx::Search and ThinkingSphinx::Index::Builder in particular.
|
|
6
|
+
|
|
7
|
+
Keep in mind that while Thinking Sphinx works for ActiveRecord with Merb, it doesn't yet support DataMapper (although that is planned).
|
|
8
|
+
|
|
9
|
+
h2. Contributing
|
|
10
|
+
|
|
11
|
+
Fork on GitHub and after you've committed tested patches, send a pull request.
|
|
12
|
+
|
|
13
|
+
To get the spec suite running, you will need to install the not-a-mock gem if you don't already have it:
|
|
14
|
+
|
|
15
|
+
git clone git://github.com/freelancing-god/not-a-mock.git
|
|
16
|
+
cd not-a-mock
|
|
17
|
+
rake gem
|
|
18
|
+
gem install pkg/not_a_mock-1.1.0.gem
|
|
19
|
+
|
|
20
|
+
Then install the ginger gem. The steps are the same, except that you might need to sudo the gem install:
|
|
21
|
+
|
|
22
|
+
git clone git://github.com/freelancing-god/ginger.git
|
|
23
|
+
cd ginger
|
|
24
|
+
rake gem
|
|
25
|
+
sudo gem install pkg/ginger-1.1.0.gem
|
|
26
|
+
|
|
27
|
+
Then set up your database:
|
|
28
|
+
|
|
29
|
+
cp spec/fixtures/database.yml.default spec/fixtures/database.yml
|
|
30
|
+
mysqladmin -u root create thinking_sphinx
|
|
31
|
+
|
|
32
|
+
Make sure you don't have another Sphinx daemon (searchd) running. If you do, quit it with "rake ts:stop"
|
|
33
|
+
in the app root.
|
|
34
|
+
|
|
35
|
+
You should now have a passing test suite from which to build your patch on.
|
|
36
|
+
|
|
37
|
+
rake spec
|
|
38
|
+
|
|
39
|
+
If you get the message "Failed to start searchd daemon", run the spec with sudo:
|
|
40
|
+
|
|
41
|
+
sudo rake spec
|
|
42
|
+
|
|
43
|
+
If you quit the spec suite before it's completed, you may be left with data in the test
|
|
44
|
+
database, causing the next run to have failures. Let that run complete and then try again.
|
|
45
|
+
|
|
46
|
+
h2. Contributors
|
|
47
|
+
|
|
48
|
+
Since I first released this library, there's been quite a few people who have submitted patches, to my immense gratitude. Others have suggested syntax changes and general improvements. So my thanks to the following people:
|
|
49
|
+
|
|
50
|
+
* Joost Hietbrink
|
|
51
|
+
* Jonathan Conway
|
|
52
|
+
* Gregory Mirzayantz
|
|
53
|
+
* Tung Nguyen
|
|
54
|
+
* Sean Cribbs
|
|
55
|
+
* Benoit Caccinolo
|
|
56
|
+
* John Barton
|
|
57
|
+
* Oliver Beddows
|
|
58
|
+
* Arthur Zapparoli
|
|
59
|
+
* Dusty Doris
|
|
60
|
+
* Marcus Crafter
|
|
61
|
+
* Patrick Lenz
|
|
62
|
+
* Björn Andreasson
|
|
63
|
+
* James Healy
|
|
64
|
+
* Jae-Jun Hwang
|
|
65
|
+
* Xavier Shay
|
|
66
|
+
* Jason Rust
|
|
67
|
+
* Gopal Patel
|
|
68
|
+
* Chris Heald
|
|
69
|
+
* Peter Vandenberk
|
|
70
|
+
* Josh French
|
|
71
|
+
* Andrew Bennett
|
|
72
|
+
* Jordan Fowler
|
|
73
|
+
* Seth Walker
|
|
74
|
+
* Joe Noon
|
|
75
|
+
* Wolfgang Postler
|
|
76
|
+
* Rick Olson
|
|
77
|
+
* Killian Murphy
|
|
78
|
+
* Morten Primdahl
|
|
79
|
+
* Ryan Bates
|
|
80
|
+
* David Eisinger
|
|
81
|
+
* Shay Arnett
|
|
82
|
+
* Minh Tran
|
|
83
|
+
* Jeremy Durham
|
|
84
|
+
* Piotr Sarnacki
|
|
85
|
+
* Matt Johnson
|
|
86
|
+
* Nicolas Blanco
|
|
87
|
+
* Max Lapshin
|
|
88
|
+
* Josh Natanson
|
|
89
|
+
* Philip Hallstrom
|
|
90
|
+
* Christian Rishøj
|
|
91
|
+
* Mike Flester
|
|
92
|
+
* Jim Remsik
|
|
93
|
+
* Kennon Ballou
|
|
94
|
+
* Henrik Nyh
|
|
95
|
+
* Emil Tin
|
|
96
|
+
* Doug Cole
|
|
97
|
+
* Ed Hickey
|
|
98
|
+
* Evan Weaver
|
|
99
|
+
* Thibaut Barrere
|
|
100
|
+
* Kristopher Chambers
|
|
101
|
+
* Dmitrij Smalko
|
|
102
|
+
* Aleksey Yeschenko
|
|
103
|
+
* Lachie Cox
|
|
104
|
+
* Lourens Naude
|
|
105
|
+
* Tom Davies
|
|
106
|
+
* Dan Pickett
|
|
107
|
+
* Alex Caudill
|
data/Rakefile
ADDED
data/contribute.rb
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'pp'
|
|
6
|
+
|
|
7
|
+
module ContributeHelper; end
|
|
8
|
+
|
|
9
|
+
class Contribute
|
|
10
|
+
include ContributeHelper
|
|
11
|
+
|
|
12
|
+
def dependencies
|
|
13
|
+
[
|
|
14
|
+
Dependencies::Sphinx,
|
|
15
|
+
Dependencies::Mysql,
|
|
16
|
+
Dependencies::AR,
|
|
17
|
+
Dependencies::Ginger
|
|
18
|
+
]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def show
|
|
22
|
+
show_welcome_screen
|
|
23
|
+
|
|
24
|
+
(
|
|
25
|
+
check_for_dependencies &&
|
|
26
|
+
create_database_yaml &&
|
|
27
|
+
check_mysql_is_working &&
|
|
28
|
+
create_test_database
|
|
29
|
+
) || exit(1)
|
|
30
|
+
|
|
31
|
+
show_done_screen
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
WELCOME_SCREEN = <<-EO_WELCOME
|
|
36
|
+
<banner>Thinking Sphinx Contribution</banner>
|
|
37
|
+
|
|
38
|
+
Thanks for contributing to Thinking Sphinx.
|
|
39
|
+
|
|
40
|
+
In this script we'll help you get setup to hack:
|
|
41
|
+
|
|
42
|
+
<b>1.</b> We'll check that you have the right software installed and running.
|
|
43
|
+
<b>2.</b> We'll set up the test database for specs to run against.
|
|
44
|
+
|
|
45
|
+
EO_WELCOME
|
|
46
|
+
|
|
47
|
+
DONE_SCREEN = <<-EO_DONE
|
|
48
|
+
<banner>Setup done!</banner>
|
|
49
|
+
|
|
50
|
+
All done! Now you can start hacking by running
|
|
51
|
+
|
|
52
|
+
<b>rake spec</b>
|
|
53
|
+
|
|
54
|
+
EO_DONE
|
|
55
|
+
|
|
56
|
+
REVIEW_YAML = <<-EO_REVIEW_YAML
|
|
57
|
+
|
|
58
|
+
Please review the database details in the yaml file details before continuing.
|
|
59
|
+
|
|
60
|
+
This file is used by the specs to connect to the database.
|
|
61
|
+
|
|
62
|
+
Current details:
|
|
63
|
+
EO_REVIEW_YAML
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
MYSQL_FAILED = <<-EO_MYSQL_FAILED
|
|
68
|
+
|
|
69
|
+
Looks like we couldn't successfully talk to the mysql database.
|
|
70
|
+
|
|
71
|
+
Don't worry though...
|
|
72
|
+
|
|
73
|
+
EO_MYSQL_FAILED
|
|
74
|
+
|
|
75
|
+
CREATE_DATABASE_FAILED = <<-EO_CREATE_DATABASE_FAILED
|
|
76
|
+
|
|
77
|
+
Looks like we couldn't create a test database to work against.
|
|
78
|
+
|
|
79
|
+
Don't worry though...
|
|
80
|
+
|
|
81
|
+
EO_CREATE_DATABASE_FAILED
|
|
82
|
+
|
|
83
|
+
def show_welcome_screen
|
|
84
|
+
colour_puts WELCOME_SCREEN
|
|
85
|
+
wait!
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def show_done_screen
|
|
89
|
+
colour_puts DONE_SCREEN
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# create database.yml
|
|
93
|
+
def create_database_yaml
|
|
94
|
+
colour_puts "<banner>creating database yaml</banner>"
|
|
95
|
+
puts
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
config = {
|
|
99
|
+
'username' => 'root',
|
|
100
|
+
'password' => nil,
|
|
101
|
+
'host' => 'localhost'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
colour_print " * <b>#{db_yml}</b>... "
|
|
106
|
+
unless File.exist?(db_yml)
|
|
107
|
+
open(db_yml,'w') {|f| f << config.to_yaml}
|
|
108
|
+
colour_puts "<green>created</green>"
|
|
109
|
+
else
|
|
110
|
+
config = YAML.load_file(db_yml)
|
|
111
|
+
colour_puts "<green>already exists</green>"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
colour_puts REVIEW_YAML
|
|
115
|
+
|
|
116
|
+
config.each do |(k,v)|
|
|
117
|
+
colour_puts " * <b>#{k}</b>: #{v}"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
puts
|
|
121
|
+
|
|
122
|
+
wait!
|
|
123
|
+
true
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def check_mysql_is_working
|
|
127
|
+
require 'activerecord'
|
|
128
|
+
colour_puts "<banner>check mysql is working</banner>"
|
|
129
|
+
puts
|
|
130
|
+
|
|
131
|
+
connect_to_db
|
|
132
|
+
|
|
133
|
+
print " * connecting to mysql... "
|
|
134
|
+
|
|
135
|
+
begin
|
|
136
|
+
ActiveRecord::Base.connection.select_value('select sysdate() from dual')
|
|
137
|
+
|
|
138
|
+
colour_puts "<green>successful</green>"
|
|
139
|
+
puts
|
|
140
|
+
|
|
141
|
+
return true
|
|
142
|
+
rescue Mysql::Error
|
|
143
|
+
colour_puts "<red>failed</red>"
|
|
144
|
+
|
|
145
|
+
puts MYSQL_FAILED
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
false
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# create test db
|
|
152
|
+
def create_test_database
|
|
153
|
+
colour_puts "<banner>create test database</banner>"
|
|
154
|
+
puts
|
|
155
|
+
|
|
156
|
+
connect_to_db
|
|
157
|
+
|
|
158
|
+
colour_print " * <b>creating thinking_sphinx database</b>... "
|
|
159
|
+
begin
|
|
160
|
+
ActiveRecord::Base.connection.create_database('thinking_sphinx')
|
|
161
|
+
colour_puts "<green>successful</green>"
|
|
162
|
+
rescue ActiveRecord::StatementInvalid
|
|
163
|
+
if $!.message[/database exists/]
|
|
164
|
+
colour_puts "<green>successful</green> (database already existed)"
|
|
165
|
+
puts
|
|
166
|
+
return true
|
|
167
|
+
else
|
|
168
|
+
colour_puts "<red>failed</red>"
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
colour_puts CREATE_DATABASE_FAILED
|
|
173
|
+
|
|
174
|
+
false
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# project
|
|
178
|
+
def ts_root
|
|
179
|
+
File.expand_path(File.dirname(__FILE__))
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def specs
|
|
183
|
+
ts_root / 'spec'
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def db_yml
|
|
187
|
+
specs / 'fixtures' / 'database.yml'
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def connect_to_db
|
|
191
|
+
config = YAML.load_file(db_yml)
|
|
192
|
+
config.update(:adapter => 'mysql', :database => 'test')
|
|
193
|
+
config.symbolize_keys!
|
|
194
|
+
|
|
195
|
+
ActiveRecord::Base.establish_connection(config)
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class String
|
|
206
|
+
def /(other)
|
|
207
|
+
"#{self}/#{other}"
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
module ContributeHelper
|
|
212
|
+
class Dependency
|
|
213
|
+
def self.name(name=nil)
|
|
214
|
+
if name then @name = name else @name end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
attr_reader :location
|
|
218
|
+
|
|
219
|
+
def initialize
|
|
220
|
+
@found = false
|
|
221
|
+
@location = nil
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def name; self.class.name end
|
|
225
|
+
|
|
226
|
+
def check; false end
|
|
227
|
+
def check!
|
|
228
|
+
@found = check
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def found?
|
|
232
|
+
@found
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
class Gem < Dependency
|
|
237
|
+
def gem_name; self.class.name end
|
|
238
|
+
def name; "#{super} gem" end
|
|
239
|
+
|
|
240
|
+
def check
|
|
241
|
+
::Gem.available? self.gem_name
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def check_for_dependencies
|
|
247
|
+
colour_puts "<banner>Checking for required software</banner>"
|
|
248
|
+
puts
|
|
249
|
+
|
|
250
|
+
all_found = true
|
|
251
|
+
|
|
252
|
+
dependencies.each do |klass|
|
|
253
|
+
dep = klass.new
|
|
254
|
+
print " * #{dep.name}... "
|
|
255
|
+
dep.check!
|
|
256
|
+
|
|
257
|
+
if dep.found?
|
|
258
|
+
if dep.location
|
|
259
|
+
colour_puts "<green>found at #{dep.location}</green>"
|
|
260
|
+
else
|
|
261
|
+
colour_puts "<green>found</green>"
|
|
262
|
+
end
|
|
263
|
+
else
|
|
264
|
+
all_found &= false
|
|
265
|
+
colour_puts "<red>not found</red>"
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
puts
|
|
270
|
+
|
|
271
|
+
all_found
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
DEFAULT_TERMINAL_COLORS = "\e[0m\e[37m\e[40m"
|
|
277
|
+
def subs_colour(data)
|
|
278
|
+
data = data.gsub(%r{<b>(.*?)</b>}m, "\e[1m\\1#{DEFAULT_TERMINAL_COLORS}")
|
|
279
|
+
data.gsub!(%r{<red>(.*?)</red>}m, "\e[1m\e[31m\\1#{DEFAULT_TERMINAL_COLORS}")
|
|
280
|
+
data.gsub!(%r{<green>(.*?)</green>}m, "\e[1m\e[32m\\1#{DEFAULT_TERMINAL_COLORS}")
|
|
281
|
+
data.gsub!(%r{<yellow>(.*?)</yellow>}m, "\e[1m\e[33m\\1#{DEFAULT_TERMINAL_COLORS}")
|
|
282
|
+
data.gsub!(%r{<banner>(.*?)</banner>}m, "\e[33m\e[44m\e[1m\\1#{DEFAULT_TERMINAL_COLORS}")
|
|
283
|
+
|
|
284
|
+
return data
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def colour_puts(text)
|
|
288
|
+
puts subs_colour(text)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def colour_print(text)
|
|
292
|
+
print subs_colour(text)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def wait!
|
|
297
|
+
colour_puts "<b>Hit Enter to continue, or Ctrl-C to quit.</b>"
|
|
298
|
+
STDIN.readline
|
|
299
|
+
rescue Interrupt
|
|
300
|
+
exit!
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
module Dependencies
|
|
305
|
+
class Mysql < ContributeHelper::Gem
|
|
306
|
+
name 'mysql'
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
class AR < ContributeHelper::Gem
|
|
310
|
+
name 'activerecord'
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
class Ginger < ContributeHelper::Gem
|
|
314
|
+
name 'ginger'
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
class Sphinx < ContributeHelper::Dependency
|
|
318
|
+
name 'sphinx'
|
|
319
|
+
|
|
320
|
+
def check
|
|
321
|
+
output = `which searchd`
|
|
322
|
+
@location = output.chomp if $? == 0
|
|
323
|
+
$? == 0
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
Contribute.new.show
|