acts_as_ferret 0.4.7 → 0.4.8.rails3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -21,9 +21,8 @@ http://github.com/jkraemer/acts_as_ferret/tree/master .
21
21
 
22
22
  Add this to your project's config/environment.rb:
23
23
 
24
- <tt>config.gem 'acts_as_ferret', :version => '~> 0.4.7'</tt>
24
+ <tt>config.gem 'acts_as_ferret', :version => '~> 0.4.8'</tt>
25
25
 
26
- With Rails 3 of course instead you have to update your Gemfile, but I guess you already knew that ;-)
27
26
  With the gem installed, change into your RAILS_ROOT and run the supplied aaf_install script.
28
27
  This will copy rake tasks, capistrano recipes and the ferret server config and startup script
29
28
  into your project.
@@ -43,6 +42,37 @@ No additional setup needed.
43
42
 
44
43
  == Usage
45
44
 
45
+ There are two ways to make your models searchable with aaf. The option to configure acts_as_ferret with
46
+ a single configuration file has been introduced because it makes more sense when a single index holds multiple
47
+ models - it's simply more logicl to define that index and tell which models should go into it than to call
48
+ acts_as_ferret in each model pointing to the same index every time.
49
+
50
+ === central configuration file
51
+
52
+ With this option, all acts_as_ferret indexes are configured in a single file, RAILS_ROOT/config/aaf.rb:
53
+
54
+ ActsAsFerret::define_index( 'my_index',
55
+ :models => {
56
+ SomeModel => {
57
+ :fields => {
58
+ :name => { :boost => 4, :store => :yes, :via => :ferret_title },
59
+ :foo => { :store => :no, :index => :untokenized },
60
+ :baz => { :store => :yes, :via => :ferret_content }
61
+ }
62
+ }
63
+ } )
64
+
65
+ ActsAsFerret::define_index( 'some_other_index',
66
+ :models => {
67
+ Foo => { :fields => { ... } },
68
+ Bar => { ... },
69
+ } )
70
+
71
+
72
+ As you can see for every index you want to define there's a single call, and each model that should go
73
+ into the index gets it's own ferret options hash (see the acts_as_ferret class method docs for all available options).
74
+
75
+ === In your models (the old fashioned way)
46
76
  include the following in your model class (specifiying the fields you want to get indexed):
47
77
 
48
78
  <tt>acts_as_ferret :fields => [ :title, :description ]</tt>
@@ -55,6 +85,10 @@ less results).
55
85
 
56
86
  Please see ActsAsFerret::ActMethods#acts_as_ferret for more information.
57
87
 
88
+ == Known issues
89
+
90
+ aaf is not yet ready for Rails3. Feel free to submit patches!
91
+
58
92
  == License
59
93
 
60
94
  Released under the MIT license.
@@ -5,8 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 7
9
- version: 0.4.7
8
+ - 8
9
+ - rails3
10
+ version: 0.4.8.rails3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jens Kraemer
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-06 13:50:00 +02:00
18
+ date: 2010-07-13 14:10:00 +02:00
18
19
  default_executable: aaf_install
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -208,7 +209,7 @@ files:
208
209
  - doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb
209
210
  - doc/monit-example
210
211
  - doc/README.win32
211
- - init.rb
212
+ - rails/init.rb
212
213
  - install.rb
213
214
  - lib
214
215
  - lib/act_methods.rb
@@ -2,8 +2,8 @@
2
2
  # host: where to reach the DRb server (used by application processes to contact the server)
3
3
  # port: which port the server should listen on
4
4
  # socket: where the DRb server should create the socket (absolute path), this setting overrides host:port configuration
5
- # pid_file: location of the server's pid file (relative to RAILS_ROOT)
6
- # log_file: log file (default: RAILS_ROOT/log/ferret_server.log
5
+ # pid_file: location of the server's pid file (relative to Rails.root)
6
+ # log_file: log file (default: Rails.root/log/ferret_server.log
7
7
  # log_level: log level for the server's logger
8
8
  production:
9
9
  host: localhost
