Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Telebugs.notify with empty implementation #4

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 3.0
8 changes: 8 additions & 0 deletions lib/telebugs.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

require "concurrent"

require_relative "telebugs/version"
require_relative "telebugs/config"
require_relative "telebugs/promise"

module Telebugs
# The general error that this library uses when it wants to raise.
Expand All @@ -11,5 +14,10 @@ class << self
def configure
yield Telebugs::Config.instance
end

def notify(error:)
Telebugs::Promise.new(error) do
end
end
end
end
15 changes: 15 additions & 0 deletions lib/telebugs/promise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Telebugs
# Wraps Concurrent::Promise to provide a consistent API for promises that we
# can control.
class Promise
def initialize(...)
@future = Concurrent::Promises.future(...)
end

def value
@future.value
end
end
end
3 changes: 1 addition & 2 deletions telebugs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"
spec.add_dependency "concurrent-ruby", "~> 1.3"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
11 changes: 11 additions & 0 deletions test/test_promise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "test_helper"

class TestPromise < Minitest::Test
def test_future_value
promise = Telebugs::Promise.new { 1 + 1 }

assert_equal 2, promise.value
end
end
6 changes: 6 additions & 0 deletions test/test_telebugs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ def test_configure_configures_project_key

assert_equal key, Telebugs::Config.instance.api_key
end

def test_notify_returns_a_future
future = Telebugs.notify(error: StandardError.new)

assert_instance_of Telebugs::Promise, future
end
end