diff --git a/Gemfile.lock b/Gemfile.lock index 65d939ff..4b8ba2f9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,7 +84,6 @@ PATH dry-configurable (> 0.1, <= 7.0) dry-container (~> 0.6) dry-inflector (~> 0.1) - filewatcher (~> 1.1.1) ice_nine (~> 0.11) redcarpet (~> 3.4) sinatra (>= 1.4, < 3.0) @@ -111,8 +110,6 @@ GEM dry-core (0.6.0) concurrent-ruby (~> 1.0) dry-inflector (0.2.0) - filewatcher (1.1.1) - optimist (~> 3.0) ice_nine (0.11.2) json (2.3.1) method_source (0.9.0) @@ -125,7 +122,6 @@ GEM racc (~> 1.4) nokogiri (1.11.7-x86_64-darwin) racc (~> 1.4) - optimist (3.0.1) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) diff --git a/coprl.gemspec b/coprl.gemspec index 2bd865d3..2fcb6a31 100644 --- a/coprl.gemspec +++ b/coprl.gemspec @@ -28,7 +28,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'tzinfo', '>=1.1', '< 3.0' spec.add_runtime_dependency 'tzinfo-data', '~>1.2018' spec.add_runtime_dependency 'redcarpet', '~>3.4' - spec.add_runtime_dependency 'filewatcher', '~> 1.1.1' spec.add_runtime_dependency 'zeitwerk', '~> 2.1' spec.add_development_dependency 'thor', '~> 1.1.0' diff --git a/lib/coprl/presenters/rails/railtie.rb b/lib/coprl/presenters/rails/railtie.rb index d457a629..845c0659 100644 --- a/lib/coprl/presenters/rails/railtie.rb +++ b/lib/coprl/presenters/rails/railtie.rb @@ -1,5 +1,3 @@ -require 'filewatcher' - module Coprl module Presenters module Rails @@ -15,20 +13,14 @@ class Railtie < ::Rails::Railtie WATCH = -> { return unless ::Rails.env.development? + path = ::Rails.root.join('app', '**', '*.pom') - puts "Watching #{path} for changes..." - filewatcher = Filewatcher.new(path) - Thread.new(filewatcher) do |fw| - fw.watch do |f| - puts "Detected updated POM file: #{f}" - begin - BOOT.call - rescue Exception => exc - puts exc.backtrace - puts exc.message - end - end + file_watcher = ActiveSupport::FileUpdateChecker.new(Dir[path]) do + BOOT.call end + + ::Rails.application.reloaders << Reloader.new(file_watcher) + } unless defined?(WATCH) config.after_initialize do diff --git a/lib/coprl/presenters/rails/reloader.rb b/lib/coprl/presenters/rails/reloader.rb new file mode 100644 index 00000000..fc62a4e8 --- /dev/null +++ b/lib/coprl/presenters/rails/reloader.rb @@ -0,0 +1,15 @@ +module Coprl + module Presenters + module Rails + class Reloader + def initialize(file_watcher) + @file_watcher = file_watcher + end + + def updated? + @file_watcher.execute_if_updated + end + end + end + end +end