
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
gRPC for Ruby on Rails
Add this line to your application's Gemfile:
gem 'rails_grpc'
gem "google-protobuf", git: "git@github.com:nishio-dens/protobuf.git", branch: "rails-grpc", glob: "ruby/google-protobuf.gemspec"
And then execute:
$ bundle
You need to put the protobuf definition in Rails.root/proto dir.
$ tree proto
proto
βββ ec.deep.proto
βββ ec.proto
βββ other.proto
You need to be careful about the location of grpc service, lib, and model files.
# current working dir is Rails.root
$ tree grpc
grpc
βββ lib
βΒ Β βββ ec.deep_pb.rb
βΒ Β βββ ec.deep_services_pb.rb
βΒ Β βββ ec_pb.rb
βΒ Β βββ ec_services_pb.rb
βΒ Β βββ other_pb.rb
βββ models
βΒ Β βββ ec
βΒ Β βββ product.rb
βββ services
βββ product_service.rb
lib files is the protobuf autogenerate files.
models is a models that you want to extend protobuf models.
services is the protobuf service files.
# grpc/models/ec/product.rb
# You can extend Ec::Product models
class Ec::Product
PORT = "127.0.0.1:8080"
def self.all
service = Ec::ProductService::Stub.new(PORT, :this_channel_is_insecure)
req = Ec::GetProductsRequest.new
res = service.get_products(req)
res.products
end
def self.find(id)
service = Ec::ProductService::Stub.new(PORT, :this_channel_is_insecure)
req = Ec::GetByProductIdRequest.new(product_id: id)
res = service.get_by_product_id(req)
res.product
end
end
# grpc/services/product\_service.rb
module Grpc
class ProductService < Ec::ProductService::Service
def get_products(req, _call)
products = Product.all
Ec::GetProductsResponse.new(products: products.map(&:to_proto))
end
def get_by_product_id(req, _call)
product = Product.find_by(id: req.product_id)
if product.present?
Ec::GetByProductIdResponse.new(product: product.to_proto)
else
fail GRPC::BadStatus.new_status_exception(
GRPC::Core::StatusCodes::ABORTED,
"product #{req.product_id} not found"
)
end
end
end
end
First, you put protobuf definition in /proto dir, and you need to run compile command.
bundle exec rake protoc:compile
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.
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.
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 code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the RailsGrpc projectβs codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that rails_grpc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.