-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from pipefy/tc-main/feat/pipe-with-uuid-strategy
feat: implement new PipeWithUuid strategy
- Loading branch information
Showing
5 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Unleash | ||
module Strategy | ||
class PipeWithUUID < Base | ||
PARAM = 'pipeUUIDs' | ||
|
||
def name | ||
'pipeWithUUID' | ||
end | ||
|
||
def is_enabled?(params = {}, context = nil) | ||
return false unless params.is_a?(Hash) && params.key?(PARAM) | ||
return false unless params.fetch(PARAM, nil).is_a? String | ||
return false unless context.instance_of?(Unleash::Context) | ||
|
||
allowed_pipe_uuids(params).include?(current_pipe_uuid(context)) | ||
end | ||
|
||
private | ||
|
||
def current_pipe_uuid(context) | ||
context&.properties&.values_at('pipe_uuid', :pipe_uuid)&.compact&.first | ||
end | ||
|
||
def allowed_pipe_uuids(params) | ||
params[PARAM].split(',').map(&:strip) | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'unleash/context' | ||
|
||
RSpec.describe Unleash::Strategy::PipeWithUUID do | ||
describe '#is_enabled?' do | ||
let(:strategy) { Unleash::Strategy::PipeWithUUID.new } | ||
let(:params) { { 'pipeUUIDs' => '1234,2567,1564' } } | ||
|
||
let(:unleash_context) { Unleash::Context.new({ properties: { 'pipe_uuid' => '1234' } }) } | ||
let(:unleash_context2) { Unleash::Context.new({ properties: { pipe_uuid: '2567' } }) } | ||
let(:unleash_context3) { Unleash::Context.new({ properties: { pipe_uuid: '666' } }) } | ||
|
||
it 'should be enabled with correct params/context as str' do | ||
expect(strategy.is_enabled?(params, unleash_context)).to be_truthy | ||
end | ||
|
||
it 'should be enabled with correct params/context as sym' do | ||
expect(strategy.is_enabled?(params, unleash_context2)).to be_truthy | ||
end | ||
|
||
it 'should not be enabled with wrong params/context' do | ||
expect(strategy.is_enabled?(params, unleash_context3)).to be_falsey | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'unleash-client-ruby-pipefy' | ||
spec.version = '2.0.0' | ||
spec.version = '2.1.0' | ||
spec.authors = ['Anderson Campos, Gustavo Candido, Thais Caldeira'] | ||
spec.email = ['[email protected], [email protected], [email protected]'] | ||
|
||
|