data/lib/act_methods.rb CHANGED
@@ -26,7 +26,7 @@ module ActsAsFerret #:nodoc:
26
26
  # to determine if it should be indexed or not.
27
27
  #
28
28
  # index_dir:: declares the directory where to put the index for this class.
29
- # The default is RAILS_ROOT/index/RAILS_ENV/CLASSNAME.
29
+ # The default is Rails.root/index/Rails.env/CLASSNAME.
30
30
  # The index directory will be created if it doesn't exist.
31
31
  #
32
32
  # reindex_batch_size:: reindexing is done in batches of this size, default is 1000
@@ -75,7 +75,7 @@ module ActsAsFerret #:nodoc:
75
75
  # set up AR hooks
76
76
  after_create :ferret_create
77
77
  after_update :ferret_update
78
- after_destroy :ferret_destroy
78
+ after_destroy :ferret_destroy
79
79
  end
80
80
 
81
81
  cattr_accessor :aaf_configuration
@@ -82,7 +82,7 @@ require 'rdig_adapter'
82
82
  # whatever reason.
83
83
  #
84
84
  # remote:: Set this to false to force acts_as_ferret into local (non-DRb) mode even if
85
- # config/ferret_server.yml contains a section for the current RAILS_ENV
85
+ # config/ferret_server.yml contains a section for the current Rails.env
86
86
  # Usually you won't need to touch this option - just configure DRb for
87
87
  # production mode in ferret_server.yml.
88
88
  #
@@ -107,7 +107,7 @@ module ActsAsFerret
107
107
  @@index_using_classes = {}
108
108
  def self.index_using_classes; @@index_using_classes end
109
109
 
110
- @@logger = Logger.new "#{RAILS_ROOT}/log/acts_as_ferret.log"
110
+ @@logger = Logger.new "#{Rails.root || '.'}/log/acts_as_ferret.log"
111
111
  @@logger.level = ActiveRecord::Base.logger.level rescue Logger::DEBUG
112
112
  mattr_accessor :logger
113
113
 
@@ -145,10 +145,15 @@ module ActsAsFerret
145
145
  remote?
146
146
 
147
147
 
148
- # Globally declares an index.
148
+ # Declares an index.
149
149
  #
150
- # This method is also used to implicitly declare an index when you use the
151
- # acts_as_ferret call in your class. Returns the created index instance.
150
+ # Use this method to define your indexes in a global initializer (i.e. config/initializers/aaf.rb).
151
+ # This is especially useful if you want to have multiple classes share the same index for cross-model
152
+ # searching as you only need a single call to declare the index for all models.
153
+ #
154
+ # This method is also used internally to declare an index when you use the
155
+ # acts_as_ferret call inside your class (which in turn can be omitted if the initializer is used).
156
+ # Returns the created index instance.
152
157
  #
153
158
  # === Options are:
154
159
  #
@@ -250,7 +255,7 @@ module ActsAsFerret
250
255
 
251
256
  def self.load_config
252
257
  # using require_dependency to make the reloading in dev mode work.
253
- require_dependency "#{RAILS_ROOT}/config/aaf.rb"
258
+ require_dependency "#{Rails.root}/config/aaf.rb"
254
259
  ActsAsFerret::logger.info "loaded configuration file aaf.rb"
255
260
  rescue LoadError
256
261
  ensure
@@ -513,10 +518,10 @@ module ActsAsFerret
513
518
 
514
519
 
515
520
  # make sure the default index base dir exists. by default, all indexes are created
516
- # under RAILS_ROOT/index/RAILS_ENV
521
+ # under Rails.root/index/Rails.env
517
522
  def self.init_index_basedir
518
- index_base = "#{RAILS_ROOT}/index"
519
- @@index_dir = "#{index_base}/#{RAILS_ENV}"
523
+ index_base = "#{Rails.root || '.'}/index"
524
+ @@index_dir = "#{index_base}/#{Rails.env}"
520
525
  end
521
526
 
522
527
  mattr_accessor :index_dir
