tire 0.1.0 → 0.1.1
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/README.markdown +0 -2
- data/examples/rails-application-template.rb +124 -39
- data/lib/tire/model/callbacks.rb +1 -1
- data/lib/tire/version.rb +1 -1
- data/test/unit/model_search_test.rb +8 -0
- metadata +4 -4
data/README.markdown
CHANGED
|
@@ -2,34 +2,99 @@
|
|
|
2
2
|
# Template for generating a no-frills Rails application with support for ElasticSearch full-text search via Tire
|
|
3
3
|
# ===================================================================================================================
|
|
4
4
|
#
|
|
5
|
-
# This file creates a basic Rails application
|
|
5
|
+
# This file creates a basic, fully working Rails application
|
|
6
|
+
# with support for ElasticSearch full-text search via the Tire gem.
|
|
6
7
|
#
|
|
7
|
-
# Run it like this:
|
|
8
8
|
#
|
|
9
|
-
#
|
|
9
|
+
# Requirements
|
|
10
|
+
# ------------
|
|
10
11
|
#
|
|
12
|
+
# * Ruby >= 1.8.7
|
|
13
|
+
# * Rubygems
|
|
14
|
+
# * Rails 3
|
|
15
|
+
#
|
|
16
|
+
#
|
|
17
|
+
# Usage
|
|
18
|
+
# -----
|
|
19
|
+
#
|
|
20
|
+
# $ rails new searchapp -m https://github.com/karmi/tire/raw/master/examples/rails-application-template.rb
|
|
21
|
+
#
|
|
22
|
+
# ===================================================================================================================
|
|
23
|
+
|
|
24
|
+
require 'rubygems'
|
|
25
|
+
require 'restclient'
|
|
26
|
+
|
|
27
|
+
at_exit do
|
|
28
|
+
say_status "Stop", "ElasticSearch", :yellow
|
|
29
|
+
|
|
30
|
+
pid = File.read("#{destination_root}/tmp/pids/elasticsearch.pid") rescue nil
|
|
31
|
+
run "kill #{pid}" if pid
|
|
32
|
+
end
|
|
11
33
|
|
|
12
34
|
run "rm public/index.html"
|
|
13
35
|
run "rm public/images/rails.png"
|
|
14
36
|
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
|
|
15
37
|
|
|
38
|
+
run "rm -f .gitignore"
|
|
39
|
+
file ".gitignore", <<-END.gsub(/ /, '')
|
|
40
|
+
.DS_Store
|
|
41
|
+
log/*.log
|
|
42
|
+
tmp/**/*
|
|
43
|
+
config/database.yml
|
|
44
|
+
db/*.sqlite3
|
|
45
|
+
vendor/elasticsearch-0.16.0/
|
|
46
|
+
END
|
|
47
|
+
|
|
16
48
|
git :init
|
|
17
49
|
git :add => '.'
|
|
18
50
|
git :commit => "-m 'Initial commit: Clean application'"
|
|
19
51
|
|
|
52
|
+
unless (RestClient.get('http://localhost:9200') rescue false)
|
|
53
|
+
COMMAND = <<-COMMAND.gsub(/^ /, '')
|
|
54
|
+
curl -k -L -# -o elasticsearch-0.16.0.tar.gz \
|
|
55
|
+
"http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.16.0.tar.gz"
|
|
56
|
+
tar -zxf elasticsearch-0.16.0.tar.gz
|
|
57
|
+
rm -f elasticsearch-0.16.0.tar.gz
|
|
58
|
+
./elasticsearch-0.16.0/bin/elasticsearch -p #{destination_root}/tmp/pids/elasticsearch.pid
|
|
59
|
+
COMMAND
|
|
60
|
+
|
|
61
|
+
puts "\n"
|
|
62
|
+
say_status "ERROR", "ElasticSearch not running!\n", :red
|
|
63
|
+
puts '-'*80
|
|
64
|
+
say_status '', "It appears that ElasticSearch is not running on this machine."
|
|
65
|
+
say_status '', "Is it installed? Do you want me to install it for you with this command?\n\n"
|
|
66
|
+
COMMAND.each_line { |l| say_status '', "$ #{l}" }
|
|
67
|
+
puts
|
|
68
|
+
say_status '', "(To uninstall, just remove the generated application directory.)"
|
|
69
|
+
puts '-'*80, ''
|
|
70
|
+
|
|
71
|
+
if yes?("Install ElasticSearch?", :bold)
|
|
72
|
+
puts
|
|
73
|
+
say_status "Install", "ElasticSearch", :yellow
|
|
74
|
+
|
|
75
|
+
commands = COMMAND.split("\n")
|
|
76
|
+
exec = commands.pop
|
|
77
|
+
inside("vendor") do
|
|
78
|
+
commands.each { |command| run command }
|
|
79
|
+
run "(#{exec})" # Launch ElasticSearch in subshell
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
20
84
|
puts
|
|
21
85
|
say_status "Rubygems", "Adding Rubygems into Gemfile...\n", :yellow
|
|
22
|
-
puts '-'*80, ''
|
|
86
|
+
puts '-'*80, ''; sleep 1
|
|
23
87
|
|
|
24
|
-
gem 'tire'
|
|
88
|
+
gem 'tire'
|
|
25
89
|
gem 'will_paginate', '~>3.0.pre'
|
|
90
|
+
|
|
26
91
|
git :add => '.'
|
|
27
92
|
git :commit => "-m 'Added gems'"
|
|
28
93
|
|
|
29
94
|
puts
|
|
30
95
|
say_status "Rubygems", "Installing Rubygems...", :yellow
|
|
96
|
+
puts '-'*80, ''
|
|
31
97
|
|
|
32
|
-
puts
|
|
33
98
|
puts "********************************************************************************"
|
|
34
99
|
puts " Running `bundle install`. Let's watch a movie!"
|
|
35
100
|
puts "********************************************************************************", ""
|
|
@@ -37,8 +102,8 @@ puts "**************************************************************************
|
|
|
37
102
|
run "bundle install"
|
|
38
103
|
|
|
39
104
|
puts
|
|
40
|
-
say_status "Model", "Adding
|
|
41
|
-
puts '-'*80, ''
|
|
105
|
+
say_status "Model", "Adding the Article resource...", :yellow
|
|
106
|
+
puts '-'*80, ''; sleep 1
|
|
42
107
|
|
|
43
108
|
generate :scaffold, "Article title:string content:text published_on:date"
|
|
44
109
|
route "root :to => 'articles#index'"
|
|
@@ -47,6 +112,38 @@ rake "db:migrate"
|
|
|
47
112
|
git :add => '.'
|
|
48
113
|
git :commit => "-m 'Added the Article resource'"
|
|
49
114
|
|
|
115
|
+
puts
|
|
116
|
+
say_status "Database", "Seeding the database with data...", :yellow
|
|
117
|
+
puts '-'*80, ''; sleep 0.25
|
|
118
|
+
|
|
119
|
+
run "rm -f db/seeds.rb"
|
|
120
|
+
file 'db/seeds.rb', <<-CODE
|
|
121
|
+
contents = [
|
|
122
|
+
'Lorem ipsum dolor sit amet.',
|
|
123
|
+
'Consectetur adipisicing elit, sed do eiusmod tempor incididunt.',
|
|
124
|
+
'Labore et dolore magna aliqua.',
|
|
125
|
+
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.',
|
|
126
|
+
'Excepteur sint occaecat cupidatat non proident.'
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
puts "Deleting all articles..."
|
|
130
|
+
Article.delete_all
|
|
131
|
+
|
|
132
|
+
puts "Creating articles..."
|
|
133
|
+
%w[ One Two Three Four Five ].each_with_index do |title, i|
|
|
134
|
+
Article.create :title => title, :content => contents[i], :published_on => i.days.ago.utc
|
|
135
|
+
end
|
|
136
|
+
CODE
|
|
137
|
+
|
|
138
|
+
rake "db:seed"
|
|
139
|
+
|
|
140
|
+
git :add => "db/seeds.rb"
|
|
141
|
+
git :commit => "-m 'Added database seeding script'"
|
|
142
|
+
|
|
143
|
+
puts
|
|
144
|
+
say_status "Model", "Adding search support into the Article model...", :yellow
|
|
145
|
+
puts '-'*80, ''; sleep 1
|
|
146
|
+
|
|
50
147
|
run "rm -f app/models/article.rb"
|
|
51
148
|
file 'app/models/article.rb', <<-CODE
|
|
52
149
|
class Article < ActiveRecord::Base
|
|
@@ -64,8 +161,8 @@ CODE
|
|
|
64
161
|
git :commit => "-a -m 'Added Tire support into the Article class and an initializer'"
|
|
65
162
|
|
|
66
163
|
puts
|
|
67
|
-
say_status "Controller", "Adding controller action, route, and
|
|
68
|
-
puts '-'*80, ''
|
|
164
|
+
say_status "Controller", "Adding controller action, route, and HTML for search...", :yellow
|
|
165
|
+
puts '-'*80, ''; sleep 1
|
|
69
166
|
|
|
70
167
|
gsub_file 'app/controllers/articles_controller.rb', %r{# GET /articles/1$}, <<-CODE
|
|
71
168
|
# GET /articles/search
|
|
@@ -104,41 +201,29 @@ CODE
|
|
|
104
201
|
git :commit => "-a -m 'Added Tire support into the frontend of application'"
|
|
105
202
|
|
|
106
203
|
puts
|
|
107
|
-
say_status "
|
|
108
|
-
puts '-'*80, ''
|
|
204
|
+
say_status "Index", "Indexing the database...", :yellow
|
|
205
|
+
puts '-'*80, ''; sleep 0.5
|
|
109
206
|
|
|
110
|
-
|
|
111
|
-
file 'db/seeds.rb', <<-CODE
|
|
112
|
-
contents = [
|
|
113
|
-
'Lorem ipsum dolor sit amet.',
|
|
114
|
-
'Consectetur adipisicing elit, sed do eiusmod tempor incididunt.',
|
|
115
|
-
'Labore et dolore magna aliqua.',
|
|
116
|
-
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.',
|
|
117
|
-
'Excepteur sint occaecat cupidatat non proident.'
|
|
118
|
-
]
|
|
119
|
-
|
|
120
|
-
puts "Deleting all articles..."
|
|
121
|
-
Article.delete_all
|
|
122
|
-
|
|
123
|
-
puts "Creating articles:"
|
|
124
|
-
%w[ One Two Three Four Five ].each_with_index do |title, i|
|
|
125
|
-
Article.create :title => title, :content => contents[i], :published_on => i.days.ago.utc
|
|
126
|
-
end
|
|
127
|
-
CODE
|
|
128
|
-
|
|
129
|
-
rake "db:seed"
|
|
130
|
-
|
|
131
|
-
git :add => "db/seeds.rb"
|
|
132
|
-
git :commit => "-m 'Added database seeding script'"
|
|
207
|
+
rake "environment tire:import CLASS='Article' FORCE=true"
|
|
133
208
|
|
|
134
209
|
puts
|
|
135
|
-
say_status "
|
|
210
|
+
say_status "Git", "Details about the application:", :yellow
|
|
136
211
|
puts '-'*80, ''
|
|
137
212
|
|
|
138
|
-
|
|
213
|
+
run "git log --reverse --pretty=format:'%Cblue%h%Creset | %s'"
|
|
214
|
+
|
|
215
|
+
if (begin; RestClient.get('http://localhost:3000'); rescue Errno::ECONNREFUSED; false; rescue Exception; true; end)
|
|
216
|
+
puts "\n"
|
|
217
|
+
say_status "ERROR", "Some other application is running on port 3000!\n", :red
|
|
218
|
+
puts '-'*80
|
|
219
|
+
|
|
220
|
+
port = ask("Please provide free port:", :bold)
|
|
221
|
+
else
|
|
222
|
+
port = '3000'
|
|
223
|
+
end
|
|
139
224
|
|
|
140
225
|
puts "", "="*80
|
|
141
|
-
say_status "DONE", "\e[1mStarting the application. Open http://localhost
|
|
226
|
+
say_status "DONE", "\e[1mStarting the application. Open http://localhost:#{port}\e[0m", :yellow
|
|
142
227
|
puts "="*80, ""
|
|
143
228
|
|
|
144
|
-
run "rails server"
|
|
229
|
+
run "rails server --port=#{port}"
|
data/lib/tire/model/callbacks.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Tire
|
|
|
9
9
|
base.send :after_destroy, :update_elastic_search_index
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
if base.respond_to?(:before_destroy) && !base.
|
|
12
|
+
if base.respond_to?(:before_destroy) && !base.instance_methods.include?('destroyed?')
|
|
13
13
|
base.class_eval do
|
|
14
14
|
before_destroy { @destroyed = true }
|
|
15
15
|
def destroyed?; !!@destroyed; end
|
data/lib/tire/version.rb
CHANGED
|
@@ -158,6 +158,14 @@ module Tire
|
|
|
158
158
|
@model.save
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
+
should_eventually "not define destroyed? if class already implements it" do
|
|
162
|
+
load File.expand_path('../../models/active_model_article_with_callbacks.rb', __FILE__)
|
|
163
|
+
|
|
164
|
+
# TODO: Find a way how to break the old implementation:
|
|
165
|
+
# if base.respond_to?(:before_destroy) && !base.respond_to?(:destroyed?)
|
|
166
|
+
ActiveModelArticleWithCallbacks.expects(:class_eval).never
|
|
167
|
+
end
|
|
168
|
+
|
|
161
169
|
should "fire :after_save callbacks" do
|
|
162
170
|
@model = ActiveModelArticleWithCallbacks.new
|
|
163
171
|
@model.expects(:update_elastic_search_index)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tire
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 25
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.1.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Karel Minarik
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-05-
|
|
18
|
+
date: 2011-05-02 00:00:00 +02:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|