diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..a4736dc --- /dev/null +++ b/bin/console @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "yookassa" + +begin + require "pry-byebug" + Pry.start +rescue LoadError + require "irb" + IRB.start +end diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/lib/yookassa.rb b/lib/yookassa.rb index 074d01f..f1a429d 100644 --- a/lib/yookassa.rb +++ b/lib/yookassa.rb @@ -11,3 +11,14 @@ require "yookassa/optional" require "yookassa/entity/payment" require "yookassa/entity/refund" require "yookassa/error" +require "yookassa/config" + +module Yookassa + def self.configure + yield(config) + end + + def self.config + @config ||= Config.new + end +end diff --git a/lib/yookassa/config.rb b/lib/yookassa/config.rb new file mode 100644 index 0000000..e6a1a8e --- /dev/null +++ b/lib/yookassa/config.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Yookassa + class Config + attr_accessor :shop_id, :api_key + end +end diff --git a/spec/yookassa/config_spec.rb b/spec/yookassa/config_spec.rb new file mode 100644 index 0000000..69fc1e5 --- /dev/null +++ b/spec/yookassa/config_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Yookassa + RSpec.describe Config do + subject { described_class.new } + it { is_expected.to respond_to(:shop_id) } + it { is_expected.to respond_to(:api_key) } + end +end diff --git a/spec/yookassa_spec.rb b/spec/yookassa_spec.rb index ced91d5..ec16e61 100644 --- a/spec/yookassa_spec.rb +++ b/spec/yookassa_spec.rb @@ -4,4 +4,18 @@ RSpec.describe Yookassa do it "has a version number" do expect(Yookassa::VERSION).not_to be nil end + + describe ".configure" do + before do + Yookassa.configure do |config| + config.shop_id = 123 + config.api_key = "test_321" + end + end + + it "stores settings and provides access to credentials" do + expect(Yookassa.config.shop_id).to eq(123) + expect(Yookassa.config.api_key).to eq("test_321") + end + end end