acts_as_ferret 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/README +32 -6
  2. data/acts_as_ferret.gemspec +260 -0
  3. data/config/ferret_server.yml +1 -0
  4. data/doc/demo/README +154 -0
  5. data/doc/demo/README_DEMO +23 -0
  6. data/doc/demo/Rakefile +10 -0
  7. data/doc/demo/app/controllers/admin/backend_controller.rb +14 -0
  8. data/doc/demo/app/controllers/admin_area_controller.rb +4 -0
  9. data/doc/demo/app/controllers/application.rb +5 -0
  10. data/doc/demo/app/controllers/contents_controller.rb +49 -0
  11. data/doc/demo/app/controllers/searches_controller.rb +8 -0
  12. data/doc/demo/app/helpers/admin/backend_helper.rb +2 -0
  13. data/doc/demo/app/helpers/application_helper.rb +3 -0
  14. data/doc/demo/app/helpers/content_helper.rb +2 -0
  15. data/doc/demo/app/helpers/search_helper.rb +2 -0
  16. data/doc/demo/app/models/comment.rb +48 -0
  17. data/doc/demo/app/models/content.rb +12 -0
  18. data/doc/demo/app/models/content_base.rb +28 -0
  19. data/doc/demo/app/models/search.rb +19 -0
  20. data/doc/demo/app/models/shared_index1.rb +3 -0
  21. data/doc/demo/app/models/shared_index2.rb +3 -0
  22. data/doc/demo/app/models/special_content.rb +3 -0
  23. data/doc/demo/app/models/stats.rb +20 -0
  24. data/doc/demo/app/views/admin/backend/search.rhtml +18 -0
  25. data/doc/demo/app/views/contents/_form.rhtml +10 -0
  26. data/doc/demo/app/views/contents/edit.rhtml +9 -0
  27. data/doc/demo/app/views/contents/index.rhtml +24 -0
  28. data/doc/demo/app/views/contents/new.rhtml +8 -0
  29. data/doc/demo/app/views/contents/show.rhtml +8 -0
  30. data/doc/demo/app/views/layouts/application.html.erb +17 -0
  31. data/doc/demo/app/views/searches/_content.html.erb +2 -0
  32. data/doc/demo/app/views/searches/search.html.erb +20 -0
  33. data/doc/demo/config/boot.rb +109 -0
  34. data/doc/demo/config/database.yml +38 -0
  35. data/doc/demo/config/environment.rb +69 -0
  36. data/doc/demo/config/environments/development.rb +16 -0
  37. data/doc/demo/config/environments/production.rb +19 -0
  38. data/doc/demo/config/environments/test.rb +21 -0
  39. data/doc/demo/config/ferret_server.yml +18 -0
  40. data/doc/demo/config/lighttpd.conf +40 -0
  41. data/doc/demo/config/routes.rb +9 -0
  42. data/doc/demo/db/development_structure.sql +15 -0
  43. data/doc/demo/db/migrate/001_initial_migration.rb +18 -0
  44. data/doc/demo/db/migrate/002_add_type_to_contents.rb +9 -0
  45. data/doc/demo/db/migrate/003_create_shared_index1s.rb +11 -0
  46. data/doc/demo/db/migrate/004_create_shared_index2s.rb +11 -0
  47. data/doc/demo/db/migrate/005_special_field.rb +9 -0
  48. data/doc/demo/db/migrate/006_create_stats.rb +15 -0
  49. data/doc/demo/db/schema.sql +18 -0
  50. data/doc/demo/doc/README_FOR_APP +2 -0
  51. data/doc/demo/doc/howto.txt +70 -0
  52. data/doc/demo/public/.htaccess +40 -0
  53. data/doc/demo/public/404.html +8 -0
  54. data/doc/demo/public/500.html +8 -0
  55. data/doc/demo/public/dispatch.cgi +10 -0
  56. data/doc/demo/public/dispatch.fcgi +24 -0
  57. data/doc/demo/public/dispatch.rb +10 -0
  58. data/doc/demo/public/favicon.ico +0 -0
  59. data/doc/demo/public/images/rails.png +0 -0
  60. data/doc/demo/public/index.html +277 -0
  61. data/doc/demo/public/robots.txt +1 -0
  62. data/doc/demo/public/stylesheets/scaffold.css +74 -0
  63. data/doc/demo/script/about +3 -0
  64. data/doc/demo/script/breakpointer +3 -0
  65. data/doc/demo/script/console +3 -0
  66. data/doc/demo/script/destroy +3 -0
  67. data/doc/demo/script/ferret_server +10 -0
  68. data/doc/demo/script/generate +3 -0
  69. data/doc/demo/script/performance/benchmarker +3 -0
  70. data/doc/demo/script/performance/profiler +3 -0
  71. data/doc/demo/script/plugin +3 -0
  72. data/doc/demo/script/process/inspector +3 -0
  73. data/doc/demo/script/process/reaper +3 -0
  74. data/doc/demo/script/process/spawner +3 -0
  75. data/doc/demo/script/process/spinner +3 -0
  76. data/doc/demo/script/runner +3 -0
  77. data/doc/demo/script/server +3 -0
  78. data/doc/demo/test/fixtures/comments.yml +12 -0
  79. data/doc/demo/test/fixtures/contents.yml +13 -0
  80. data/doc/demo/test/fixtures/remote_contents.yml +9 -0
  81. data/doc/demo/test/fixtures/shared_index1s.yml +7 -0
  82. data/doc/demo/test/fixtures/shared_index2s.yml +7 -0
  83. data/doc/demo/test/functional/admin/backend_controller_test.rb +35 -0
  84. data/doc/demo/test/functional/contents_controller_test.rb +81 -0
  85. data/doc/demo/test/functional/searches_controller_test.rb +71 -0
  86. data/doc/demo/test/smoke/drb_smoke_test.rb +321 -0
  87. data/doc/demo/test/smoke/process_stats.rb +21 -0
  88. data/doc/demo/test/test_helper.rb +30 -0
  89. data/doc/demo/test/unit/comment_test.rb +217 -0
  90. data/doc/demo/test/unit/content_test.rb +705 -0
  91. data/doc/demo/test/unit/ferret_result_test.rb +24 -0
  92. data/doc/demo/test/unit/multi_index_test.rb +329 -0
  93. data/doc/demo/test/unit/remote_index_test.rb +23 -0
  94. data/doc/demo/test/unit/shared_index1_test.rb +108 -0
  95. data/doc/demo/test/unit/shared_index2_test.rb +13 -0
  96. data/doc/demo/test/unit/sort_test.rb +21 -0
  97. data/doc/demo/test/unit/special_content_test.rb +25 -0
  98. data/doc/demo/vendor/plugins/will_paginate/LICENSE +18 -0
  99. data/doc/demo/vendor/plugins/will_paginate/README +108 -0
  100. data/doc/demo/vendor/plugins/will_paginate/Rakefile +23 -0
  101. data/doc/demo/vendor/plugins/will_paginate/init.rb +21 -0
  102. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +45 -0
  103. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +44 -0
  104. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +159 -0
  105. data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +95 -0
  106. data/doc/demo/vendor/plugins/will_paginate/test/array_pagination_test.rb +23 -0
  107. data/doc/demo/vendor/plugins/will_paginate/test/boot.rb +27 -0
  108. data/doc/demo/vendor/plugins/will_paginate/test/console +10 -0
  109. data/doc/demo/vendor/plugins/will_paginate/test/finder_test.rb +219 -0
  110. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
  111. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/companies.yml +24 -0
  112. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/company.rb +23 -0
  113. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
  114. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +13 -0
  115. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/project.rb +4 -0
  116. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/projects.yml +7 -0
  117. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/replies.yml +20 -0
  118. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
  119. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/schema.sql +44 -0
  120. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topic.rb +19 -0
  121. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topics.yml +30 -0
  122. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
  123. data/doc/demo/vendor/plugins/will_paginate/test/fixtures/users.yml +35 -0
  124. data/doc/demo/vendor/plugins/will_paginate/test/helper.rb +42 -0
  125. data/doc/demo/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +64 -0
  126. data/doc/demo/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +10 -0
  127. data/doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb +136 -0
  128. data/init.rb +2 -0
  129. data/lib/act_methods.rb +50 -157
  130. data/lib/acts_as_ferret.rb +457 -23
  131. data/lib/ar_mysql_auto_reconnect_patch.rb +41 -0
  132. data/lib/blank_slate.rb +53 -0
  133. data/lib/bulk_indexer.rb +4 -1
  134. data/lib/class_methods.rb +106 -295
  135. data/lib/ferret_extensions.rb +78 -5
  136. data/lib/ferret_find_methods.rb +141 -0
  137. data/lib/ferret_result.rb +26 -9
  138. data/lib/ferret_server.rb +100 -65
  139. data/lib/index.rb +83 -15
  140. data/lib/instance_methods.rb +32 -17
  141. data/lib/local_index.rb +106 -112
  142. data/lib/more_like_this.rb +13 -13
  143. data/lib/multi_index.rb +115 -72
  144. data/lib/rdig_adapter.rb +148 -0
  145. data/lib/remote_functions.rb +43 -0
  146. data/lib/remote_index.rb +25 -21
  147. data/lib/remote_multi_index.rb +20 -0
  148. data/lib/search_results.rb +7 -10
  149. data/lib/server_manager.rb +16 -4
  150. data/lib/unix_daemon.rb +23 -0
  151. data/lib/without_ar.rb +52 -0
  152. data/rakefile +23 -16
  153. data/recipes/aaf_recipes.rb +114 -0
  154. data/tasks/ferret.rake +22 -0
  155. metadata +233 -54
  156. data/lib/ferret_cap_tasks.rb +0 -21
  157. data/lib/shared_index.rb +0 -14
  158. data/lib/shared_index_class_methods.rb +0 -90
