Class: Toggler

Inherits:
Object
  • Object
show all
Defined in:
lib/tailslide/toggler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flag_name: '', get_flags: nil, emit_redis_signal: nil, user_context: '') ⇒ Toggler

Returns a new instance of Toggler.



7
8
9
10
11
12
13
14
15
# File 'lib/tailslide/toggler.rb', line 7

def initialize(flag_name: '', get_flags: nil, emit_redis_signal: nil, user_context: '')
  @flag_name = flag_name
  @get_flags = get_flags
  @flag_id = nil
  @app_id = nil
  set_flag_id_and_app_id(flag_name)
  @emit_redis_signal = emit_redis_signal
  @user_context = user_context
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



5
6
7
# File 'lib/tailslide/toggler.rb', line 5

def app_id
  @app_id
end

#emit_redis_signalObject (readonly)

Returns the value of attribute emit_redis_signal.



4
5
6
# File 'lib/tailslide/toggler.rb', line 4

def emit_redis_signal
  @emit_redis_signal
end

#flag_idObject

Returns the value of attribute flag_id.



5
6
7
# File 'lib/tailslide/toggler.rb', line 5

def flag_id
  @flag_id
end

#flag_nameObject (readonly)

Returns the value of attribute flag_name.



4
5
6
# File 'lib/tailslide/toggler.rb', line 4

def flag_name
  @flag_name
end

#get_flagsObject (readonly)

Returns the value of attribute get_flags.



4
5
6
# File 'lib/tailslide/toggler.rb', line 4

def get_flags
  @get_flags
end

#user_contextObject (readonly)

Returns the value of attribute user_context.



4
5
6
# File 'lib/tailslide/toggler.rb', line 4

def user_context
  @user_context
end

Instance Method Details

#emit_failureObject



29
30
31
32
33
# File 'lib/tailslide/toggler.rb', line 29

def emit_failure
  return unless flag_id

  emit_redis_signal.call(flag_id, app_id, 'failure')
end

#emit_successObject



22
23
24
25
26
27
# File 'lib/tailslide/toggler.rb', line 22

def emit_success
  return unless flag_id

  p 'emiting success'
  emit_redis_signal.call(flag_id, app_id, 'success')
end

#is_flag_activeObject



17
18
19
20
# File 'lib/tailslide/toggler.rb', line 17

def is_flag_active
  flag = get_matching_flag
  flag['is_active'] && (is_user_white_listed(flag) || validate_user_rollout(flag))
end