Skip to content

Commit

Permalink
Merge pull request #3 from telebugs/config
Browse files Browse the repository at this point in the history
Make it possible to configure api_key
  • Loading branch information
kyrylo committed Jun 6, 2024
2 parents 2b7d785 + 0e27c83 commit b6c1c3d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
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

0 comments on commit b6c1c3d

Please sign in to comment.