Class: Unleash::Strategy::Member

Inherits:
Base
  • Object
show all
Defined in:
lib/unleash/strategy/member.rb

Constant Summary collapse

PARAM =
'memberIds'.freeze

Instance Method Summary collapse

Instance Method Details

#is_enabled?(params = {}, context = nil) ⇒ Boolean

requires: params, context.properties.organization_id, context.properties.user_id

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unleash/strategy/member.rb', line 12

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.class.name == 'Unleash::Context'
  return false unless context.properties.fetch(:user_id, nil)
  return false unless context.properties.fetch(:organization_id, nil)

  user_id = context.properties.fetch(:user_id)
  organization_id = context.properties.fetch(:organization_id)
  member_id = "#{user_id}##{organization_id}"

  params[PARAM]
    .split(',')
    .map(&:strip)
    .include?(member_id)
end

#nameObject



6
7
8
# File 'lib/unleash/strategy/member.rb', line 6

def name
  'Member'
end