data/lib/ferret_server.rb CHANGED
@@ -14,9 +14,9 @@ module ActsAsFerret
14
14
  DEFAULTS = {
15
15
  'host' => 'localhost',
16
16
  'port' => '9009',
17
- 'cf' => "#{RAILS_ROOT}/config/ferret_server.yml",
18
- 'pid_file' => "#{RAILS_ROOT}/log/ferret_server.pid",
19
- 'log_file' => "#{RAILS_ROOT}/log/ferret_server.log",
17
+ 'cf' => "#{Rails.root}/config/ferret_server.yml",
18
+ 'pid_file' => "#{Rails.root}/log/ferret_server.pid",
19
+ 'log_file' => "#{Rails.root}/log/ferret_server.log",
20
20
  'log_level' => 'debug',
21
21
  'socket' => nil,
22
22
  'script' => nil
@@ -27,8 +27,8 @@ module ActsAsFerret
27
27
  def initialize (file=DEFAULTS['cf'])
28
28
  @everything = YAML.load(ERB.new(IO.read(file)).result)
29
29
  raise "malformed ferret server config" unless @everything.is_a?(Hash)
30
- @config = DEFAULTS.merge(@everything[RAILS_ENV] || {})
31
- if @everything[RAILS_ENV]
30
+ @config = DEFAULTS.merge(@everything[Rails.env] || {})
31
+ if @everything[Rails.env]
32
32
  @config['uri'] = socket.nil? ? "druby://#{host}:#{port}" : "drbunix:#{socket}"
33
33
  end
34
34
  end
@@ -46,7 +46,7 @@ module ActsAsFerret
46
46
  # search requests from models declared to 'acts_as_ferret :remote => true'
47
47
  #
48
48
  # Usage:
49
- # - modify RAILS_ROOT/config/ferret_server.yml to suit your needs.
49
+ # - modify Rails.root/config/ferret_server.yml to suit your needs.
50
50
  # - environments for which no section in the config file exists will use
51
51
  # the index locally (good for unit tests/development mode)
52
52
  # - run script/ferret_server to start the server:
@@ -73,7 +73,7 @@ module ActsAsFerret
73
73
  ActiveRecord::Base.logger = @logger = Logger.new(@cfg.log_file)
74
74
  ActiveRecord::Base.logger.level = Logger.const_get(@cfg.log_level.upcase) rescue Logger::DEBUG
75
75
  if @cfg.script
76
- path = File.join(RAILS_ROOT, @cfg.script)
76
+ path = File.join(Rails.root, @cfg.script)
77
77
  load path
78
78
  @logger.info "loaded custom startup script from #{path}"
79
79
  end
@@ -82,14 +82,14 @@ module ActsAsFerret
82
82
  ################################################################################
83
83
  # start the server as a daemon process
84
84
  def start
85
- raise "ferret_server not configured for #{RAILS_ENV}" unless (@cfg.uri rescue nil)
85
+ raise "ferret_server not configured for #{Rails.env}" unless (@cfg.uri rescue nil)
86
86
  platform_daemon { run_drb_service }
87
87
  end
88
88
 
89
89
  ################################################################################
90
90
  # run the server and block until it exits
91
91
  def run
92
- raise "ferret_server not configured for #{RAILS_ENV}" unless (@cfg.uri rescue nil)
92
+ raise "ferret_server not configured for #{Rails.env}" unless (@cfg.uri rescue nil)
93
93
  run_drb_service
94
94
  end
95
95
 
@@ -103,7 +103,7 @@ module ActsAsFerret #:nodoc:
103
103
  end
104
104
  true # signal success to AR
105
105
  end
106
- def ferret_update; ferret_create end
106
+ alias :ferret_update :ferret_create
107
107
 
108
108
 
109
109
  # remove from index
@@ -17,11 +17,11 @@ OptionParser.new do |optparser|
17
17
  exit
18
18
  end
19
19
 
20
- optparser.on('-R', '--root=PATH', 'Set RAILS_ROOT to the given string') do |r|
20
+ optparser.on('-R', '--root=PATH', 'Set Rails.root to the given string') do |r|
21
21
  $ferret_server_options['root'] = r
22
22
  end
23
23
 
24
- optparser.on('-e', '--environment=NAME', 'Set RAILS_ENV to the given string') do |e|
24
+ optparser.on('-e', '--environment=NAME', 'Set Rails.env to the given string') do |e|
25
25
  $ferret_server_options['environment'] = e
26
26
  end
27
27
 
@@ -37,19 +37,32 @@ OptionParser.new do |optparser|
37
37
  end
38
38
 
39
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
+
40
52
  begin
41
53
  ENV['FERRET_USE_LOCAL_INDEX'] = 'true'
42
54
  ENV['RAILS_ENV'] = $ferret_server_options['environment']
43
-
44
55
  # determine RAILS_ROOT unless already set
45
- RAILS_ROOT = $ferret_server_options['root'] || File.join(File.dirname(__FILE__), *(['..']*4)) unless defined? RAILS_ROOT
46
- # check if environment.rb is present
47
- rails_env_file = File.join(RAILS_ROOT, 'config', 'environment')
48
- raise "Unable to find Rails environment.rb at \n#{rails_env_file}.rb\nPlease use the --root option of ferret_server to point it to your RAILS_ROOT." unless File.exists?(rails_env_file+'.rb')
49
- # load it
50
- require rails_env_file
51
-
52
- require 'acts_as_ferret'
56
+ Rails.root = determine_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'
53
66
  ActsAsFerret::Remote::Server.new.send($ferret_server_action)
54
67
  rescue Exception => e
55
68
  $stderr.puts(e.message)
data/lib/unix_daemon.rb CHANGED
@@ -13,7 +13,7 @@ module ActsAsFerret
13
13
  trap("TERM") { exit(0) }
14
14
  sess_id = Process.setsid
15
15
  STDIN.reopen("/dev/null")
16
- STDOUT.reopen("#{RAILS_ROOT}/log/ferret_server.out", "a")
16
+ STDOUT.reopen("#{Rails.root}/log/ferret_server.out", "a")
17
17
  STDERR.reopen(STDOUT)
18
18
  block.call
19
19
  end
File without changes
data/script/ferret_server CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ FERRET_SERVER = File.expand_path(__FILE__)
4
+
3
5
  begin
4
6
  require File.join(File.dirname(__FILE__), '../vendor/plugins/acts_as_ferret/lib/server_manager')
5
7
  rescue LoadError
metadata CHANGED
@@ -1,12 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_ferret
3
3
  version: !ruby/object:Gem::Version
4
+ hash: -428173559
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 4
8
- - 7
9
- version: 0.4.7
9
+ - 8
10
+ - rails3
11
+ version: 0.4.8.rails3
10
12
  platform: ruby
11
13
  authors:
12
14
  - Jens Kraemer
@@ -14,7 +16,7 @@ autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-07-06 13:50:00 +02:00
19
+ date: 2010-07-13 14:10:00 +02:00
18
20
  default_executable: aaf_install
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
@@ -24,6 +26,7 @@ dependencies:
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -167,7 +170,7 @@ files:
167
170
  - doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb
168
171
  - doc/monit-example
169
172
  - doc/README.win32
170
- - init.rb
173
+ - rails/init.rb
171
174
  - install.rb
172
175
  - lib/act_methods.rb
173
176
  - lib/acts_as_ferret.rb
@@ -213,6 +216,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
216
  requirements:
214
217
  - - ">="
215
218
  - !ruby/object:Gem::Version
219
+ hash: 3
216
220
  segments:
217
221
  - 0
218
222
  version: "0"
@@ -220,13 +224,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
224
  requirements:
221
225
  - - ">="
222
226
  - !ruby/object:Gem::Version
227
+ hash: 3
223
228
  segments:
224
229
  - 0
225
230
  version: "0"
226
231
  requirements: []
227
232
 
228
233
  rubyforge_project: acts_as_ferret
229
- rubygems_version: 1.3.6
234
+ rubygems_version: 1.3.7
230
235
  signing_key:
231
236
  specification_version: 3
232
237
  summary: acts_as_ferret - Ferret based full text search for any ActiveRecord model