rails_grpc 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: acc0ad828c933fd0f0ae43e535227444abc7dc4d9ce5217ac0c0137620e65488
4
+ data.tar.gz: dee6ef08887455e08f66d8e5d694edf39e90199f68e5bac38c4a28a5d4bf154d
5
+ SHA512:
6
+ metadata.gz: 3a6d38a83f247d78a53b00e0377465b349b50d8c1b6164acebdf3eac395bd154880afbb3d4ccb3b2c280dd86d81d16e37ce3012273bbdbee032146327d32ec04
7
+ data.tar.gz: bac414c21a83a38125052dabea4f0eb28041fe5ee03e9b7e03e62a4278d19b885d6d117faf742409ca2b1421c5bf54127e6745a2e04c3dba3b7029793c0ec06c
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -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 nishio@densan-labs.net. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
6
+
7
+ gem "google-protobuf", git: "git@github.com:nishio-dens/protobuf.git", branch: "rails-grpc", glob: "ruby/google-protobuf.gemspec"
8
+
9
+ group :development, :test do
10
+ gem "pry"
11
+ gem "pry-doc"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,174 @@
1
+ GIT
2
+ remote: git@github.com:nishio-dens/protobuf.git
3
+ revision: b4f6ee826ddd98e96e29ceef586843e8e219bca0
4
+ branch: rails-grpc
5
+ glob: ruby/google-protobuf.gemspec
6
+ specs:
7
+ google-protobuf (3.6.0)
8
+
9
+ PATH
10
+ remote: .
11
+ specs:
12
+ rails_grpc (0.1.0)
13
+ grpc
14
+ protobuf
15
+ rails
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ actioncable (5.2.0)
21
+ actionpack (= 5.2.0)
22
+ nio4r (~> 2.0)
23
+ websocket-driver (>= 0.6.1)
24
+ actionmailer (5.2.0)
25
+ actionpack (= 5.2.0)
26
+ actionview (= 5.2.0)
27
+ activejob (= 5.2.0)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 2.0)
30
+ actionpack (5.2.0)
31
+ actionview (= 5.2.0)
32
+ activesupport (= 5.2.0)
33
+ rack (~> 2.0)
34
+ rack-test (>= 0.6.3)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
37
+ actionview (5.2.0)
38
+ activesupport (= 5.2.0)
39
+ builder (~> 3.1)
40
+ erubi (~> 1.4)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
43
+ activejob (5.2.0)
44
+ activesupport (= 5.2.0)
45
+ globalid (>= 0.3.6)
46
+ activemodel (5.2.0)
47
+ activesupport (= 5.2.0)
48
+ activerecord (5.2.0)
49
+ activemodel (= 5.2.0)
50
+ activesupport (= 5.2.0)
51
+ arel (>= 9.0)
52
+ activestorage (5.2.0)
53
+ actionpack (= 5.2.0)
54
+ activerecord (= 5.2.0)
55
+ marcel (~> 0.3.1)
56
+ activesupport (5.2.0)
57
+ concurrent-ruby (~> 1.0, >= 1.0.2)
58
+ i18n (>= 0.7, < 2)
59
+ minitest (~> 5.1)
60
+ tzinfo (~> 1.1)
61
+ arel (9.0.0)
62
+ builder (3.2.3)
63
+ coderay (1.1.2)
64
+ concurrent-ruby (1.0.5)
65
+ crass (1.0.4)
66
+ diff-lcs (1.3)
67
+ erubi (1.7.1)
68
+ globalid (0.4.1)
69
+ activesupport (>= 4.2.0)
70
+ googleapis-common-protos-types (1.0.2)
71
+ google-protobuf (~> 3.0)
72
+ grpc (1.14.1)
73
+ google-protobuf (~> 3.1)
74
+ googleapis-common-protos-types (~> 1.0.0)
75
+ i18n (1.0.1)
76
+ concurrent-ruby (~> 1.0)
77
+ loofah (2.2.2)
78
+ crass (~> 1.0.2)
79
+ nokogiri (>= 1.5.9)
80
+ mail (2.7.0)
81
+ mini_mime (>= 0.1.1)
82
+ marcel (0.3.2)
83
+ mimemagic (~> 0.3.2)
84
+ method_source (0.9.0)
85
+ middleware (0.1.0)
86
+ mimemagic (0.3.2)
87
+ mini_mime (1.0.0)
88
+ mini_portile2 (2.3.0)
89
+ minitest (5.11.3)
90
+ nio4r (2.3.1)
91
+ nokogiri (1.8.4)
92
+ mini_portile2 (~> 2.3.0)
93
+ protobuf (3.8.4)
94
+ activesupport (>= 3.2)
95
+ middleware
96
+ thor
97
+ thread_safe
98
+ pry (0.11.3)
99
+ coderay (~> 1.1.0)
100
+ method_source (~> 0.9.0)
101
+ pry-doc (0.13.4)
102
+ pry (~> 0.11)
103
+ yard (~> 0.9.11)
104
+ rack (2.0.5)
105
+ rack-test (1.1.0)
106
+ rack (>= 1.0, < 3)
107
+ rails (5.2.0)
108
+ actioncable (= 5.2.0)
109
+ actionmailer (= 5.2.0)
110
+ actionpack (= 5.2.0)
111
+ actionview (= 5.2.0)
112
+ activejob (= 5.2.0)
113
+ activemodel (= 5.2.0)
114
+ activerecord (= 5.2.0)
115
+ activestorage (= 5.2.0)
116
+ activesupport (= 5.2.0)
117
+ bundler (>= 1.3.0)
118
+ railties (= 5.2.0)
119
+ sprockets-rails (>= 2.0.0)
120
+ rails-dom-testing (2.0.3)
121
+ activesupport (>= 4.2.0)
122
+ nokogiri (>= 1.6)
123
+ rails-html-sanitizer (1.0.4)
124
+ loofah (~> 2.2, >= 2.2.2)
125
+ railties (5.2.0)
126
+ actionpack (= 5.2.0)
127
+ activesupport (= 5.2.0)
128
+ method_source
129
+ rake (>= 0.8.7)
130
+ thor (>= 0.18.1, < 2.0)
131
+ rake (10.5.0)
132
+ rspec (3.7.0)
133
+ rspec-core (~> 3.7.0)
134
+ rspec-expectations (~> 3.7.0)
135
+ rspec-mocks (~> 3.7.0)
136
+ rspec-core (3.7.1)
137
+ rspec-support (~> 3.7.0)
138
+ rspec-expectations (3.7.0)
139
+ diff-lcs (>= 1.2.0, < 2.0)
140
+ rspec-support (~> 3.7.0)
141
+ rspec-mocks (3.7.0)
142
+ diff-lcs (>= 1.2.0, < 2.0)
143
+ rspec-support (~> 3.7.0)
144
+ rspec-support (3.7.1)
145
+ sprockets (3.7.2)
146
+ concurrent-ruby (~> 1.0)
147
+ rack (> 1, < 3)
148
+ sprockets-rails (3.2.1)
149
+ actionpack (>= 4.0)
150
+ activesupport (>= 4.0)
151
+ sprockets (>= 3.0.0)
152
+ thor (0.20.0)
153
+ thread_safe (0.3.6)
154
+ tzinfo (1.2.5)
155
+ thread_safe (~> 0.1)
156
+ websocket-driver (0.7.0)
157
+ websocket-extensions (>= 0.1.0)
158
+ websocket-extensions (0.1.3)
159
+ yard (0.9.15)
160
+
161
+ PLATFORMS
162
+ ruby
163
+
164
+ DEPENDENCIES
165
+ bundler (~> 1.16)
166
+ google-protobuf!
167
+ pry
168
+ pry-doc
169
+ rails_grpc!
170
+ rake (~> 10.0)
171
+ rspec (~> 3.0)
172
+
173
+ BUNDLED WITH
174
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Shinsuke Nishio
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.
data/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # rails\_grpc: gRPC for Ruby on Rails
2
+
3
+ gRPC for Ruby on Rails
4
+
5
+ ## Feature
6
+
7
+ - Add Autoreload protobuf definition feature in development mode
8
+ - Grpc Rails Server
9
+ - Add some useful grcp function
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'rails_grpc'
17
+ gem "google-protobuf", git: "git@github.com:nishio-dens/protobuf.git", branch: "rails-grpc", glob: "ruby/google-protobuf.gemspec"
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ ## Directory Structure
25
+
26
+ ### /proto
27
+
28
+ You need to put the protobuf definition in Rails.root/proto dir.
29
+
30
+ ```
31
+ $ tree proto
32
+ proto
33
+ ├── ec.deep.proto
34
+ ├── ec.proto
35
+ └── other.proto
36
+ ```
37
+
38
+ ### /grpc
39
+
40
+ You need to be careful about the location of grpc service, lib, and model files.
41
+
42
+ ```
43
+ # current working dir is Rails.root
44
+
45
+ $ tree grpc
46
+
47
+ grpc
48
+ ├── lib
49
+ │   ├── ec.deep_pb.rb
50
+ │   ├── ec.deep_services_pb.rb
51
+ │   ├── ec_pb.rb
52
+ │   ├── ec_services_pb.rb
53
+ │   └── other_pb.rb
54
+ ├── models
55
+ │   └── ec
56
+ │   └── product.rb
57
+ └── services
58
+ └── product_service.rb
59
+ ```
60
+
61
+ lib files is the protobuf autogenerate files.
62
+
63
+ models is a models that you want to extend protobuf models.
64
+
65
+ services is the protobuf service files.
66
+
67
+
68
+ ### example models
69
+
70
+ ```
71
+ # grpc/models/ec/product.rb
72
+
73
+ # You can extend Ec::Product models
74
+ class Ec::Product
75
+ PORT = "127.0.0.1:8080"
76
+
77
+ def self.all
78
+ service = Ec::ProductService::Stub.new(PORT, :this_channel_is_insecure)
79
+ req = Ec::GetProductsRequest.new
80
+ res = service.get_products(req)
81
+
82
+ res.products
83
+ end
84
+
85
+ def self.find(id)
86
+ service = Ec::ProductService::Stub.new(PORT, :this_channel_is_insecure)
87
+ req = Ec::GetByProductIdRequest.new(product_id: id)
88
+ res = service.get_by_product_id(req)
89
+
90
+ res.product
91
+ end
92
+ end
93
+ ```
94
+
95
+ ### example services
96
+
97
+ ```
98
+ # grpc/services/product\_service.rb
99
+
100
+ module Grpc
101
+ class ProductService < Ec::ProductService::Service
102
+ def get_products(req, _call)
103
+ products = Product.all
104
+ Ec::GetProductsResponse.new(products: products.map(&:to_proto))
105
+ end
106
+
107
+ def get_by_product_id(req, _call)
108
+ product = Product.find_by(id: req.product_id)
109
+ if product.present?
110
+ Ec::GetByProductIdResponse.new(product: product.to_proto)
111
+ else
112
+ fail GRPC::BadStatus.new_status_exception(
113
+ GRPC::Core::StatusCodes::ABORTED,
114
+ "product #{req.product_id} not found"
115
+ )
116
+ end
117
+ end
118
+ end
119
+ end
120
+ ```
121
+
122
+
123
+ ## Compile Protoc
124
+
125
+ First, you put protobuf definition in /proto dir, and you need to run compile command.
126
+
127
+ ```
128
+ bundle exec rake protoc:compile
129
+ ```
130
+
131
+ ## Development
132
+
133
+ 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.
134
+
135
+ 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).
136
+
137
+ ## Contributing
138
+
139
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nishio-dens/rails_grpc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
140
+
141
+ ## License
142
+
143
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
144
+
145
+ ## Code of Conduct
146
+
147
+ Everyone interacting in the RailsGrpc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nishio-dens/rails_grpc/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_grpc"
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
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/lib/rails_grpc.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "rails_grpc/version"
2
+
3
+ module RailsGrpc
4
+ end
5
+
6
+ if defined?(Rails)
7
+ require "rails_grpc/dependencies"
8
+ require "rails_grpc/reloader"
9
+ require "rails_grpc/railtie"
10
+ end
@@ -0,0 +1,93 @@
1
+ require "rails"
2
+
3
+ module RailsGrpc
4
+ module Dependencies
5
+ mattr_accessor :proto_lib_dir
6
+ mattr_accessor :grpc_model_dir
7
+ mattr_accessor :grpc_service_dir
8
+
9
+ @@proto_lib_dir = "grpc/lib"
10
+ @@grpc_model_dir = "grpc/models"
11
+ @@grpc_service_dir = "grpc/services"
12
+ @@loaded = false
13
+
14
+ class << self
15
+ def rails_root
16
+ ::Rails.root
17
+ end
18
+
19
+ def find_proto_lib_files
20
+ Dir.glob(File.join(rails_root, proto_lib_dir, "**/*.rb"))
21
+ end
22
+
23
+ def find_proto_message_definitions
24
+ find_proto_lib_files.reject do |t|
25
+ File.basename(t).include?("_services_pb.rb")
26
+ end
27
+ end
28
+
29
+ def find_proto_service_definitions
30
+ find_proto_lib_files.select do |t|
31
+ File.basename(t).include?("_services_pb.rb")
32
+ end
33
+ end
34
+
35
+ def find_grpc_model_files
36
+ Dir.glob(File.join(rails_root, grpc_model_dir, "**/*.rb"))
37
+ end
38
+
39
+ def find_grpc_service_files
40
+ Dir.glob(File.join(rails_root, grpc_service_dir, "**/*.rb"))
41
+ end
42
+
43
+ def cache_classes?
44
+ ::Rails.application.config.cache_classes
45
+ end
46
+
47
+ def load_dependencies!
48
+ return if @@loaded
49
+
50
+ find_proto_message_definitions.each do |f|
51
+ parent_const_name = File.basename(f).gsub(".", "::").split("::")[0].classify
52
+ load_and_watch(f, parent_const_name)
53
+ end
54
+
55
+ find_proto_service_definitions.each do |f|
56
+ parent_const_name = File.basename(f).gsub(".", "::").split("::")[0].classify
57
+ load_and_watch(f, parent_const_name)
58
+ end
59
+
60
+ find_grpc_model_files.each do |f|
61
+ parent_const_name = File.basename(f).gsub(".", "::").split("::")[0].classify
62
+ load_and_watch(f, parent_const_name)
63
+ end
64
+
65
+ find_grpc_service_files.each do |f|
66
+ parent_const_name = File.basename(f).gsub(".", "::").split("::")[0].classify
67
+ load_and_watch(f, parent_const_name)
68
+ end
69
+
70
+ @@loaded = true
71
+ end
72
+
73
+ def clear_dependencies!
74
+ @@loaded = false
75
+ end
76
+
77
+ def load_and_watch(file_path, const_name)
78
+ watch_file_and_dir(file_path) if self.cache_classes?
79
+
80
+ ActiveSupport::Dependencies.require_or_load(file_path, const_name.to_sym)
81
+ end
82
+
83
+ def watch_file_and_dir(filepath)
84
+ dir_path = File.dirname(file_path)
85
+
86
+ ::Rails.application.config.watchable_dirs[dir_path] = [:rb]
87
+ unless ::Rails.application.config.watchable_files.include?(file_path)
88
+ ::Rails.application.config.watchable_files.concat([file_path])
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,23 @@
1
+ require "rails"
2
+ require "rails_grpc/dependencies"
3
+ require "google/protobuf"
4
+
5
+ module RailsGrpc
6
+ class Railtie < ::Rails::Railtie
7
+ rake_tasks do
8
+ load "tasks/protoc.rake"
9
+ end
10
+
11
+ config.before_initialize do |app|
12
+ RailsGrpc::Dependencies.load_dependencies!
13
+ end
14
+
15
+ ActiveSupport::Reloader.to_complete do
16
+ unless RailsGrpc::Dependencies.cache_classes?
17
+ Google::Protobuf::DescriptorPool.generated_pool.clear
18
+ RailsGrpc::Dependencies.clear_dependencies!
19
+ RailsGrpc::Dependencies.load_dependencies!
20
+ end
21
+ end
22
+ end
23
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module RailsGrpc
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,64 @@
1
+ namespace :protoc do
2
+ desc "Compile Protobuf and generate ruby code"
3
+ task compile: :environment do
4
+ compile
5
+ remove_unnecessary_require
6
+ end
7
+
8
+ private
9
+
10
+ def proto_path
11
+ File.join(Rails.root, "proto")
12
+ end
13
+
14
+ def grpc_path
15
+ File.join(Rails.root, "grpc")
16
+ end
17
+
18
+ def ruby_out
19
+ File.join(grpc_path, "lib")
20
+ end
21
+
22
+ def grpc_out
23
+ ruby_out
24
+ end
25
+
26
+ def grpc_ruby_plugin_path
27
+ `which grpc_ruby_plugin`.chomp
28
+ end
29
+
30
+ def proto_files
31
+ Dir.glob(File.join(Rails.root, "proto", "*.proto"))
32
+ end
33
+
34
+ def compile
35
+ command = <<-EOS
36
+ protoc -I #{proto_path} --ruby_out=#{ruby_out} --grpc_out=#{grpc_out} \
37
+ --plugin=protoc-gen-grpc=#{grpc_ruby_plugin_path} #{proto_files.join(" ")}
38
+ EOS
39
+ puts "Compile Protobuf..."
40
+ puts command
41
+ `#{command}`
42
+ end
43
+
44
+ def grpc_out_ruby_files
45
+ Dir.glob(File.join(ruby_out, "**/*.rb"))
46
+ end
47
+
48
+ # FIXME:
49
+ # - Load the definition of protobuf twice will result in an error
50
+ # so we remove the require pb definition.
51
+ # This is not a smart way, we need to fix it.
52
+ def remove_unnecessary_require
53
+ service_files = grpc_out_ruby_files.select do |v|
54
+ name = File.basename(v)
55
+ name.end_with?("_pb.rb") && name.include?("_services_")
56
+ end
57
+ service_files.each do |path|
58
+ source = open(path).read.split("\n").reject { |line| line =~ /^require / }.join("\n")
59
+ open(path, "w") do |f|
60
+ f.write source
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rails_grpc/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_grpc"
8
+ spec.version = RailsGrpc::VERSION
9
+ spec.authors = ["Shinsuke Nishio"]
10
+ spec.email = ["nishio@densan-labs.net"]
11
+
12
+ spec.summary = %q{gRPC for Ruby on Rails}
13
+ spec.description = %q{gRPC for Ruby on Rails}
14
+ spec.homepage = "https://github.com/nishio-dens/rails_grpc"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "rails"
25
+ spec.add_dependency "grpc"
26
+ spec.add_dependency "protobuf"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_grpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shinsuke Nishio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
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: grpc
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
+ - !ruby/object:Gem::Dependency
42
+ name: protobuf
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: gRPC for Ruby on Rails
98
+ email:
99
+ - nishio@densan-labs.net
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/rails_grpc.rb
116
+ - lib/rails_grpc/dependencies.rb
117
+ - lib/rails_grpc/railtie.rb
118
+ - lib/rails_grpc/reloader.rb
119
+ - lib/rails_grpc/version.rb
120
+ - lib/tasks/protoc.rake
121
+ - rails_grpc.gemspec
122
+ homepage: https://github.com/nishio-dens/rails_grpc
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.7.6
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: gRPC for Ruby on Rails
146
+ test_files: []