Class: Rox::Core::Flag

Inherits:
RoxString show all
Defined in:
lib/rox/core/entities/flag.rb

Direct Known Subclasses

Server::RoxFlag

Constant Summary collapse

FLAG_TRUE_VALUE =
'true'.freeze
FLAG_FALSE_VALUE =
'false'.freeze

Instance Attribute Summary

Attributes inherited from RoxString

#client_experiment, #condition, #default_value, #impression_invoker, #name, #options, #parser

Instance Method Summary collapse

Methods inherited from RoxString

#internal_value, #send_impressions, #set_for_evaluation

Constructor Details

#initialize(default_value = DefaultFlagValues::BOOLEAN) ⇒ Flag

Returns a new instance of Flag.



10
11
12
13
# File 'lib/rox/core/entities/flag.rb', line 10

def initialize(default_value = DefaultFlagValues::BOOLEAN)
  super(default_value ? Flag::FLAG_TRUE_VALUE : Flag::FLAG_FALSE_VALUE, [Flag::FLAG_FALSE_VALUE,
                                                                         Flag::FLAG_TRUE_VALUE])
end

Instance Method Details

#disabled(context) ⇒ Object



43
44
45
# File 'lib/rox/core/entities/flag.rb', line 43

def disabled(context)
  yield unless enabled?(context)
end

#enabled(context) ⇒ Object



39
40
41
# File 'lib/rox/core/entities/flag.rb', line 39

def enabled(context)
  yield if enabled?(context)
end

#enabled?(context) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rox/core/entities/flag.rb', line 15

def enabled?(context)
  merged_context = MergedContext.new(@parser&.global_context, context)
  value = internal_enabled?(merged_context)
  if [true, false].include? value
    send_impressions(value, merged_context)
    return value
  end

  send_impressions(DefaultFlagValues::BOOLEAN, merged_context)
  DefaultFlagValues.BOOLEAN
end

#external_typeObject



47
48
49
# File 'lib/rox/core/entities/flag.rb', line 47

def external_type
  'Boolean'
end

#internal_enabled?(context, nil_instead_of_default = false) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/rox/core/entities/flag.rb', line 34

def internal_enabled?(context, nil_instead_of_default = false)
  val = internal_value(context, nil_instead_of_default)
  nil_instead_of_default && val.nil? ? nil : (val == Flag::FLAG_TRUE_VALUE)
end

#value(context = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/rox/core/entities/flag.rb', line 27

def value(context = nil)
  merged_context = MergedContext.new(@parser&.global_context, context)
  return_value = internal_value(merged_context, false)
  send_impressions(return_value, merged_context)
  return_value
end