Skip to content

Commit

Permalink
Merge pull request #15 from pipefy/tc-main/feat/pipe-with-uuid-strategy
Browse files Browse the repository at this point in the history
feat: implement new PipeWithUuid strategy
  • Loading branch information
thaiscaldeira authored Dec 5, 2022
2 parents e765f63 + c1e8afd commit abec7e5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/unleash-client-ruby-pipefy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require_relative 'unleash/strategy/flexible_rollout_org_uuid'
require_relative 'unleash/strategy/gradual_rollout_org_uuid'
require_relative 'unleash/strategy/pipe_with_uuid'
require_relative 'unleash/strategy/org_created_after'
require_relative 'unleash/strategy/org_with_uuid'
require_relative 'unleash/strategy/use_case'
Expand Down
31 changes: 31 additions & 0 deletions lib/unleash/strategy/pipe_with_uuid.rb
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.
26 changes: 26 additions & 0 deletions spec/unleash/strategy/pipe_with_uuid_spec.rb
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
2 changes: 1 addition & 1 deletion unleash-client-ruby-pipefy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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]']

Expand Down

0 comments on commit abec7e5

Please sign in to comment.