Skip to content

Commit

Permalink
Merge pull request #4 from telebugs/notify-method
Browse files Browse the repository at this point in the history
Add Telebugs.notify with empty implementation
  • Loading branch information
kyrylo committed Jun 6, 2024
2 parents b6c1c3d + ea981f7 commit 67145bc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
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

0 comments on commit 67145bc

Please sign in to comment.