Skip to content

Commit

Permalink
Rename RedisKeys to Keys only
Browse files Browse the repository at this point in the history
Why? Keys class it's responsible for decomposing the feature_key
and this logic will be needed in others Storages as well.
So we are renaming it to make clear it doesn't depends on Redis.
  • Loading branch information
henrich-m committed Jul 30, 2020
1 parent 679fcc2 commit 2977d70
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/feature_flagger/control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def released?(feature_key, resource_id)
end

def release(feature_key, resource_id)
resource_name = FeatureFlagger::Storage::RedisKeys.extract_resource_name_from_feature_key(
resource_name = Storage::Keys.extract_resource_name_from_feature_key(
feature_key
)

Expand All @@ -29,10 +29,10 @@ def release_to_all(feature_key)
end

def unrelease(feature_key, resource_id)
resource_name = FeatureFlagger::Storage::RedisKeys.extract_resource_name_from_feature_key(
resource_name = Storage::Keys.extract_resource_name_from_feature_key(
feature_key
)

@storage.remove(feature_key, resource_name, resource_id)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FeatureFlagger
module Storage
module RedisKeys
module Keys
MINIMUM_VALID_FEATURE_PATH = 2.freeze

def self.resource_key(prefix, resource_name, resource_id)
Expand All @@ -9,13 +9,13 @@ def self.resource_key(prefix, resource_name, resource_id)

def self.extract_resource_name_from_feature_key(feature_key)
feature_paths = feature_key.split(':')

raise InvalidResourceNameError if feature_paths.size < MINIMUM_VALID_FEATURE_PATH

feature_paths.first
end

class InvalidResourceNameError < StandardError; end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/feature_flagger/storage/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def feature_keys
private

def resource_key(resource_name, resource_id)
FeatureFlagger::Storage::RedisKeys.resource_key(
FeatureFlagger::Storage::Keys.resource_key(
RESOURCE_PREFIX,
resource_name,
resource_id,
Expand Down
12 changes: 6 additions & 6 deletions spec/feature_flagger/storage/redis_keys_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'spec_helper'

RSpec.describe FeatureFlagger::Storage::RedisKeys do
RSpec.describe FeatureFlagger::Storage::Keys do
describe '.resource_key' do
it 'generates the resource_key' do
prefix = "my_prefix"
resource_name = "account"
resource_id = "1"

result = FeatureFlagger::Storage::RedisKeys.resource_key(
result = FeatureFlagger::Storage::Keys.resource_key(
prefix,
resource_name,
resource_id,
Expand All @@ -21,7 +21,7 @@
context 'when feature_key is valid' do
it 'returns resource_name' do
feature_key = 'account:email_marketing:whitelabel'
result = FeatureFlagger::Storage::RedisKeys.extract_resource_name_from_feature_key(
result = FeatureFlagger::Storage::Keys.extract_resource_name_from_feature_key(
feature_key
)

Expand All @@ -34,11 +34,11 @@
feature_key = 'account'

expect {
FeatureFlagger::Storage::RedisKeys.extract_resource_name_from_feature_key(
FeatureFlagger::Storage::Keys.extract_resource_name_from_feature_key(
feature_key
)
}.to raise_error(FeatureFlagger::Storage::RedisKeys::InvalidResourceNameError)
}.to raise_error(FeatureFlagger::Storage::Keys::InvalidResourceNameError)
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/feature_flagger/storage/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:resource_name) { 'account' }
let(:global_key) { 'released_features' }
let(:resource_key) do
FeatureFlagger::Storage::RedisKeys.resource_key(
FeatureFlagger::Storage::Keys.resource_key(
FeatureFlagger::Storage::Redis::RESOURCE_PREFIX,
resource_name,
resource_id,
Expand Down Expand Up @@ -66,7 +66,7 @@
context 'when only add_all is called' do
it 'turns feature a global' do
storage.add_all(global_key, feature_key)

expect(storage).to have_value(global_key, feature_key)
end
end
Expand Down

0 comments on commit 2977d70

Please sign in to comment.