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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
/.claude/settings.local.json
/TODO.md
/.claude/settings.json
*.iml
/.vscode
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
featurehub-sdk (2.1.0)
featurehub-sdk (2.1.1)
concurrent-ruby (~> 1.3)
faraday
ld-eventsource (>= 2.5.1, < 2.7.0)
Expand Down Expand Up @@ -123,7 +123,7 @@ CHECKSUMS
domain_name (0.6.20240107) sha256=5f693b2215708476517479bf2b3802e49068ad82167bcd2286f899536a17d933
faraday (2.14.0) sha256=8699cfe5d97e55268f2596f9a9d5a43736808a943714e3d9a53e6110593941cd
faraday-net_http (3.4.2) sha256=f147758260d3526939bf57ecf911682f94926a3666502e24c69992765875906c
featurehub-sdk (2.1.0)
featurehub-sdk (2.1.1)
http (6.0.2) sha256=be337816fb45cee712eeb0829a16d9300c9d2b87b38b771d177d7a59f77e8b83
http-cookie (1.1.4) sha256=8dd8011dedcae5f91af2671b7ba878c4a9e89f0f6384790c1f4cdd176f5e3ada
json (2.19.3) sha256=289b0bb53052a1fa8c34ab33cc750b659ba14a5c45f3fcf4b18762dc67c78646
Expand Down
3 changes: 1 addition & 2 deletions examples/sinatra/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
featurehub-sdk (2.1.0)
featurehub-sdk (2.1.1)
concurrent-ruby (~> 1.3)
faraday
ld-eventsource (~> 2.5.1)
Expand Down Expand Up @@ -44,7 +44,6 @@ GEM
faraday-rack (1.0.0)
faraday-retry (1.0.4)
ffi (1.17.3-x86_64-darwin)
ffi (1.17.3-x86_64-linux-gnu)
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
Expand Down
9 changes: 0 additions & 9 deletions featurehub-ruby-sdk.iml

This file was deleted.

5 changes: 5 additions & 0 deletions lib/feature_hub/sdk/feature_state_holder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def feature_type
exists?(fs) ? fs["type"] : nil
end

def feature_properties
fs = feature_state
(exists?(fs) ? fs["fp"] : {}) || {}
end

def with_context(ctx)
FeatureStateHolder.new(@key, @repo, nil, self, ctx)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/feature_hub/sdk/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module FeatureHub
# already documented elsewhere
module Sdk
VERSION = "2.1.0"
VERSION = "2.1.1"
end
end
2 changes: 2 additions & 0 deletions sig/feature_hub/featurehub.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ module FeatureHub

def feature_type: -> String?

def feature_properties: -> Hash[String, String]

def with_context: (ctx: ClientContext) -> FeatureStateHolder

def update_feature_state: (feature_state: FeatureState) -> void
Expand Down
40 changes: 40 additions & 0 deletions spec/feature_hub/sdk/feature_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,46 @@ def raw_full_feature
END_JSON
end

def raw_feature_property_feature
<<~END_JSON
{
"id": "227dc2e8-59e8-424a-b510-328ef52010f7",
"key": "SUBMIT_COLOR_BUTTON",
"l": true,
"version": 28,
"type": "STRING",
"value": "orange",
"fp": {"appName": "figs", "portfolio": "fruit", "category": "shoes"}
}
END_JSON
end

def raw_simple_feature
'{"id": 123, "key": "blah", "version": 1, "value": false, "type": "BOOLEAN", "l": true}'
end

it "a feature with no state has an empty properties" do
fs = FeatureHub::Sdk::FeatureStateHolder.new("key", repo)
expect(fs.feature_properties).to eq({})
end

it "a feature with no feature properties has an empty properties" do
state = JSON.parse(raw_simple_feature)
fs = FeatureHub::Sdk::FeatureStateHolder.new(state["key"].to_sym, repo)
fs.update_feature_state(state)
expect(fs.feature_properties).to eq({})
end

it "should correctly expose the feature properties when they are there" do
state = JSON.parse(raw_feature_property_feature)
fs = FeatureHub::Sdk::FeatureStateHolder.new(state["key"].to_sym, repo)
fs.update_feature_state(state)
props = fs.feature_properties
expect(props["appName"]).to eq("figs")
expect(props["portfolio"]).to eq("fruit")
expect(props["category"]).to eq("shoes")
end

it "recognizes the correct state of a complex feature" do
state = JSON.parse(raw_full_feature)
fs = FeatureHub::Sdk::FeatureStateHolder.new(state["key"].to_sym, repo)
Expand Down