diff --git a/CHANGELOG.md b/CHANGELOG.md index a2fdb47..78ea5a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Changelog for the gruf gem. This includes internal history before the gem was ma ### Pending release * [#190] Remove unsued `e2mmap` and `thwait` gems from `runtime_dependency`. +* [#194] Add interceptor to reload Rails app code accross requests ### 2.19.0 diff --git a/lib/gruf/configuration.rb b/lib/gruf/configuration.rb index ca12b3f..5d949ef 100644 --- a/lib/gruf/configuration.rb +++ b/lib/gruf/configuration.rb @@ -189,6 +189,9 @@ def reset self.use_default_interceptors = ::ENV.fetch('GRUF_USE_DEFAULT_INTERCEPTORS', 1).to_i.positive? if use_default_interceptors + if defined?(::Rails) + interceptors.use(::Gruf::Interceptors::Rails::Reloader, reloader: Rails.application.reloader) + end interceptors.use(::Gruf::Interceptors::ActiveRecord::ConnectionReset) interceptors.use(::Gruf::Interceptors::Instrumentation::OutputMetadataTimer) end diff --git a/lib/gruf/interceptors/rails/reloader.rb b/lib/gruf/interceptors/rails/reloader.rb new file mode 100644 index 0000000..57105c0 --- /dev/null +++ b/lib/gruf/interceptors/rails/reloader.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +module Gruf + module Interceptors + module Rails + ## + # Triggers rails code reloading between requests + # + class Reloader < ::Gruf::Interceptors::ServerInterceptor + def call(&block) + options[:reloader].wrap(&block) + end + end + end + end +end