diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6bf8010..60d1f66 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: [ '3.0', '3.1', '3.2', '3.3', '3.4' ] + ruby-version: [ '2.7', '3.0', '3.1', '3.2', '3.3', '3.4' ] steps: - uses: actions/checkout@v3 diff --git a/Gemfile.lock b/Gemfile.lock index 3cc9307..c4ac2b6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,8 @@ PATH remote: . specs: - absmartly-sdk (1.1.2) + absmartly-sdk (1.2.1) + base64 (~> 0.2) faraday (~> 2.0) faraday-retry (~> 2.0) murmurhash3 (~> 0.1.7) @@ -10,13 +11,14 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) + base64 (0.3.0) byebug (11.1.3) diff-lcs (1.5.0) faraday (2.7.4) faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) faraday-net_http (3.0.2) - faraday-retry (2.1.0) + faraday-retry (2.4.0) faraday (~> 2.0) io-console (0.5.6) irb (1.2.6) @@ -31,7 +33,7 @@ GEM regexp_parser (2.5.0) reline (0.1.5) io-console (~> 0.5) - rexml (3.2.8) + rexml (3.4.4) rspec (3.11.0) rspec-core (~> 3.11.0) rspec-expectations (~> 3.11.0) diff --git a/absmartly.gemspec b/absmartly.gemspec index e931c07..7fc5366 100644 --- a/absmartly.gemspec +++ b/absmartly.gemspec @@ -32,6 +32,9 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] + # Required for Ruby 3.4+ where base64 is no longer a default gem. + # Faraday 2.7.x uses base64 but doesn't declare it as a dependency. + spec.add_dependency "base64", "~> 0.2" spec.add_dependency "faraday", "~> 2.0" spec.add_dependency "faraday-retry", "~> 2.0" spec.add_dependency "murmurhash3", "~> 0.1.7" diff --git a/lib/absmartly/version.rb b/lib/absmartly/version.rb index 4e387d3..d2c762f 100644 --- a/lib/absmartly/version.rb +++ b/lib/absmartly/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Absmartly - VERSION = "1.2.0" + VERSION = "1.2.1" end diff --git a/lib/client_config.rb b/lib/client_config.rb index 113a507..0b6437c 100644 --- a/lib/client_config.rb +++ b/lib/client_config.rb @@ -17,7 +17,7 @@ class ClientConfig def_delegators :@http_client_config, :connect_timeout, :connection_request_timeout, :retry_interval, :max_retries def self.create(endpoint: nil, environment: nil, application: nil, api_key: nil) - new(endpoint:, environment:, application:, api_key:) + new(endpoint: endpoint, environment: environment, application: application, api_key: api_key) end def self.create_from_properties(properties, prefix) diff --git a/lib/context_config.rb b/lib/context_config.rb index 156793e..0cb7fe7 100644 --- a/lib/context_config.rb +++ b/lib/context_config.rb @@ -29,7 +29,8 @@ def unit(unit_type) end def set_attributes(attributes) - @attributes ||= attributes.transform_keys(&:to_sym) + @attributes.merge!(attributes.transform_keys(&:to_sym)) + self end def set_attribute(name, value) diff --git a/spec/context_config_spec.rb b/spec/context_config_spec.rb index 109267b..ed2e355 100644 --- a/spec/context_config_spec.rb +++ b/spec/context_config_spec.rb @@ -22,12 +22,31 @@ it ".set_attributes" do attributes = { "user_agent": "Chrome", "age": 9 } config = described_class.create - config.attributes = attributes + .set_attributes(attributes) expect(config.attribute("user_agent")).to eq("Chrome") expect(config.attribute("age")).to eq(9) expect(config.attributes).to eq(attributes) end + it ".set_attributes merges with set_attribute" do + config = described_class.create + .set_attribute("attr1", "value1") + .set_attributes({ attr2: "value2", attr3: 15 }) + + expect(config.attribute("attr1")).to eq("value1") + expect(config.attribute("attr2")).to eq("value2") + expect(config.attribute("attr3")).to eq(15) + end + + it ".set_attributes can be called multiple times" do + config = described_class.create + .set_attributes({ attr1: "value1" }) + .set_attributes({ attr2: "value2" }) + + expect(config.attribute("attr1")).to eq("value1") + expect(config.attribute("attr2")).to eq("value2") + end + it ".set_override" do config = described_class.create .set_override("exp_test", 2) diff --git a/spec/context_spec.rb b/spec/context_spec.rb index f5f4b42..268076c 100644 --- a/spec/context_spec.rb +++ b/spec/context_spec.rb @@ -434,6 +434,30 @@ def faraday_response(content) expect(context.override("exp_test_new_2")).to eq(5) end + it "set_attribute and set_attributes" do + context = create_ready_context + + context.set_attribute("attr1", "value1") + context.set_attributes({ attr2: "value2", attr3: 15 }) + + attrs = context.instance_variable_get(:@attributes) + expect(attrs).to include(Attribute.new("attr1", "value1", clock_in_millis)) + expect(attrs).to include(Attribute.new(:attr2, "value2", clock_in_millis)) + expect(attrs).to include(Attribute.new(:attr3, 15, clock_in_millis)) + end + + it "set_attributes before ready" do + context = create_context(data_future) + expect(context.ready?).to be_falsey + + context.set_attribute("attr1", "value1") + context.set_attributes({ attr2: "value2" }) + + attrs = context.instance_variable_get(:@attributes) + expect(attrs).to include(Attribute.new("attr1", "value1", clock_in_millis)) + expect(attrs).to include(Attribute.new(:attr2, "value2", clock_in_millis)) + end + it "set custom assignment" do context = create_ready_context context.set_custom_assignment("exp_test", 2)