hadron 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -1
- data/Gemfile.lock +11 -3
- data/bin/cli +7 -0
- data/hadron.gemspec +2 -1
- data/lib/hadron/cli.rb +25 -0
- data/lib/hadron/version.rb +1 -1
- data/lib/hadron.rb +0 -16
- data/templates/gemfile.erb +4 -0
- data/templates/protobuf.erb +13 -0
- data/templates/readme.md +53 -0
- data/templates/server.erb +13 -0
- data/templates/services.erb +9 -0
- metadata +10 -6
- data/bin/hadron +0 -53
- data/lib/hadron/command.rb +0 -45
- data/lib/hadron/command_line.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9c80e4d16226e4f656e36f23f9195db88fe9330070ebf9da6cd062f7386a0a5
|
4
|
+
data.tar.gz: 273a6c9d5389325ef878671321c4913a312f81c7d51cfdb30810c7cde18fe6a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95c08fc728f26542cb9719326fd2739447f4cb426cec11fb514d080a01129cb2e4b05cff2893cf90843f40df25a38775fd015ad42aed78dff2f002e67d6b2fe5
|
7
|
+
data.tar.gz: 67c42934db699adbebbcdbfc6d01a854f6c6d2c128cba6e697a4d99542690b952e74ebb57a63eed50dc804f43ef7260664e881fa6e78152302bf4b26d9547ca2
|
data/Gemfile
CHANGED
@@ -5,7 +5,10 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in hadron.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "
|
8
|
+
gem "pry", "~> 0.14.1"
|
9
9
|
gem "rake", "~> 13.0"
|
10
10
|
gem "rspec", "~> 3.0"
|
11
11
|
gem "rubocop", "~> 1.21"
|
12
|
+
|
13
|
+
gem "thor", "~> 1.2"
|
14
|
+
gem "fileutils", "~> 1.7"
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hadron (0.1.
|
4
|
+
hadron (0.1.6)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
|
+
coderay (1.1.3)
|
10
11
|
diff-lcs (1.5.0)
|
12
|
+
fileutils (1.7.0)
|
11
13
|
json (2.6.3)
|
14
|
+
method_source (1.0.0)
|
12
15
|
parallel (1.22.1)
|
13
16
|
parser (3.1.3.0)
|
14
17
|
ast (~> 2.4.1)
|
15
|
-
|
18
|
+
pry (0.14.1)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
16
21
|
rainbow (3.1.1)
|
17
22
|
rake (13.0.6)
|
18
23
|
regexp_parser (2.6.1)
|
@@ -43,6 +48,7 @@ GEM
|
|
43
48
|
rubocop-ast (1.24.0)
|
44
49
|
parser (>= 3.1.1.0)
|
45
50
|
ruby-progressbar (1.11.0)
|
51
|
+
thor (1.2.1)
|
46
52
|
unicode-display_width (2.3.0)
|
47
53
|
|
48
54
|
PLATFORMS
|
@@ -50,11 +56,13 @@ PLATFORMS
|
|
50
56
|
x86_64-linux
|
51
57
|
|
52
58
|
DEPENDENCIES
|
59
|
+
fileutils (~> 1.7)
|
53
60
|
hadron!
|
54
|
-
|
61
|
+
pry (~> 0.14.1)
|
55
62
|
rake (~> 13.0)
|
56
63
|
rspec (~> 3.0)
|
57
64
|
rubocop (~> 1.21)
|
65
|
+
thor (~> 1.2)
|
58
66
|
|
59
67
|
BUNDLED WITH
|
60
68
|
2.3.15
|
data/bin/cli
ADDED
data/hadron.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = Hadron::VERSION
|
8
8
|
spec.authors = ["Sylvance"]
|
9
9
|
spec.email = ["kerandisylvance@gmail.com"]
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
10
11
|
|
11
12
|
spec.summary = "Ruby framework called Hadron that allows you to work with gRPC Ruby output easily."
|
12
13
|
spec.description = "Ruby framework called Hadron that allows you to work with gRPC Ruby output easily."
|
@@ -27,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
spec.executables
|
31
|
+
spec.executables << "cli"
|
31
32
|
spec.require_paths = ["lib"]
|
32
33
|
|
33
34
|
# Uncomment to register a new dependency of your gem
|
data/lib/hadron/cli.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
module Hadron
|
7
|
+
class Cli < Thor
|
8
|
+
desc "create PROJECT_NAME", "Creates a new gRPC Ruby server project with the given name"
|
9
|
+
def create(project_name)
|
10
|
+
# Create the project directory
|
11
|
+
FileUtils.mkdir_p(project_name)
|
12
|
+
|
13
|
+
# Copy the templates to the project directory
|
14
|
+
FileUtils.cp_r("templates/.", project_name)
|
15
|
+
|
16
|
+
# Replace placeholders in the templates with the project name
|
17
|
+
Dir["#{project_name}/**/*.erb"].each do |template_path|
|
18
|
+
template = File.read(template_path)
|
19
|
+
result = ERB.new(template).result(binding)
|
20
|
+
File.write(template_path.sub(/\.erb\z/, ""), result)
|
21
|
+
File.delete(template_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/hadron/version.rb
CHANGED
data/lib/hadron.rb
CHANGED
@@ -4,20 +4,4 @@ Dir[File.join(__dir__, "hadron", "*.rb")].sort.each { |file| require file }
|
|
4
4
|
|
5
5
|
module Hadron
|
6
6
|
class Error < StandardError; end
|
7
|
-
|
8
|
-
def self.create_project(name)
|
9
|
-
puts "Creates project #{name}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.create_database
|
13
|
-
puts "Creates database"
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.migrates_database
|
17
|
-
puts "Migrates database"
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.generate_scaffold(name)
|
21
|
-
puts "Generates scaffold #{name}"
|
22
|
-
end
|
23
7
|
end
|
data/templates/readme.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Welcome to the gRPC Ruby Server Project
|
2
|
+
|
3
|
+
This project is a template for creating a gRPC Ruby server using the [gRPC gem](https://github.com/grpc/grpc). It includes the necessary dependencies and files to get started with building a gRPC server in Ruby.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
Before getting started, make sure you have the following installed on your machine:
|
8
|
+
|
9
|
+
- [Ruby](https://www.ruby-lang.org/) (version 2.6 or higher)
|
10
|
+
- [Bundler](https://bundler.io/) (for installing dependencies)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
To install the dependencies for this project, run the following command in the root directory of the project:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
bundle install
|
18
|
+
```
|
19
|
+
|
20
|
+
## Running the Server
|
21
|
+
To start the gRPC server, run the following command in the root directory of the project:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
ruby server.rb
|
25
|
+
```
|
26
|
+
|
27
|
+
This will start the server and listen for incoming gRPC requests on port 50051.
|
28
|
+
|
29
|
+
## Customizing the Server
|
30
|
+
|
31
|
+
To customize the gRPC server, you can modify the helloworld.proto file in the lib/proto directory to define your own gRPC service and messages. You can then regenerate the Ruby code for the service using the grpc_tools_ruby_protoc command:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
bundle exec grpc_tools_ruby_protoc -I lib/proto --ruby_out=lib --grpc_out=lib lib/proto/helloworld.proto
|
35
|
+
```
|
36
|
+
|
37
|
+
You can also modify the helloworld_services.rb file in the lib directory to define the logic for handling gRPC requests and responses.
|
38
|
+
|
39
|
+
## Testing the Server
|
40
|
+
|
41
|
+
To test the gRPC server, you can use a gRPC client to send requests to the server and verify the responses. You can find more information about creating gRPC clients in Ruby in the gRPC documentation.
|
42
|
+
|
43
|
+
## Deployment
|
44
|
+
|
45
|
+
To deploy the gRPC server, you can follow the steps for deploying a gRPC server in your preferred environment. You can find more information about deploying gRPC servers in the gRPC documentation.
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
We welcome contributions to this project! If you have an idea for how to improve the gRPC Ruby server template, please feel free to open an issue or pull request.
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
This project is licensed under the MIT License. See the LICENSE file for more information.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "helloworld_services"
|
5
|
+
|
6
|
+
def main
|
7
|
+
s = GRPC::RpcServer.new
|
8
|
+
s.add_http2_port("0.0.0.0:50051", :this_port_is_insecure)
|
9
|
+
s.handle(Helloworld::GreeterServer)
|
10
|
+
s.run_till_terminated_or_interrupted([1, "int", "SIGQUIT"])
|
11
|
+
end
|
12
|
+
|
13
|
+
main
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hadron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvance
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby framework called Hadron that allows you to work with gRPC Ruby output
|
14
14
|
easily.
|
15
15
|
email:
|
16
16
|
- kerandisylvance@gmail.com
|
17
17
|
executables:
|
18
|
-
-
|
18
|
+
- cli
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
@@ -27,12 +27,16 @@ files:
|
|
27
27
|
- Gemfile.lock
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
|
-
- bin/
|
30
|
+
- bin/cli
|
31
31
|
- hadron.gemspec
|
32
32
|
- lib/hadron.rb
|
33
|
-
- lib/hadron/
|
34
|
-
- lib/hadron/command_line.rb
|
33
|
+
- lib/hadron/cli.rb
|
35
34
|
- lib/hadron/version.rb
|
35
|
+
- templates/gemfile.erb
|
36
|
+
- templates/protobuf.erb
|
37
|
+
- templates/readme.md
|
38
|
+
- templates/server.erb
|
39
|
+
- templates/services.erb
|
36
40
|
homepage: https://github.com/Sylvance/hadron
|
37
41
|
licenses: []
|
38
42
|
metadata:
|
data/bin/hadron
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'hadron'
|
4
|
-
|
5
|
-
cli = Hadron::CommandLine.new
|
6
|
-
|
7
|
-
# Define the `create` subcommand
|
8
|
-
cli.command :create do |c|
|
9
|
-
c.desc "Create a new project"
|
10
|
-
c.arg_name "project_name"
|
11
|
-
|
12
|
-
c.action do |args, options|
|
13
|
-
project_name = args.first
|
14
|
-
Hadron.create_project(project_name)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Define the `db` subcommand
|
19
|
-
cli.command :db do |c|
|
20
|
-
# Define the `create` subcommand for `db`
|
21
|
-
c.command :create do |create|
|
22
|
-
create.desc "Create a database"
|
23
|
-
create.action do |args, options|
|
24
|
-
Hadron.create_database
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Define the `migrate` subcommand for `db`
|
29
|
-
c.command :migrate do |migrate|
|
30
|
-
migrate.desc "Migrate a database"
|
31
|
-
migrate.action do |args, options|
|
32
|
-
Hadron.migrate_database
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Define the `generate` subcommand
|
38
|
-
cli.command :generate do |c|
|
39
|
-
c.desc "Generate boilerplate code"
|
40
|
-
|
41
|
-
# Define the `scaffold` subcommand for `generate`
|
42
|
-
c.command :scaffold do |scaffold|
|
43
|
-
scaffold.desc "Generate scaffold code"
|
44
|
-
scaffold.arg_name "scaffold_name"
|
45
|
-
|
46
|
-
scaffold.action do |args, options|
|
47
|
-
scaffold_name = args.first
|
48
|
-
Hadron.generate_scaffold(scaffold_name)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
cli.run(ARGV)
|
data/lib/hadron/command.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hadron
|
4
|
-
class Command
|
5
|
-
def initialize(name)
|
6
|
-
@name = name
|
7
|
-
@subcommands = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
def desc(description)
|
11
|
-
@description = description
|
12
|
-
end
|
13
|
-
|
14
|
-
def arg_name(name)
|
15
|
-
@arg_name = name
|
16
|
-
end
|
17
|
-
|
18
|
-
def action(&block)
|
19
|
-
@action = block
|
20
|
-
end
|
21
|
-
|
22
|
-
def command(name, &block)
|
23
|
-
cmd = Command.new(name)
|
24
|
-
cmd.instance_eval(&block)
|
25
|
-
@subcommands[name] = cmd
|
26
|
-
end
|
27
|
-
|
28
|
-
def run(args)
|
29
|
-
if @subcommands.empty?
|
30
|
-
# This command has no subcommands, so it must have an action
|
31
|
-
@action.call(args)
|
32
|
-
else
|
33
|
-
# This command has subcommands, so the next argument should be a subcommand name
|
34
|
-
subcmd_name = args.shift
|
35
|
-
subcmd = @subcommands[subcmd_name]
|
36
|
-
|
37
|
-
if subcmd
|
38
|
-
subcmd.run(args)
|
39
|
-
else
|
40
|
-
puts "Unknown subcommand for '#{@name}': #{subcmd_name}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/hadron/command_line.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./command"
|
4
|
-
|
5
|
-
module Hadron
|
6
|
-
class CommandLine
|
7
|
-
def initialize
|
8
|
-
@commands = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def command(name, &block)
|
12
|
-
cmd = Command.new(name)
|
13
|
-
cmd.instance_eval(&block)
|
14
|
-
@commands[name] = cmd
|
15
|
-
end
|
16
|
-
|
17
|
-
def run(args)
|
18
|
-
cmd_name = args.shift
|
19
|
-
cmd = @commands[cmd_name]
|
20
|
-
|
21
|
-
if cmd
|
22
|
-
cmd.run(args)
|
23
|
-
else
|
24
|
-
puts "Unknown command: #{cmd_name}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|