Skip to content

Commit

Permalink
add a code reload interceptor for rails
Browse files Browse the repository at this point in the history
  • Loading branch information
ximus committed Feb 20, 2024
1 parent f40f022 commit 8519631
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/gruf/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions lib/gruf/interceptors/rails/reloader.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8519631

Please sign in to comment.