hadron 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d100356d8e2274c4bf905faf27dfe83fedbd0a4d2d04a2c27d25d6a9448e687
4
- data.tar.gz: 0502ca57031a8040518e06036759ccd73eff72c2f29a75e532c5de8d37e19c0a
3
+ metadata.gz: bc7969e6e3c5841b97f243a67ce9f9d90b9858acd7478a4b0305b7b0096176e3
4
+ data.tar.gz: fb26b6476ad91568938a3ad07d39caaea2e68bd1d67e5135765d760bd9e331c3
5
5
  SHA512:
6
- metadata.gz: 3d6190786df02e902da5132e916c9a98079b80cab0062025a5b104597fcc19e030c38a6f685582f69f979faeef46c36f77b2cd14f89abcdfa77f6f4f5b424524
7
- data.tar.gz: c2b25b3debf03274a7eb30eb888be747a3dccf3762a5a7a7a2af6b41a03b64fb8aef5296992a610b32b93efbcb07059a88294eb9e7081402750d40390ceee98d
6
+ metadata.gz: 98002297226f9e4fd89157429cec9495fb02427efe727c6b74efd91e3763cadaca25082b79fa3304008b962d2cc9b3f38f39ff6fbc589db9eba34ff7101bf5ff
7
+ data.tar.gz: 14378d7ae3fde41374b7c695acd5e1ef596caf1f3fb548982cd26ac9e6a04f3f1204879dc332224e75f9cb85b301dd1cc8dfefeae4a3e8c731dcda4de2bfef4d
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 "proto_dsl", "~> 0.1.1"
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.5)
4
+ hadron (0.1.7)
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
- proto_dsl (0.1.1)
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
- proto_dsl (~> 0.1.1)
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/hadron CHANGED
@@ -1,53 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require 'hadron'
4
+ require "bundler/setup"
5
+ require "hadron"
4
6
 
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)
7
+ Hadron::Cli.start(ARGV)
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 = ["hadron"]
31
+ spec.executables << "hadron"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hadron
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.7"
5
5
  end
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
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "grpc"
4
+ gem "grpc-tools"
@@ -0,0 +1,13 @@
1
+ syntax = "proto3";
2
+
3
+ service Greeter {
4
+ rpc SayHello (HelloRequest) returns (HelloResponse) {}
5
+ }
6
+
7
+ message HelloRequest {
8
+ string name = 1;
9
+ }
10
+
11
+ message HelloResponse {
12
+ string message = 1;
13
+ }
@@ -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
@@ -0,0 +1,9 @@
1
+ require "grpc"
2
+
3
+ module Helloworld
4
+ class GreeterServer < Helloworld::Greeter::Service
5
+ def say_hello(hello_req, _unused_call)
6
+ Helloworld::HelloResponse.new(message: "Hello \#{hello_req.name}")
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hadron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
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-08 00:00:00.000000000 Z
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.
@@ -30,9 +30,13 @@ files:
30
30
  - bin/hadron
31
31
  - hadron.gemspec
32
32
  - lib/hadron.rb
33
- - lib/hadron/command.rb
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:
@@ -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
@@ -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