data/lib/remote_index.rb CHANGED
@@ -4,46 +4,50 @@ module ActsAsFerret
4
4
  # This index implementation connects to a remote ferret server instance. It
5
5
  # basically forwards all calls to the remote server.
6
6
  class RemoteIndex < AbstractIndex
7
+ include RemoteFunctions
7
8
 
8
9
  def initialize(config)
9
- @config = config
10
- @ferret_config = config[:ferret]
11
- @server = DRbObject.new(nil, config[:remote])
10
+ super
11
+ @server = DRbObject.new(nil, ActsAsFerret::remote)
12
+ end
13
+
14
+ # Cause model classes to be loaded (and indexes get declared) on the DRb
15
+ # side of things.
16
+ def register_class(clazz, options)
17
+ handle_drb_error { @server.register_class clazz.name }
12
18
  end
13
19
 
14
20
  def method_missing(method_name, *args)
15
- args.unshift model_class_name
16
- @server.send(method_name, *args)
21
+ args.unshift index_name
22
+ handle_drb_error { @server.send(method_name, *args) }
17
23
  end
18
24
 
19
- def find_id_by_contents(q, options = {}, &proc)
20
- total_hits, results = @server.find_id_by_contents(model_class_name, q, options)
21
- block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ]
25
+ # Proxy any methods that require special return values in case of errors
26
+ {
27
+ :highlight => []
28
+ }.each do |method_name, default_result|
29
+ define_method method_name do |*args|
30
+ args.unshift index_name
31
+ handle_drb_error(default_result) { @server.send method_name, *args }
32
+ end
22
33
  end
