dapr 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b58530051c7cbe3448434e7b5f82c54ccd07edfba848cc6e3d158c2f3e45f0a
4
+ data.tar.gz: cd95a77acfb96d76b47517185abc5e82b7c1678a9edff528a00dcaec1fb06e53
5
+ SHA512:
6
+ metadata.gz: ddf0d0ef8bf1a77a42a1385690d1db8ba8f2674f757f144afae5a774b0e5441a12f00ecab53df2773023c405f39f97731f1ba55ede64cc22e960339703fcbe0f
7
+ data.tar.gz: 4c6933ff7cce846cc31994ff24ed731a37fc41c109fccdd10d87fbba7bde6b36e174006528fb97ba4d4bb861313fbcb7becc44acfb9eac6274bf6cb5aece403d
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ ---
2
+ require:
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 3.2.0
8
+ NewCops: enable
9
+
10
+ Style/StringLiterals:
11
+ Enabled: true
12
+ EnforcedStyle: single_quotes
13
+
14
+ Style/StringLiteralsInInterpolation:
15
+ Enabled: true
16
+ EnforcedStyle: double_quotes
17
+
18
+ Layout/LineLength:
19
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-15
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Dapr
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/dapr`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dapr.
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]
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubyists
4
+ module Dapr
5
+ module Client
6
+ # Handles publishing messages to Dapr pub/sub topics
7
+ class Publisher
8
+ # Include the client module
9
+ include Client
10
+
11
+ # The name of the pubsub component, and the client
12
+ attr_reader :pubsub_name, :client
13
+
14
+ # The proto class for the publish event request
15
+ Proto = Dapr::Proto::Runtime::V1::PublishEventRequest
16
+
17
+ # Initialize the publisher
18
+ # @param name [String] The name of the pubsub component in Dapr
19
+ # @param serialization [Symbol] The serialization format to use. Defaults to :to_json
20
+ # this can be :to_json, :to_dapr, or any object that responds to :wrap.
21
+ # If it responds to :wrap, it will be called with the message to be sent.
22
+ def initialize(name, serialization: :to_json)
23
+ @serialization = serialization
24
+ @pubsub_name = name
25
+ end
26
+
27
+ def publish(topic, message)
28
+ singleton.publish_event(Proto.new(pubsub_name:, topic:, data: wrap(message)))
29
+ end
30
+
31
+ private
32
+
33
+ def wrap(message)
34
+ case serialization
35
+ when :to_dapr, :to_json
36
+ message.send(serialization)
37
+ when ->(s) { s.respond_to?(:wrap) }
38
+ serialization.wrap(message)
39
+ else
40
+ raise "Unknown serialization format: #{serialization}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'semantic_logger'
4
+ require 'dapr-ruby'
5
+ require 'dapr/proto/runtime/v1/dapr_services_pb'
6
+
7
+ module Rubyists
8
+ module Dapr
9
+ # The namespace for the Dapr client
10
+ module Client
11
+ include SemanticLogger::Loggable
12
+ DAPR_PORT = ENV.fetch('DAPR_GRPC_PORT', '5001')
13
+ DAPR_URI = ENV.fetch('DAPR_GRPC_HOST', 'localhost')
14
+ DAPR_STUB = Dapr::Proto::Runtime::V1::Dapr::Stub
15
+
16
+ def self.client
17
+ logger.info "Creating Dapr client for #{DAPR_URI}:#{DAPR_PORT}"
18
+ DAPR_STUB.new("#{DAPR_URI}:#{DAPR_PORT}", :this_channel_is_insecure)
19
+ end
20
+
21
+ def self.singleton
22
+ @singleton ||= client
23
+ end
24
+
25
+ def client
26
+ self.class.client
27
+ end
28
+
29
+ def singleton
30
+ self.class.singleton
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubyists
4
+ module Dapr
5
+ VERSION = '0.1.1'
6
+ end
7
+ end
data/lib/dapr.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'dapr/version'
4
+
5
+ module Dapr
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
data/sig/dapr.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Dapr
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dapr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Tj (bougyman) Vanderpoel
8
+ - afulki
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2024-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dapr-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: semantic_logger
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Wrappers to the dapr protobuf spec.
43
+ email:
44
+ - tj@rubyists.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - README.md
53
+ - Rakefile
54
+ - lib/dapr.rb
55
+ - lib/dapr/client.rb
56
+ - lib/dapr/client/publisher.rb
57
+ - lib/dapr/version.rb
58
+ - sig/dapr.rbs
59
+ homepage: https://github.com/rubyists/dapr
60
+ licenses: []
61
+ metadata:
62
+ allowed_push_host: https://rubygems.org
63
+ homepage_uri: https://github.com/rubyists/dapr
64
+ source_code_uri: https://github.com/rubyists/dapr
65
+ changelog_uri: https://github.com/rubyists/dapr/blob/main/CHANGELOG.md
66
+ rubygems_mfa_required: 'true'
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.5.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Library for interacting with dapr.
86
+ test_files: []