Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions absmartly.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/absmartly/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Absmartly
VERSION = "1.2.0"
VERSION = "1.2.1"
end
2 changes: 1 addition & 1 deletion lib/client_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/context_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 20 additions & 1 deletion spec/context_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions spec/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down