active_reload 0.0.1 → 0.1.0

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.
@@ -0,0 +1,58 @@
1
+ h1. Active Reload
2
+
3
+ Active Reload is a gem that changes a little when Rails code reloading is executed.
4
+ Normally Rails "forgets" your code after every request in development mode and loads again necessary
5
+ files during the request. If your application is big this can take lot of time especially on "dashboard" page
6
+ that uses lot of different classes.
7
+
8
+ However this constant reloading is not always necessary. This gem changes it so it occurs
9
+ before request and only when file was changed or added. It won't make reloading your app
10
+ faster but it will skip reloading when nothing changed and that saved second can really sum
11
+ up to a big value. It means that after change first request in development mode will reload the code
12
+ and take as much time as it takes without this gem but subsequent request will be faster until next
13
+ changes due to lack of code reloading.
14
+
15
+ h2. Installation
16
+
17
+ Simply add Active Reload to your Gemfile and bundle it up:
18
+
19
+ <pre>
20
+ gem 'active_reload'
21
+ </pre>
22
+
23
+ h2. Compatibility
24
+
25
+ It was hand tested only with Rails 3.0.9 but should work without any problem on any 3.0.* version.
26
+ Expect 3.1.* support soon :-) !
27
+
28
+ h2. Notifications
29
+
30
+ You can subscribe to two notifications provided by this gem.
31
+
32
+ @active_reload.set_clear_dependencies_hook_replaced@ event is triggered when the gem changes original rails hook for code reloading.
33
+
34
+ <pre>
35
+
36
+ ActiveSupport::Notifications.subscribe("active_reload.set_clear_dependencies_hook_replaced") do |*args|
37
+ event = ActiveSupport::Notifications::Event.new(*args)
38
+ msg = event.name
39
+ # Ubuntu: https://github.com/splattael/libnotify, Example: Libnotify.show(:body => msg, :summary => Rails.application.class.name, :timeout => 2.5, :append => true)
40
+ # Macos: http://segment7.net/projects/ruby/growl/
41
+ puts Rails.logger.warn(" --- #{msg} --- ")
42
+ end
43
+
44
+ </pre>
45
+
46
+ @active_support.dependencies.clear@ event is triggered when code reloading is triggered by this gem.
47
+
48
+ <pre>
49
+
50
+ ActiveSupport::Notifications.subscribe("active_support.dependencies.clear") do |*args|
51
+ msg = "Code reloaded!"
52
+ # Ubuntu: https://github.com/splattael/libnotify, Example: Libnotify.show(:body => msg, :summary => Rails.application.class.name, :timeout => 2.5, :append => true)
53
+ # Macos: http://segment7.net/projects/ruby/growl/
54
+ puts Rails.logger.info(" --- #{msg} --- ")
55
+ end
56
+
57
+ </pre>
58
+
@@ -1,5 +1,53 @@
1
1
  require "active_reload/version"
2
2
 
3
3
  module ActiveReload
4
- # Your code goes here...
4
+
5
+ class Railtie < ::Rails::Railtie
6
+ initializer :'active_reload.set_clear_dependencies_hook', :after => :set_clear_dependencies_hook do
7
+ ActiveReload.replace!
8
+ end
9
+ end # Railtie
10
+
11
+ def self.replace?
12
+ !Rails.application.config.cache_classes && replace_proc?(ActionDispatch::Callbacks.instance_variable_get(:@_call_callbacks).last)
13
+ end
14
+
15
+ def self.replace_proc?(last)
16
+ last.respond_to?(:raw_filter) &&
17
+ last.raw_filter.is_a?(Proc) &&
18
+ last.raw_filter.source_location.first.match( Regexp.new("railties.*/lib/rails/application/bootstrap.rb") )
19
+ end
20
+
21
+ def self.replace!
22
+ return unless replace?
23
+
24
+ ActiveSupport::Notifications.instrument("active_reload.set_clear_dependencies_hook_replaced") do
25
+
26
+ changed_at = Proc.new do
27
+ ActiveSupport::Dependencies.autoload_paths.map do |p|
28
+ Dir["#{p}/**/*.rb"].map{|f| File.mtime(f) }
29
+ end.flatten.max
30
+ end
31
+
32
+ last_change = Time.now
33
+
34
+ replace_proc do
35
+ change = changed_at.call
36
+ if change > last_change
37
+ last_change = change
38
+ ActiveSupport::Notifications.instrument("active_support.dependencies.clear") do
39
+ ActiveSupport::DescendantsTracker.clear
40
+ ActiveSupport::Dependencies.clear
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.replace_proc(&new)
48
+ replaced = ActionDispatch::Callbacks.instance_variable_get(:@_call_callbacks).pop
49
+ ActionDispatch::Callbacks.before(&new)
50
+ end
51
+
52
+
5
53
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveReload
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_reload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &77247640 !ruby/object:Gem::Requirement
17
+ requirement: &79278680 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *77247640
25
+ version_requirements: *79278680
26
26
  description: Reload Rails code in development mode only when change is deteced
27
27
  email:
28
28
  - robert.pankowecki@gmail.com
@@ -32,6 +32,7 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - .gitignore
34
34
  - Gemfile
35
+ - README.textile
35
36
  - Rakefile
36
37
  - active_reload.gemspec
37
38
  - lib/active_reload.rb
@@ -51,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
52
  version: '0'
52
53
  segments:
53
54
  - 0
54
- hash: 1016503411
55
+ hash: -820515487
55
56
  required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  none: false
57
58
  requirements:
@@ -60,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  version: '0'
61
62
  segments:
62
63
  - 0
63
- hash: 1016503411
64
+ hash: -820515487
64
65
  requirements: []
65
66
  rubyforge_project: active_reload
66
67
  rubygems_version: 1.6.2