23
34
 
24
- def id_multi_search(query, models, options, &proc)
25
- total_hits, results = @server.id_multi_search(model_class_name, query, models, options)
35
+ def find_ids(q, options = {}, &proc)
36
+ total_hits, results = handle_drb_error([0, []]) { @server.find_ids(index_name, q, options) }
26
37
  block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ]
27
38
  end
28
39
 
29
40
  # add record to index
30
41
  def add(record)
31
- @server.add record.class.name, record.to_doc
42
+ handle_drb_error { @server.add index_name, record.to_doc }
32
43
  end
33
44
  alias << add
34
45
 
35
46
  private
36
47
 
37
- def yield_results(total_hits, results)
38
- results.each do |result|
39
- yield result[:model], result[:id], result[:score], result[:data]
40
- end
41
- total_hits
42
- end
43
-
44
- def model_class_name
45
- @config[:class_name]
46
- end
48
+ #def model_class_name
49
+ # index_definition[:class_name]
50
+ #end
47
51
 
48
52
  end
49
53
 
@@ -0,0 +1,20 @@
1
+ module ActsAsFerret
2
+ class RemoteMultiIndex < MultiIndexBase
3
+ include RemoteFunctions
4
+
5
+ def initialize(indexes, options = {})
6
+ @index_names = indexes.map(&:index_name)
7
+ @server = DRbObject.new(nil, ActsAsFerret::remote)
8
+ super
9
+ end
10
+
11
+ def find_ids(query, options, &proc)
12
+ total_hits, results = handle_drb_error([0, []]) { @server.multi_find_ids(@index_names, query, options) }
13
+ block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ]
14
+ end
15
+
16
+ def method_missing(name, *args)
17
+ handle_drb_error { @server.send(:"multi_#{name}", @index_names, *args) }
18
+ end
19
+ end
20
+ end
@@ -2,8 +2,11 @@ module ActsAsFerret
2
2
 
