Class: FlagManager

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

Direct Known Subclasses

Tailslide::FlagManager

Instance Method Summary collapse

Constructor Details

#initialize(nats_server: '', stream: '', app_id: '', sdk_key: '', user_context: '', redis_host: '', redis_port: '') ⇒ FlagManager

Returns a new instance of FlagManager.



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

def initialize(nats_server: '', stream: '', app_id: '', sdk_key: '', user_context: '', redis_host: '', redis_port: '')
  @nats_client = NatsClient.new(server_url: nats_server, stream: stream, subject: app_id, callback: method(:set_flags),
                                token: sdk_key)
  @redis_ts_client = RedisTimeSeriesClient.new(redis_host, redis_port)
  @user_context = user_context
  @flags = []
end

Instance Method Details

#disconnectObject



36
37
38
39
# File 'lib/tailslide/flag_manager.rb', line 36

def disconnect
  @nats_client.disconnect
  @redis_ts_client.disconnect
end

#get_flagsObject



24
25
26
# File 'lib/tailslide/flag_manager.rb', line 24

def get_flags
  @flags
end

#get_user_contextObject



32
33
34
# File 'lib/tailslide/flag_manager.rb', line 32

def get_user_context
  @user_context
end

#initialize_flagsObject



15
16
17
18
# File 'lib/tailslide/flag_manager.rb', line 15

def initialize_flags
  @nats_client.initialize_flags
  @redis_ts_client.init
end

#new_toggler(config) ⇒ Object



41
42
43
44
# File 'lib/tailslide/flag_manager.rb', line 41

def new_toggler(config)
  Toggler.new(**config, get_flags: method(:get_flags), user_context: get_user_context,
                        emit_redis_signal: @redis_ts_client.method(:emit_signal))
end

#set_flags(flags) ⇒ Object



20
21
22
# File 'lib/tailslide/flag_manager.rb', line 20

def set_flags(flags)
  @flags = flags
end

#set_user_context(new_user_context) ⇒ Object



28
29
30
# File 'lib/tailslide/flag_manager.rb', line 28

def set_user_context(new_user_context)
  @user_context = new_user_context
end