Class: ThisFeature::Adapters::SplitIo

Inherits:
Base
  • Object
show all
Defined in:
lib/this_feature/adapters/split_io.rb

Constant Summary collapse

EMPTY_CONTEXT =

Used as the context key when none is given. This arg is required by Split, but it’s nice not to have to pass it when the context is empty.

'undefined_key'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, context_key_method: nil) ⇒ SplitIo

Returns a new instance of SplitIo.



10
11
12
13
14
15
# File 'lib/this_feature/adapters/split_io.rb', line 10

def initialize(client: nil, context_key_method: nil)
  @client = client || default_split_client
  @context_key_method = context_key_method

  @client.block_until_ready
end

Instance Method Details

#control?(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/this_feature/adapters/split_io.rb', line 21

def control?(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
  treatment(flag_name, context: context, data: data, record: record).include?('control')
end

#off?(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/this_feature/adapters/split_io.rb', line 29

def off?(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
  treatment(flag_name, context: context, data: data, record: record).eql?('off')
end

#on?(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/this_feature/adapters/split_io.rb', line 25

def on?(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
  treatment(flag_name, context: context, data: data, record: record).eql?('on')
end

#present?(flag_name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/this_feature/adapters/split_io.rb', line 17

def present?(flag_name)
  !control?(flag_name)
end

#treatment_config(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil) ⇒ Object



37
38
39
# File 'lib/this_feature/adapters/split_io.rb', line 37

def treatment_config(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
  treatment_with_config(flag_name, context: context, data: data, record: record)[:config]
end

#treatment_value(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil) ⇒ Object



33
34
35
# File 'lib/this_feature/adapters/split_io.rb', line 33

def treatment_value(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
  treatment_with_config(flag_name, context: context, data: data, record: record)[:treatment]
end