karmi (owner)

Revisions

gist: 169035 Download_button fork
public
Public Clone URL: git://gist.github.com/169035.git
Embed All Files: show embed
friendly_message/init.rb #
1
2
3
# Include hook code here
ActionView::Base.send( :include, FriendlyMessage )
 
friendly_message/lib/friendly_message.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module FriendlyMessage
 
  LOGGER = defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new($stdout) unless defined?(LOGGER)
 
  module ClassMethods
  end
 
  module InstanceMethods
    def friendly_message
      "Hello, friend!"
    end
  end
 
  def self.included(receiver)
    LOGGER.info("Friendly message gets included")
    receiver.extend ClassMethods
    receiver.send :include, InstanceMethods
  end
end
 
plugin_reloading.patch #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
commit 4d7bbf81aa013d445a8ebf857d3ec60da4f61c04
Author: Karel Minarik <karmi@karmi.cz>
Date: Mon Aug 17 12:29:41 2009 +0200
 
    PLUGIN RELOADING IMPLEMENTATION
    
    1. We need to set "config.reload_plugins" in environment.rb, it makes no difference in development.rb
    2. We must delete plugin's "lib" folder from ActiveSupport::Dependencies.load_once_paths
    3. We must reload plugin's "init.rb" in controller (using before_filter)
 
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 6635a3f..f5ebf8e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -7,4 +7,13 @@ class ApplicationController < ActionController::Base
 
   # Scrub sensitive parameters from your log
   # filter_parameter_logging :password
+
+ before_filter :reload_plugin
+
+ private
+
+ # Force-load plugins init.rb file to include it's module Again
+ def reload_plugin
+ ActiveSupport::Dependencies.load_file Rails.root.join('vendor/plugins/friendly_message/init.rb').to_s
+ end
 end
diff --git a/config/environment.rb b/config/environment.rb
index 685505d..19585c1 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -38,4 +38,9 @@ Rails::Initializer.run do |config|
   # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
   # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
   # config.i18n.default_locale = :de
+
+ # Reload plugins, see http://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb#L763-779
+ config.reload_plugins = true
+ # Exclude plugin from paths loading only once
+ ActiveSupport::Dependencies.load_once_paths.delete Rails.root.join('vendor/plugins/friendly_message/lib')
 end
\ No newline at end of file
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 85c9a60..81ad49d 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -14,4 +14,9 @@ config.action_view.debug_rjs = true
 config.action_controller.perform_caching = false
 
 # Don't care if the mailer can't send
-config.action_mailer.raise_delivery_errors = false
\ No newline at end of file
+config.action_mailer.raise_delivery_errors = false
+
+# THIS DOES NOT MAKE A DIFFERENCE, must be in environment.rb
+# Reload plugins, see http://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb#L763-779
+# config.reload_plugins = true
+# ActiveSupport::Dependencies.load_once_paths.delete Rails.root.join('vendor/plugins/friendly_message/lib')
\ No newline at end of file