reloader_interceptor 0.0.1

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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f38b4d1966eb68ac82bb3f0e2a54b0f3838aae47b3b0ebd63dbd1cda4595a680
4
+ data.tar.gz: f039be6691bf07498be7a7828398ffae6975df1a2eced716df74e29e0294bd1a
5
+ SHA512:
6
+ metadata.gz: ff4697f459848a0c520c98c42b9910cd3f2d6d800fd95675840db70dea7ec33ccb931a742ab0daad0b27999dc3f51e0c969e060d14123ffa6d7c4aa097eca1af
7
+ data.tar.gz: 2e717dc1d1df328f50b3267217690ac322fa35288acd5703f5f06bd54ee9c7d0f87bc34d25b5066ec47d509e03ef4ff3a04bd6fed4cb87809097740adaee594b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at south37777@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in reloader_interceptor.gemspec
4
+ gemspec
5
+
6
+ gem "pry"
7
+ gem "rake", "~> 12.0"
8
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reloader_interceptor (0.0.1)
5
+ activesupport
6
+ grpc
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.3.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ coderay (1.1.3)
18
+ concurrent-ruby (1.1.7)
19
+ diff-lcs (1.4.4)
20
+ google-protobuf (3.13.0)
21
+ googleapis-common-protos-types (1.0.5)
22
+ google-protobuf (~> 3.11)
23
+ grpc (1.31.1)
24
+ google-protobuf (~> 3.12)
25
+ googleapis-common-protos-types (~> 1.0)
26
+ i18n (1.8.5)
27
+ concurrent-ruby (~> 1.0)
28
+ method_source (1.0.0)
29
+ minitest (5.14.2)
30
+ pry (0.13.1)
31
+ coderay (~> 1.1)
32
+ method_source (~> 1.0)
33
+ rake (12.3.3)
34
+ rspec (3.9.0)
35
+ rspec-core (~> 3.9.0)
36
+ rspec-expectations (~> 3.9.0)
37
+ rspec-mocks (~> 3.9.0)
38
+ rspec-core (3.9.2)
39
+ rspec-support (~> 3.9.3)
40
+ rspec-expectations (3.9.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-mocks (3.9.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-support (3.9.3)
47
+ thread_safe (0.3.6)
48
+ tzinfo (1.2.7)
49
+ thread_safe (~> 0.1)
50
+ zeitwerk (2.4.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ pry
57
+ rake (~> 12.0)
58
+ reloader_interceptor!
59
+ rspec (~> 3.0)
60
+
61
+ BUNDLED WITH
62
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Nao Minami
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # ReloaderInterceptor
2
+
3
+ A gRPC interceptor for using [ActiveSupport::Reloader](https://guides.rubyonrails.org/threading_and_code_execution.html#reloader).
4
+
5
+ This gem enables hot-reloading feature when used with Ruby on Rails.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'reloader_interceptor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install reloader_interceptor
22
+
23
+ ## Usage
24
+
25
+ If you use this gem with Ruby on Rails, I recommend you to write the code like this. This code also uses [grpc_server](https://github.com/south37/grpc_server).
26
+
27
+ ```ruby
28
+ # Initialization of rails here
29
+ APP_PATH = File.expand_path('./config/application', Dir.pwd)
30
+ require './config/boot'
31
+ require 'rails'
32
+ require './config/environment'
33
+
34
+ # Setup ReloaderInterceptor
35
+ require "reloader_interceptor"
36
+ ReloaderInterceptor.enabled = Rails.env.development? # Enable only in development
37
+
38
+ # Setup gRPC server
39
+ require "grpc_server"
40
+ server = GrpcServer.new(
41
+ port: 3000,
42
+ threads: 30,
43
+ interceptors: [
44
+ ReloaderInterceptor::ServerInterceptor.new(
45
+ reloader: Rails.application.reloader
46
+ ) # Set interceptor here
47
+ ]
48
+ )
49
+ server.set_handler(
50
+ ReloaderInterceptor::Wrapper.wrap(XXX) # Wrap gRPC service here
51
+ )
52
+ server.run
53
+ ```
54
+
55
+ ## Architecture
56
+ There are 2 components in `ReloaderInterceptor`.
57
+
58
+ ### `ReloaderInterceptor::Wrapper`
59
+
60
+ `Reloaderinterceptor::Wrapper` is used to wrap the original gRPC server class. For using [ActiveSupport::Reloader](https://guides.rubyonrails.org/threading_and_code_execution.html#reloader), gRPC server classes must be accessed by its name. `Wrapper` enables this.
61
+
62
+ ### `ReloaderInterceptor::ServerInterceptor`
63
+
64
+ `ReloaderInterceptor::ServerInterceptor` is used to intercept each gRPC request. If code is changed, then constants are automatically erased in each request. You should set up an autoload environment by using [Zeitwork](https://github.com/fxn/zeitwerk) or [Ruby on Rails](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html).
65
+
66
+ ## Development
67
+
68
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
69
+
70
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/south37/reloader_interceptor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/south37/reloader_interceptor/blob/master/CODE_OF_CONDUCT.md).
75
+
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
80
+
81
+ ## Code of Conduct
82
+
83
+ Everyone interacting in the ReloaderInterceptor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/south37/reloader_interceptor/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "reloader_interceptor"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "pry"
10
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ require_relative "./reloader_interceptor/version"
2
+ require_relative "./reloader_interceptor/server_interceptor"
3
+ require_relative "./reloader_interceptor/wrapper"
4
+
5
+ module ReloaderInterceptor
6
+ @enabled = true # Enabled by default
7
+
8
+ class << self
9
+ def enabled?
10
+ @enabled
11
+ end
12
+
13
+ def enable!
14
+ @enabled = true
15
+ end
16
+
17
+ def disable!
18
+ @enabled = false
19
+ end
20
+
21
+ attr_writer :enabled
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require "grpc"
2
+
3
+ module ReloaderInterceptor
4
+ class ServerInterceptor < GRPC::ServerInterceptor
5
+ def initialize(reloader:)
6
+ @reloader = reloader
7
+ end
8
+
9
+ def request_response(request:, call:, method:, &block)
10
+ return yield unless ReloaderInterceptor.enabled?
11
+
12
+ @reloader.wrap do
13
+ yield
14
+ end
15
+ end
16
+
17
+ # NOTE: For now, we don't support server_streamer, client_streamer and bidi_streamer
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module ReloaderInterceptor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,79 @@
1
+ require "active_support/core_ext"
2
+
3
+ module ReloaderInterceptor
4
+ class Wrapper
5
+ module DSL
6
+ # @param [Class] dst Wrapping class
7
+ # @param [String] src Wrapped class
8
+ def define_singleton_methods_using_class_name(dst, src)
9
+ src_name = src.name
10
+
11
+ src_singleton_class = src.singleton_class
12
+ dst_singleton_class = dst.singleton_class
13
+
14
+ public_methods = src_singleton_class.public_instance_methods(false)
15
+ protected_methods = src_singleton_class.protected_instance_methods(false)
16
+ private_methods = src_singleton_class.private_instance_methods(false)
17
+
18
+ [*public_methods, *protected_methods, *private_methods].each do |method|
19
+ dst_singleton_class.define_method method do |*args|
20
+ klass = src_name.constantize
21
+ klass.send(method, *args)
22
+ end
23
+ end
24
+
25
+ dst_singleton_class.send(:protected, *protected_methods) if protected_methods.size > 0
26
+ dst_singleton_class.send(:private, *private_methods) if private_methods.size > 0
27
+ end
28
+
29
+ # @param [Class] dst Wrapping class
30
+ # @param [String] src Wrapped class
31
+ def define_instance_methods_using_class_name(dst, src)
32
+ src_name = src.name
33
+
34
+ public_methods = src.public_instance_methods(false)
35
+ protected_methods = src.protected_instance_methods(false)
36
+ private_methods = src.private_instance_methods(false)
37
+
38
+ [*public_methods, *protected_methods, *private_methods].each do |method|
39
+ dst.define_method method do |*args|
40
+ klass = src_name.constantize
41
+ klass.new(*@options).send(method, *args)
42
+ end
43
+ end
44
+
45
+ dst.send(:protected, *protected_methods) if protected_methods.size > 0
46
+ dst.send(:private, *private_methods) if private_methods.size > 0
47
+ end
48
+ end
49
+
50
+ class << self
51
+ # @param [Class] klass An original class.
52
+ # @return [Class] A wrapping class. Return the original one if
53
+ # `ReloaderInterceptor` is disabled.
54
+ def wrap(klass)
55
+ return klass unless ReloaderInterceptor.enabled?
56
+
57
+ klass_name = klass.name
58
+ Class.new(klass.superclass) do
59
+ extend Wrapper::DSL
60
+
61
+ # Define `.name` and `.inspect` to mimic the original class.
62
+ self.define_singleton_method :name do
63
+ klass_name
64
+ end
65
+ self.define_singleton_method :inspect do
66
+ klass_name
67
+ end
68
+
69
+ def initialize(*options)
70
+ @options = options
71
+ end
72
+
73
+ define_instance_methods_using_class_name(self, klass)
74
+ define_singleton_methods_using_class_name(self, klass)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/reloader_interceptor/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "reloader_interceptor"
5
+ spec.version = ReloaderInterceptor::VERSION
6
+ spec.authors = ["Nao Minami"]
7
+ spec.email = ["south37777@gmail.com"]
8
+
9
+ spec.summary = %q{A gRPC interceptor for using ActiveSupport::Reloader.}
10
+ spec.description = %q{A gRPC interceptor for using ActiveSupport::Reloader.}
11
+ spec.homepage = "https://github.com/south37/reloader_interceptor"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/south37/reloader_interceptor"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_runtime_dependency "grpc"
28
+ spec.add_runtime_dependency "activesupport"
29
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reloader_interceptor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nao Minami
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A gRPC interceptor for using ActiveSupport::Reloader.
42
+ email:
43
+ - south37777@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/reloader_interceptor.rb
60
+ - lib/reloader_interceptor/server_interceptor.rb
61
+ - lib/reloader_interceptor/version.rb
62
+ - lib/reloader_interceptor/wrapper.rb
63
+ - reloader_interceptor.gemspec
64
+ homepage: https://github.com/south37/reloader_interceptor
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ homepage_uri: https://github.com/south37/reloader_interceptor
69
+ source_code_uri: https://github.com/south37/reloader_interceptor
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.3.0
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.0.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A gRPC interceptor for using ActiveSupport::Reloader.
89
+ test_files: []