3
3
  # decorator that adds a total_hits accessor and will_paginate compatible
4
4
  # paging support to search result arrays
5
- class SearchResults
6
- attr_reader :current_page, :per_page, :total_hits
5
+ class SearchResults < ActsAsFerret::BlankSlate
6
+ reveal :methods
7
+ attr_reader :current_page, :per_page, :total_hits, :total_pages
8
+ alias total_entries total_hits # will_paginate compatibility
9
+ alias page_count total_pages # will_paginate backwards compatibility
7
10
 
8
11
  def initialize(results, total_hits, current_page = 1, per_page = nil)
9
12
  @results = results
@@ -18,18 +21,12 @@ module ActsAsFerret
18
21
  end
19
22
 
20
23
  def respond_to?(name)
21
- self.methods.include?(name) || @results.respond_to?(name)
24
+ methods.include?(name.to_s) || @results.respond_to?(name)
22
25
  end
23
26
 
24
27
 
25
28
  # code from here on was directly taken from will_paginate's collection.rb
26
29
 
27
- #
28
- # The total number of pages.
29
- def page_count
30
- @total_pages
31
- end
32
-
33
30
  # Current offset of the paginated collection. If we're on the first page,
34
31
  # it is always 0. If we're on the 2nd page and there are 30 entries per page,
35
32
  # the offset is 30. This property is useful if you want to render ordinals
@@ -46,7 +43,7 @@ module ActsAsFerret
46
43
 
47
44
  # current_page + 1 or nil if there is no next page
48
45
  def next_page
49
- current_page < page_count ? (current_page + 1) : nil
46
+ current_page < total_pages ? (current_page + 1) : nil
50
47
  end
51
48
  end
52
49
 
@@ -5,16 +5,21 @@ require 'optparse'
5
5
  $ferret_server_options = {
6
6
  'environment' => nil,
7
7
  'debug' => nil,
8
+ 'root' => nil
8
9
  }
9
10
 
10
11
  ################################################################################
11
12
  OptionParser.new do |optparser|
12
- optparser.banner = "Usage: #{File.basename($0)} [options] {start|stop}"
13
+ optparser.banner = "Usage: #{File.basename($0)} [options] {start|stop|run}"
13
14
 
14
15
  optparser.on('-h', '--help', "This message") do
15
16
  puts optparser
16
17
  exit
17
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
18
23
 
19
24
  optparser.on('-e', '--environment=NAME', 'Set RAILS_ENV to the given string') do |e|
20
25
  $ferret_server_options['environment'] = e
@@ -28,15 +33,22 @@ OptionParser.new do |optparser|
28
33
  (puts optparser; exit(1)) unless $ferret_server_action.size == 1
29
34
 
