acts_as_ferret 0.4.8.2 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -6
- data/bin/aaf_install +10 -6
- data/config/ferret_server.yml +2 -2
- data/doc/demo/app/models/stats.rb +1 -1
- data/lib/acts_as_ferret.rb +39 -37
- data/lib/{act_methods.rb → acts_as_ferret/act_methods.rb} +1 -1
- data/lib/{blank_slate.rb → acts_as_ferret/blank_slate.rb} +0 -0
- data/lib/{bulk_indexer.rb → acts_as_ferret/bulk_indexer.rb} +0 -0
- data/lib/{class_methods.rb → acts_as_ferret/class_methods.rb} +0 -0
- data/lib/{ferret_extensions.rb → acts_as_ferret/ferret_extensions.rb} +12 -16
- data/lib/{ferret_find_methods.rb → acts_as_ferret/ferret_find_methods.rb} +0 -0
- data/lib/{ferret_result.rb → acts_as_ferret/ferret_result.rb} +0 -0
- data/lib/{index.rb → acts_as_ferret/index.rb} +0 -0
- data/lib/{instance_methods.rb → acts_as_ferret/instance_methods.rb} +1 -1
- data/lib/{local_index.rb → acts_as_ferret/local_index.rb} +7 -4
- data/lib/{more_like_this.rb → acts_as_ferret/more_like_this.rb} +0 -0
- data/lib/{multi_index.rb → acts_as_ferret/multi_index.rb} +0 -0
- data/lib/acts_as_ferret/railtie.rb +16 -0
- data/lib/{rdig_adapter.rb → acts_as_ferret/rdig_adapter.rb} +0 -1
- data/lib/{remote_functions.rb → acts_as_ferret/remote_functions.rb} +0 -0
- data/lib/{remote_index.rb → acts_as_ferret/remote_index.rb} +0 -0
- data/lib/{remote_multi_index.rb → acts_as_ferret/remote_multi_index.rb} +0 -0
- data/lib/{search_results.rb → acts_as_ferret/search_results.rb} +0 -0
- data/lib/acts_as_ferret/server/config.rb +50 -0
- data/lib/{ferret_server.rb → acts_as_ferret/server/server.rb} +11 -56
- data/lib/{unix_daemon.rb → acts_as_ferret/server/unix_daemon.rb} +2 -4
- data/lib/acts_as_ferret/version.rb +3 -0
- data/lib/{without_ar.rb → acts_as_ferret/without_ar.rb} +0 -0
- data/recipes/aaf_recipes.rb +2 -4
- data/script/ferret_server +72 -6
- data/tasks/ferret.rake +13 -9
- metadata +68 -39
- data/acts_as_ferret.gemspec +0 -59
- data/init.rb +0 -24
- data/install.rb +0 -18
- data/lib/ar_mysql_auto_reconnect_patch.rb +0 -41
- data/lib/server_manager.rb +0 -71
- data/script/ferret_daemon +0 -94
- data/script/ferret_service +0 -178
data/lib/server_manager.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
################################################################################
|
2
|
-
require 'optparse'
|
3
|
-
|
4
|
-
################################################################################
|
5
|
-
$ferret_server_options = {
|
6
|
-
'environment' => nil,
|
7
|
-
'debug' => nil,
|
8
|
-
'root' => nil
|
9
|
-
}
|
10
|
-
|
11
|
-
################################################################################
|
12
|
-
OptionParser.new do |optparser|
|
13
|
-
optparser.banner = "Usage: #{File.basename($0)} [options] {start|stop|run}"
|
14
|
-
|
15
|
-
optparser.on('-h', '--help', "This message") do
|
16
|
-
puts optparser
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
|
20
|
-
optparser.on('-R', '--root=PATH', 'Set RAILS_ROOT to the given string') do |r|
|
21
|
-
$ferret_server_options['root'] = r
|
22
|
-
end
|
23
|
-
|
24
|
-
optparser.on('-e', '--environment=NAME', 'Set RAILS_ENV to the given string') do |e|
|
25
|
-
$ferret_server_options['environment'] = e
|
26
|
-
end
|
27
|
-
|
28
|
-
optparser.on('--debug', 'Include full stack traces on exceptions') do
|
29
|
-
$ferret_server_options['debug'] = true
|
30
|
-
end
|
31
|
-
|
32
|
-
$ferret_server_action = optparser.permute!(ARGV)
|
33
|
-
(puts optparser; exit(1)) unless $ferret_server_action.size == 1
|
34
|
-
|
35
|
-
$ferret_server_action = $ferret_server_action.first
|
36
|
-
(puts optparser; exit(1)) unless %w(start stop run).include?($ferret_server_action)
|
37
|
-
end
|
38
|
-
|
39
|
-
################################################################################
|
40
|
-
|
41
|
-
def determine_rails_root
|
42
|
-
possible_rails_roots = [
|
43
|
-
$ferret_server_options['root'],
|
44
|
-
(defined?(FERRET_SERVER) ? File.join(File.dirname(FERRET_SERVER), '..') : nil),
|
45
|
-
File.join(File.dirname(__FILE__), *(['..']*4)),
|
46
|
-
'.'
|
47
|
-
].compact
|
48
|
-
# take the first dir where environment.rb can be found
|
49
|
-
possible_rails_roots.find{ |dir| File.readable?(File.join(dir, 'config', 'environment.rb')) }
|
50
|
-
end
|
51
|
-
|
52
|
-
begin
|
53
|
-
ENV['FERRET_USE_LOCAL_INDEX'] = 'true'
|
54
|
-
ENV['RAILS_ENV'] = $ferret_server_options['environment']
|
55
|
-
# determine RAILS_ROOT unless already set
|
56
|
-
RAILS_ROOT = determine_rails_root unless defined?(RAILS_ROOT)
|
57
|
-
|
58
|
-
begin
|
59
|
-
require File.join(RAILS_ROOT, 'config', 'environment')
|
60
|
-
rescue LoadError
|
61
|
-
puts "Unable to find Rails environment.rb in any of these locations:\n#{possible_rails_roots.join("\n")}\nPlease use the --root option of ferret_server to point it to your RAILS_ROOT."
|
62
|
-
raise $!
|
63
|
-
end
|
64
|
-
|
65
|
-
# require 'acts_as_ferret'
|
66
|
-
ActsAsFerret::Remote::Server.new.send($ferret_server_action)
|
67
|
-
rescue Exception => e
|
68
|
-
$stderr.puts(e.message)
|
69
|
-
$stderr.puts(e.backtrace.join("\n")) if $ferret_server_options['debug']
|
70
|
-
exit(1)
|
71
|
-
end
|
data/script/ferret_daemon
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
# Ferret Win32 Service Daemon, called by Win 32 service,
|
2
|
-
# created by Herryanto Siatono <herryanto@pluitsolutions.com>
|
3
|
-
#
|
4
|
-
# see doc/README.win32 for usage instructions
|
5
|
-
#
|
6
|
-
require 'optparse'
|
7
|
-
require 'win32/service'
|
8
|
-
include Win32
|
9
|
-
|
10
|
-
# Read options
|
11
|
-
options = {}
|
12
|
-
ARGV.options do |opts|
|
13
|
-
opts.banner = 'Usage: ferret_daemon [options]'
|
14
|
-
opts.on("-l", "--log FILE", "Daemon log file") {|file| options[:log] = file }
|
15
|
-
opts.on("-c","--console","Run Ferret server on console.") {options[:console] = true}
|
16
|
-
opts.on_tail("-h","--help", "Show this help message") {puts opts; exit}
|
17
|
-
opts.on("-e", "--environment ENV ", "Rails environment") {|env|
|
18
|
-
options[:environment] = env
|
19
|
-
ENV['RAILS_ENV'] = env
|
20
|
-
}
|
21
|
-
opts.parse!
|
22
|
-
end
|
23
|
-
|
24
|
-
require File.dirname(__FILE__) + '/../config/environment'
|
25
|
-
|
26
|
-
# Ferret Win32 Service Daemon, called by Win 32 service,
|
27
|
-
# to run on the console, use -c or --console option.
|
28
|
-
module Ferret
|
29
|
-
class FerretDaemon < Daemon
|
30
|
-
# Standard logger to redirect STDOUT and STDERR to a log file
|
31
|
-
class FerretStandardLogger
|
32
|
-
def initialize(logger)
|
33
|
-
@logger = logger
|
34
|
-
end
|
35
|
-
|
36
|
-
def write(s)
|
37
|
-
@logger.info s
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def initialize(options={})
|
42
|
-
@options = options
|
43
|
-
|
44
|
-
# initialize logger
|
45
|
-
if options[:log]
|
46
|
-
@logger = Logger.new @options[:log]
|
47
|
-
else
|
48
|
-
@logger = Logger.new RAILS_ROOT + "/log/ferret_service_#{RAILS_ENV}.log"
|
49
|
-
end
|
50
|
-
|
51
|
-
# redirect stout and stderr to Ferret logger if running as windows service
|
52
|
-
$stdout = $stderr = FerretStandardLogger.new(@logger) unless @options[:console]
|
53
|
-
|
54
|
-
log "Initializing FerretDaemon..."
|
55
|
-
if @options[:console]
|
56
|
-
self.service_init
|
57
|
-
self.service_main
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def service_main
|
62
|
-
log "Service main enterred..."
|
63
|
-
|
64
|
-
while running?
|
65
|
-
log "Listening..."
|
66
|
-
sleep
|
67
|
-
end
|
68
|
-
|
69
|
-
log "Service main exit..."
|
70
|
-
end
|
71
|
-
|
72
|
-
def service_init
|
73
|
-
log "Starting Ferret DRb server..."
|
74
|
-
ActsAsFerret::Remote::Server.start
|
75
|
-
log "FerretDaemon started."
|
76
|
-
end
|
77
|
-
|
78
|
-
def service_stop
|
79
|
-
log "Stopping service..."
|
80
|
-
DRb.stop_service
|
81
|
-
log "FerretDaemon stopped."
|
82
|
-
end
|
83
|
-
|
84
|
-
def log(msg)
|
85
|
-
@logger.info msg
|
86
|
-
puts msg if @options[:console]
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
if __FILE__ == $0
|
92
|
-
d = Ferret::FerretDaemon.new(options)
|
93
|
-
d.mainloop
|
94
|
-
end
|
data/script/ferret_service
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
# Ferret Win32 Service Daemon install script
|
2
|
-
# created by Herryanto Siatono <herryanto@pluitsolutions.com>
|
3
|
-
#
|
4
|
-
# see doc/README.win32 for usage instructions
|
5
|
-
#
|
6
|
-
require 'optparse'
|
7
|
-
require 'win32/service'
|
8
|
-
include Win32
|
9
|
-
|
10
|
-
module Ferret
|
11
|
-
# Parse and validate service command and options
|
12
|
-
class FerretServiceCommand
|
13
|
-
COMMANDS = ['install', 'remove', 'start', 'stop', 'help']
|
14
|
-
BANNER = "Usage: ruby script/ferret_service <command> [options]"
|
15
|
-
|
16
|
-
attr_reader :options, :command
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@options = {}
|
20
|
-
end
|
21
|
-
|
22
|
-
def valid_command?
|
23
|
-
COMMANDS.include?@command
|
24
|
-
end
|
25
|
-
|
26
|
-
def valid_options?
|
27
|
-
@options[:name] and !@options[:name].empty?
|
28
|
-
end
|
29
|
-
|
30
|
-
def print_command_list
|
31
|
-
puts BANNER
|
32
|
-
puts "\nAvailable commands:\n"
|
33
|
-
puts COMMANDS.map {|cmd| " - #{cmd}\n"}
|
34
|
-
puts "\nUse option -h for each command to help."
|
35
|
-
exit
|
36
|
-
end
|
37
|
-
|
38
|
-
def validate_options
|
39
|
-
errors = []
|
40
|
-
errors << "Service name is required." unless @options[:name]
|
41
|
-
|
42
|
-
if (errors.size > 0)
|
43
|
-
errors << "Error found. Use: 'ruby script/ferret_service #{@command} -h' for to get help."
|
44
|
-
puts errors.join("\n")
|
45
|
-
exit
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def run(args)
|
50
|
-
@command = args.shift
|
51
|
-
@command = @command.dup.downcase if @command
|
52
|
-
|
53
|
-
# validate command and options
|
54
|
-
print_command_list unless valid_command? or @command == 'help'
|
55
|
-
|
56
|
-
opts_parser = create_options_parser
|
57
|
-
begin
|
58
|
-
opts_parser.parse!(args)
|
59
|
-
rescue OptionParser::ParseError => e
|
60
|
-
puts e
|
61
|
-
puts opts_parser
|
62
|
-
end
|
63
|
-
|
64
|
-
# validate required options
|
65
|
-
validate_options
|
66
|
-
end
|
67
|
-
|
68
|
-
def create_options_parser
|
69
|
-
opts_parser = OptionParser.new
|
70
|
-
opts_parser.banner = BANNER
|
71
|
-
opts_parser.on("-n", "--name=NAME", "Service name") {|name| @options[:name] = name }
|
72
|
-
opts_parser.on_tail("-t", "--trace", "Display stack trace when exception thrown") { @options[:trace] = true }
|
73
|
-
opts_parser.on_tail("-h", "--help", "Show this help message") { puts opts_parser; exit }
|
74
|
-
|
75
|
-
if ['install'].include?@command
|
76
|
-
opts_parser.on("-d", "--display=NAME", "Service display name") {|name| @options[:display] = name }
|
77
|
-
|
78
|
-
opts_parser.on("-l", "--log FILE", "Service log file") {|file| @options[:log] = file }
|
79
|
-
opts_parser.on("-e", "--environment ENV ", "Rails environment") { |env|
|
80
|
-
@options[:environment] = env
|
81
|
-
ENV['RAILS_ENV'] = env
|
82
|
-
}
|
83
|
-
end
|
84
|
-
opts_parser
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Install, Remove, Start and Stop Ferret DRb server Win32 service
|
89
|
-
class FerretService
|
90
|
-
FERRET_DAEMON = 'ferret_daemon'
|
91
|
-
|
92
|
-
def initialize
|
93
|
-
end
|
94
|
-
|
95
|
-
def install
|
96
|
-
svc = Service.new
|
97
|
-
|
98
|
-
begin
|
99
|
-
if Service.exists?(@options[:name])
|
100
|
-
puts "Service name '#{@options[:name]}' already exists."
|
101
|
-
return
|
102
|
-
end
|
103
|
-
|
104
|
-
svc.create_service do |s|
|
105
|
-
s.service_name = @options[:name]
|
106
|
-
s.display_name = @options[:display]
|
107
|
-
s.binary_path_name = binary_path_name
|
108
|
-
s.dependencies = []
|
109
|
-
end
|
110
|
-
|
111
|
-
svc.close
|
112
|
-
puts "'#{@options[:name]}' service installed."
|
113
|
-
rescue => e
|
114
|
-
handle_error(e)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def remove
|
119
|
-
begin
|
120
|
-
Service.stop(@options[:name])
|
121
|
-
rescue
|
122
|
-
end
|
123
|
-
|
124
|
-
begin
|
125
|
-
Service.delete(@options[:name])
|
126
|
-
puts "'#{@options[:name]}' service removed."
|
127
|
-
rescue => e
|
128
|
-
handle_error(e)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def start
|
133
|
-
begin
|
134
|
-
Service.start(@options[:name])
|
135
|
-
puts "'#{@options[:name]}' successfully started."
|
136
|
-
rescue => e
|
137
|
-
handle_error(e)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def stop
|
142
|
-
begin
|
143
|
-
Service.stop(@options[:name])
|
144
|
-
puts "'#{@options[:name]}' successfully stopped.\n"
|
145
|
-
rescue => e
|
146
|
-
handle_error(e)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def run(args)
|
151
|
-
svc_cmd = FerretServiceCommand.new
|
152
|
-
svc_cmd.run(args)
|
153
|
-
@options = svc_cmd.options
|
154
|
-
self.send(svc_cmd.command.to_sym)
|
155
|
-
end
|
156
|
-
|
157
|
-
protected
|
158
|
-
def handle_error(e)
|
159
|
-
if @options[:trace]
|
160
|
-
raise e
|
161
|
-
else
|
162
|
-
puts e
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def binary_path_name
|
167
|
-
path = ""
|
168
|
-
path << "#{ENV['RUBY_HOME']}/bin/" if ENV['RUBY_HOME']
|
169
|
-
path << "ruby.exe "
|
170
|
-
path << File.expand_path("script/" + FERRET_DAEMON)
|
171
|
-
path << " -e #{@options[:environment]} " if @options[:environment]
|
172
|
-
path << " -l #{@options[:log]} " if @options[:log]
|
173
|
-
path
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
Ferret::FerretService.new.run(ARGV)
|