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

Make it possible to configure api_key #3

Merged
merged 1 commit 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
11 changes: 9 additions & 2 deletions lib/telebugs.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# frozen_string_literal: true

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

module Telebugs
class Error < StandardError; end
# Your code goes here...
# The general error that this library uses when it wants to raise.
Error = Class.new(StandardError)

class << self
def configure
yield Telebugs::Config.instance
end
end
end
21 changes: 21 additions & 0 deletions lib/telebugs/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Telebugs
# Represents the Telebugs config. A config contains all the options that you
# can use to configure a +Telebugs::Notifier+ instance.
class Config
attr_accessor :api_key

class << self
attr_writer :instance

def instance
@instance ||= new
end
end

def initialize
@api_key = nil
end
end
end
10 changes: 10 additions & 0 deletions test/test_telebugs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ class TestTelebugs < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::Telebugs::VERSION
end

def test_configure_configures_project_key
key = "12345:abcdef"

Telebugs.configure do |config|
config.api_key = key
end

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