30
35
  $ferret_server_action = $ferret_server_action.first
31
- (puts optparser; exit(1)) unless %w(start stop).include?($ferret_server_action)
36
+ (puts optparser; exit(1)) unless %w(start stop run).include?($ferret_server_action)
32
37
  end
33
38
 
34
39
  ################################################################################
35
40
  begin
36
41
  ENV['FERRET_USE_LOCAL_INDEX'] = 'true'
37
42
  ENV['RAILS_ENV'] = $ferret_server_options['environment']
38
- #require(File.join(File.dirname(__FILE__), '../../../../config/environment'))
39
- require(File.join(File.dirname(ENV['_']), '../config/environment'))
43
+
44
+ # 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
+
40
52
  require 'acts_as_ferret'
41
53
  ActsAsFerret::Remote::Server.new.send($ferret_server_action)
42
54
  rescue Exception => e
data/lib/unix_daemon.rb CHANGED
@@ -49,6 +49,7 @@ module ActsAsFerret
49
49
  #################################################################################
50
50
  # create the PID file and install an at_exit handler
51
51
  def write_pid_file
52
+ ensure_stopped
52
53
  open(@cfg.pid_file, "w") {|f| f << Process.pid << "\n"}
53
54
  at_exit { File.unlink(@cfg.pid_file) if read_pid_file == Process.pid }
54
55
  end
@@ -58,6 +59,28 @@ module ActsAsFerret
58
59
  File.read(@cfg.pid_file).to_i if File.exist?(@cfg.pid_file)
59
60
  end
60
61
 
62
+ #################################################################################
63
+ def ensure_stopped
64
+ if pid = read_pid_file
65
+ if process_exists(pid)
66
+ raise "ferret_server may already be running, a pid file exists: #{@cfg.pid_file} and a ferret_server process exists with matching pid #{pid}"
67
+ else
68
+ $stdout.puts("removing stale pid file...")
69
+ File.unlink(@cfg.pid_file) if File.exist?(@cfg.pid_file)
70
+ end
71
+ end
72
+ end
73
+
74
+ #################################################################################
75
+ # Check for existence of ferret_server process with PID from pid file
76
+ # checked on ubuntu and OSX only
77
+ def process_exists(pid)
78
+ ps = IO.popen("ps -fp #{pid}", "r")
79
+ process = ps.to_a[1]
80
+ ps.close
81
+ process =~ /ferret_server/
82
+ end
83
+
61
84
  end
62
85
  end
63
86
  end
data/lib/without_ar.rb ADDED
@@ -0,0 +1,52 @@
1
+ module ActsAsFerret
2
+
3
+ # Include this module to use acts_as_ferret with model classes
4
+ # not based on ActiveRecord.
5
+ #
6
+ # Implement the find_for_id(id) class method in your model class in
7
+ # order to make search work.
8
+ module WithoutAR
9
+ def self.included(target)
10
+ target.extend ClassMethods
11
+ target.extend ActsAsFerret::ActMethods
12
+ target.send :include, InstanceMethods
13
+ end
14
+
15
+ module ClassMethods
16
+ def logger
17
+ RAILS_DEFAULT_LOGGER
18
+ end
19
+ def table_name
20
+ self.name.underscore
21
+ end
22
+ def primary_key
23
+ 'id'
24
+ end
25
+ def find(what, args = {})
26
+ case what
27
+ when :all
28
+ ids = args[:conditions][1]
29
+ ids.map { |id| find id }
30
+ else
31
+ find_for_id what
32
+ end
33
+ end
34
+ def find_for_id(id)
35
+ raise NotImplementedError.new("implement find_for_id in class #{self.name}")
36
+ end
37
+ def count
38
+ 0
39
+ end
40
+ end
41
+
42
+ module InstanceMethods
43
+ def logger
44
+ self.class.logger
45
+ end
46
+ def new_record?
47
+ false
48
+ end
49
+ end
50
+ end
51
+
52
+ end
data/rakefile CHANGED
@@ -4,6 +4,8 @@
4
4
  # RELEASE creation:
5
5
  # rake release REL=x.y.z
