ruby_nest_nats 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: eb157d3580a1c3059fd2accca997d62b983e3d02a88256caf933f842efaeb45c
4
+ data.tar.gz: 85ca0f29130a422f72ea3a966a38fcafba3c1a59abbc64504fccb5e2d6ed7b84
5
+ SHA512:
6
+ metadata.gz: ecb51585d48e0a2e6613815e00b6d9c869444ea70567775138d5c6264fa20f77494f242c0165a975c03b6c24732a7c4050704dd3fc58a98a1f2be0cc789bcf50
7
+ data.tar.gz: 6b0c1f22915cffd57897b41df7c9f72173ca3a1e84b7f2d3adee3a611c0bf9dc67509d1fb064966f778b50dda931412a41d1cc4b19b8028df5017876d019b511
@@ -0,0 +1,44 @@
1
+ name: Test and lint
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+ branches:
10
+ - main
11
+
12
+ # Allows you to run this workflow manually from the Actions tab
13
+ workflow_dispatch:
14
+
15
+ jobs:
16
+ build:
17
+ name: Run RSpec tests and RuboCop lints
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ strategy:
22
+ matrix:
23
+ ruby-version:
24
+ - 2.7
25
+ - 2.6
26
+
27
+ steps:
28
+ - name: Checkout the repo
29
+ uses: actions/checkout@v2
30
+
31
+ - name: Set up Ruby v${{ matrix.ruby-version }}
32
+ uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby-version }}
35
+ bundler-cache: true
36
+
37
+ - name: Install dependencies
38
+ run: bundle install
39
+
40
+ - name: Run RSpec tests
41
+ run: bundle exec rake spec
42
+
43
+ - name: Run RuboCop lints
44
+ run: bundle exec rubocop
data/.gitignore ADDED
@@ -0,0 +1,70 @@
1
+ # generic stuff
2
+ .env
3
+ *.gem
4
+ *.rbc
5
+ log/*.log
6
+ /.config
7
+ /InstalledFiles
8
+ /pkg/
9
+ /tmp/
10
+
11
+ # testy stuff
12
+ .rspec
13
+ .rspec_status
14
+ *.orig
15
+ /coverage/
16
+ /coverage/
17
+ /db/*.sqlite3
18
+ /db/*.sqlite3-[0-9]*
19
+ /db/*.sqlite3-journal
20
+ /public/system
21
+ /spec/examples.txt
22
+ /spec/reports/
23
+ /spec/tmp
24
+ /test/tmp/
25
+ /test/version_tmp/
26
+ capybara-*.html
27
+ pickle-email-*.html
28
+ rerun.txt
29
+ test/dummy/db/*.sqlite3
30
+ test/dummy/db/*.sqlite3-journal
31
+ test/dummy/log/*.log
32
+ test/dummy/node_modules/
33
+ test/dummy/storage/
34
+ test/dummy/tmp/
35
+ test/dummy/yarn-error.log
36
+
37
+ # debuggy stuff
38
+ .byebug_history
39
+
40
+ ## doccy stuff
41
+ /.yardoc/
42
+ /_yardoc/
43
+ /doc/
44
+ /rdoc/
45
+
46
+ ## bundly stuff
47
+ /.bundle/
48
+ /vendor/bundle
49
+ /lib/bundler/man/
50
+
51
+ # "for a library or gem, you might want to ignore these files since the code is
52
+ # intended to run in multiple environments"
53
+ Gemfile.lock
54
+ .ruby-version
55
+ .ruby-gemset
56
+
57
+ # rvmmy stuff
58
+ .rvmrc
59
+
60
+ # editory stuff
61
+ .idea
62
+ .vscode
63
+ *.rdb
64
+
65
+ # systemy stuff
66
+ *.swm
67
+ *.swn
68
+ *.swo
69
+ *.swp
70
+ *.DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,102 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+ - rubocop-rake
5
+
6
+ # Globals
7
+
8
+ AllCops:
9
+ NewCops: enable
10
+ TargetRubyVersion: 2.6
11
+
12
+ # Layout
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+ Exclude:
17
+ - 'spec/**/*_spec.rb'
18
+ - '*.gemspec'
19
+
20
+ Layout/EndAlignment:
21
+ EnforcedStyleAlignWith: variable
22
+
23
+ Layout/FirstArrayElementIndentation:
24
+ EnforcedStyle: consistent
25
+
26
+ # Metrics
27
+
28
+ Metrics/AbcSize:
29
+ CountRepeatedAttributes: false
30
+ Exclude:
31
+ - 'spec/**/*_spec.rb'
32
+ - '*.gemspec'
33
+
34
+ Metrics/BlockLength:
35
+ Exclude:
36
+ - 'spec/**/*_spec.rb'
37
+ - '*.gemspec'
38
+
39
+ Metrics/ClassLength:
40
+ Max: 150
41
+ CountComments: false
42
+ CountAsOne:
43
+ - array
44
+ - hash
45
+ - heredoc
46
+ Exclude:
47
+ - 'spec/**/*_spec.rb'
48
+ - '*.gemspec'
49
+
50
+ Metrics/MethodLength:
51
+ Max: 20
52
+ CountComments: false
53
+ CountAsOne:
54
+ - array
55
+ - hash
56
+ - heredoc
57
+
58
+ Metrics/ModuleLength:
59
+ Max: 150
60
+ CountComments: false
61
+ CountAsOne:
62
+ - array
63
+ - hash
64
+ - heredoc
65
+ Exclude:
66
+ - 'spec/**/*_spec.rb'
67
+ - '*.gemspec'
68
+
69
+ # Rspec
70
+
71
+ RSpec/ExampleLength:
72
+ Max: 25
73
+
74
+ RSpec/MessageSpies:
75
+ Enabled: false
76
+
77
+ RSpec/MultipleExpectations:
78
+ Enabled: false
79
+
80
+ RSpec/NestedGroups:
81
+ Max: 10
82
+
83
+ # Style
84
+
85
+ Style/DoubleNegation:
86
+ Enabled: false
87
+
88
+ Style/ExpandPathArguments:
89
+ Exclude:
90
+ - 'adornable.gemspec'
91
+
92
+ Style/StringLiterals:
93
+ Enabled: false
94
+
95
+ Style/TrailingCommaInArguments:
96
+ EnforcedStyleForMultiline: consistent_comma
97
+
98
+ Style/TrailingCommaInArrayLiteral:
99
+ EnforcedStyleForMultiline: consistent_comma
100
+
101
+ Style/TrailingCommaInHashLiteral:
102
+ EnforcedStyleForMultiline: consistent_comma
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-05-10
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ruby_nest_nats.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Keegan Leitz
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,39 @@
1
+ # RubyNestNats
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruby_nest_nats`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruby_nest_nats'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruby_nest_nats
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_nest_nats.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ruby_nest_nats"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_nest_nats/version"
4
+ require "nats/client"
5
+
6
+ module RubyNestNats
7
+ class Error < StandardError; end
8
+
9
+ class Client
10
+ class << self
11
+ def queue=(some_queue)
12
+ @queue = some_queue.to_s
13
+ end
14
+
15
+ def queue
16
+ @queue
17
+ end
18
+
19
+ def replies
20
+ @replies ||= []
21
+ end
22
+
23
+ def started?
24
+ !!@started
25
+ end
26
+
27
+ def reply_to(raw_subject, with:)
28
+ subject = raw_subject.to_s
29
+
30
+ if started?
31
+ raise StandardError, "NATS already started"
32
+ elsif !with.respond_to?(:call)
33
+ raise ArgumentError, "Option `:with` must be callable"
34
+ elsif replies.any? { |reply| reply[:subject] == subject }
35
+ raise ArgumentError, "Already registered a reply to #{subject}"
36
+ end
37
+
38
+ replies << { subject: subject, handler: with, queue: queue }
39
+ end
40
+
41
+ def start!
42
+ @started = true
43
+
44
+ fiber = Fiber.new do
45
+ NATS.start do
46
+ replies.each do |replier|
47
+ NATS.subscribe(replier[:subject], queue: reply[:queue]) do |message, reply, _subject|
48
+ response = replier[:handler].call(JSON.parse(message)["data"])
49
+ NATS.publish(reply, response.to_json, queue: reply[:queue])
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ fiber.resume
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyNestNats
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ruby_nest_nats/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruby_nest_nats"
7
+ spec.version = RubyNestNats::VERSION
8
+ spec.authors = ["Keegan Leitz"]
9
+ spec.email = ["keegan@openbay.com"]
10
+
11
+ spec.summary = "Bridge between NestJS NATS and Ruby NATS"
12
+ spec.description = "Write Ruby NATS handlers for NestJS NATS implementations"
13
+ spec.homepage = "https://github.com/openbay/ruby_nest_nats"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/openbay/ruby_nest_nats"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.2"
31
+ spec.add_development_dependency "rake", "~> 13.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "rubocop", "~> 1.10"
34
+ spec.add_development_dependency "rubocop-performance", "~> 1.9"
35
+ spec.add_development_dependency "rubocop-rake", "~> 0.5"
36
+ spec.add_development_dependency "rubocop-rspec", "~> 2.2"
37
+ spec.add_development_dependency "solargraph"
38
+
39
+ spec.add_runtime_dependency "nats", "~> 0.11"
40
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_nest_nats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Keegan Leitz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: solargraph
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: nats
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.11'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.11'
139
+ description: Write Ruby NATS handlers for NestJS NATS implementations
140
+ email:
141
+ - keegan@openbay.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".github/workflows/main.yml"
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - CHANGELOG.md
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - lib/ruby_nest_nats.rb
158
+ - lib/ruby_nest_nats/version.rb
159
+ - ruby_nest_nats.gemspec
160
+ homepage: https://github.com/openbay/ruby_nest_nats
161
+ licenses:
162
+ - MIT
163
+ metadata:
164
+ homepage_uri: https://github.com/openbay/ruby_nest_nats
165
+ source_code_uri: https://github.com/openbay/ruby_nest_nats
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '2.6'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubygems_version: 3.0.9
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: Bridge between NestJS NATS and Ruby NATS
185
+ test_files: []