6
6
 
7
+ require 'pathname'
8
+ require 'yaml'
7
9
  require 'rake'
8
10
  require 'rake/rdoctask'
9
11
  require 'rake/packagetask'
@@ -55,7 +57,7 @@ if PKG_VERSION
55
57
  s.platform = Gem::Platform::RUBY
56
58
  s.summary = "acts_as_ferret - Ferret based full text search for any ActiveRecord model"
57
59
  s.files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |f|
58
- [ /\.$/, /sqlite$/, /\.log$/, /^pkg/, /\.svn/, /\.\w+\.sw.$/,
60
+ [ /\.$/, /sqlite$/, /\.log$/, /^pkg/, /\.svn/, /\.git/, /\.\w+\.sw.$/,
59
61
  /^html/, /\~$/, /\/\._/, /\/#/ ].any? {|regex| f =~ regex }
60
62
  end
61
63
  #s.files = FileList["{lib,test}/**/*"].to_a + %w(README MIT-LICENSE CHANGELOG)
@@ -71,6 +73,11 @@ if PKG_VERSION
71
73
  s.email = "jk@jkraemer.net"
72
74
  s.homepage = "http://projects.jkraemer.net/acts_as_ferret"
73
75
  end
76
+
77
+ desc "Update the gemspec for GitHub's gem server"
78
+ task :gemspec do
79
+ Pathname("#{spec.name}.gemspec").open('w') {|f| f << YAML.dump(spec) }
80
+ end
74
81
 
75
82
  package_task = Rake::GemPackageTask.new(spec) do |pkg|
76
83
  pkg.need_tar = true
@@ -83,21 +90,21 @@ if PKG_VERSION
83
90
  announce "* Making RubyGem Release #{PKG_VERSION}"
84
91
  announce "**************************************************************"
85
92
  announce
86
- # Are all source files checked in?
87
- if ENV['RELTEST']
88
- announce "Release Task Testing, skipping checked-in file test"
89
- else
90
- announce "Pulling in svn..."
91
- `svk pull .`
92
- announce "Checking for unchecked-in files..."
93
- data = `svk st`
94
- unless data =~ /^$/
95
- fail "SVK status is not clean ... do you have unchecked-in files?"
96
- end
97
- announce "No outstanding checkins found ... OK"
98
- # announce "Pushing to svn..."
99
- # `svk push .`
100
- end
93
+ # # Are all source files checked in?
94
+ # if ENV['RELTEST']
95
+ # announce "Release Task Testing, skipping checked-in file test"
96
+ # else
97
+ # announce "Pulling in svn..."
98
+ # `svk pull .`
99
+ # announce "Checking for unchecked-in files..."
100
+ # data = `svk st`
101
+ # unless data =~ /^$/
102
+ # fail "SVK status is not clean ... do you have unchecked-in files?"
103
+ # end
104
+ # announce "No outstanding checkins found ... OK"
105
+ # # announce "Pushing to svn..."
106
+ # # `svk push .`
107
+ # end
101
108
  end
102
109
 
103
110
 
@@ -0,0 +1,114 @@
1
+ # Ferret DRb server Capistrano tasks
2
+ #
3
+ # Usage:
4
+ # in your Capfile, add acts_as_ferret's recipes directory to your load path and
5
+ # load the ferret tasks:
6
+ #
7
+ # load_paths << 'vendor/plugins/acts_as_ferret/recipes'
8
+ # load 'aaf_recipes'
9
+ #
10
+ # This will hook aaf's DRb start/stop tasks into the standard
11
+ # deploy:{start|restart|stop} tasks so the server will be restarted along with
12
+ # the rest of your application.
13
+ # Also an index directory in the shared folder will be created and symlinked
14
+ # into current/ when you deploy.
15
+ #
16
+ # In order to use the ferret:index:rebuild task, declare the indexes you intend to
17
+ # rebuild remotely in config/deploy.rb:
18
+ #
19
+ # set :ferret_indexes, %w( model another_model shared )
20
+ #
21
+ # HINT: To be very sure that your DRb server and application are always using
22
+ # the same model and schema versions, and you never lose any index updates because
23
+ # of the DRb server being restarted in that moment, use the following sequence
24
+ # to update your application:
25
+ #
26
+ # cap deploy:stop deploy:update deploy:migrate deploy:start
27
+ #
28
+ # That will stop the DRb server after stopping your application, and bring it
29
+ # up before starting the application again. Plus they'll never use different
30
+ # versions of model classes (which might happen otherwise)
31
+ # Downside: Your downtime is a bit longer than with the usual deploy, so be sure to
32
+ # put up some maintenance page for the meantime. Obviously this won't work if
33
+ # your migrations need acts_as_ferret (i.e. if you update model instances which
34
+ # would lead to index updates). In this case bring up the DRb server before
35
+ # running your migrations:
36
+ #
37
+ # cap deploy:stop deploy:update ferret:start deploy:migrate ferret:stop deploy:start
38
+ #
39
+ # Chances are that you're still not safe if your migrations not only modify the index,
40
+ # but also change the structure of your models. So just don't do both things in
41
+ # one go - I can't think of an easy way to handle this case automatically.
42
+ # Suggestions and patches are of course very welcome :-)
43
+
44
+ namespace :ferret do
45
+
46
+ desc "Stop the Ferret DRb server"
47
+ task :stop, :roles => :app do
48
+ rails_env = fetch(:rails_env, 'production')
49
+ run "cd #{current_path}; script/ferret_server -e #{rails_env} stop || true"
50
+ end
51
+
52
+ desc "Start the Ferret DRb server"
53
+ task :start, :roles => :app do
54
+ rails_env = fetch(:rails_env, 'production')
55
+ run "cd #{current_path}; script/ferret_server -e #{rails_env} start"
56
+ end
57
+
58
+ desc "Restart the Ferret DRb server"
59
+ task :restart, :roles => :app do
60
+ top.ferret.stop
61
+ sleep 1
62
+ top.ferret.start
63
+ end
64
+
65
+ namespace :index do
66
+
67
+ desc "Rebuild the Ferret index. See aaf_recipes.rb for instructions."
68
+ task :rebuild, :roles => :app do
69
+ rake = fetch(:rake, 'rake')
70
+ rails_env = fetch(:rails_env, 'production')
71
+ indexes = fetch(:ferret_indexes, [])
72
+ if indexes.any?
73
+ run "cd #{current_path}; RAILS_ENV=#{rails_env} INDEXES='#{indexes.join(' ')}' #{rake} ferret:rebuild"
74
+ end
75
+ end
76
+
77
+ desc "purges all indexes for the current environment"
78
+ task :purge, :roles => :app do
79
+ run "rm -fr #{shared_path}/index/#{rails_env}"
80
+ end
81
+
82
+ desc "symlinks index folder"
83
+ task :symlink, :roles => :app do
84
+ run "mkdir -p #{shared_path}/index && rm -rf #{release_path}/index && ln -nfs #{shared_path}/index #{release_path}/index"
85
+ end
86
+
87
+ desc "Clean up old index versions"
88
+ task :cleanup, :roles => :app do
89
+ indexes = fetch(:ferret_indexes, [])
90
+ indexes.each do |index|
91
+ ferret_index_path = "#{shared_path}/index/#{rails_env}/#{index}"
92
+ releases = capture("ls -x #{ferret_index_path}").split.sort
93
+ count = 2
94
+ if count >= releases.length
95
+ logger.important "no old indexes to clean up"
96
+ else
97
+ logger.info "keeping #{count} of #{releases.length} indexes"
98
+ directories = (releases - releases.last(count)).map { |release|
99
+ File.join(ferret_index_path, release) }.join(" ")
100
+ sudo "rm -rf #{directories}"
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ after "deploy:stop", "ferret:stop"
109
+ before "deploy:start", "ferret:start"
110
+
111
+ before "deploy:restart", "ferret:stop"
112
+ after "deploy:restart", "ferret:start"
113
+ after "deploy:symlink", "ferret:index:symlink"
114
+