Class: FeatBit::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/featbit/options.rb

Constant Summary collapse

DEFAULT_STREAMING_URL =
"wss://app-eval.featbit.co"
DEFAULT_EVENT_URL =
"https://app-eval.featbit.co"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env_secret: "", streaming_url: DEFAULT_STREAMING_URL, event_url: DEFAULT_EVENT_URL, start_wait: 5.0, offline: false, bootstrap: nil, disable_events: false, logger: nil, events_capacity: 10_000, events_flush_interval: 1.0, events_batch_size: 50, connect_timeout: 5.0, read_timeout: 10.0, reconnect_delay: 1.0, data_store: nil, synchronizer_factory: nil, event_processor_factory: nil) ⇒ Options

Returns a new instance of Options.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/featbit/options.rb', line 17

def initialize(env_secret: "", streaming_url: DEFAULT_STREAMING_URL,
               event_url: DEFAULT_EVENT_URL, start_wait: 5.0, offline: false,
               bootstrap: nil, disable_events: false, logger: nil,
               events_capacity: 10_000, events_flush_interval: 1.0,
               events_batch_size: 50, connect_timeout: 5.0,
               read_timeout: 10.0, reconnect_delay: 1.0,
               data_store: nil, synchronizer_factory: nil,
               event_processor_factory: nil)
  @env_secret = env_secret.to_s
  @streaming_url = normalize_url(streaming_url)
  @event_url = normalize_url(event_url)
  @start_wait = positive_number(start_wait, 5.0)
  @offline = offline == true
  @bootstrap = bootstrap
  @disable_events = disable_events == true
  @logger = logger || Logger.new($stderr, level: Logger::WARN)
  @events_capacity = positive_integer(events_capacity, 10_000)
  @events_flush_interval = positive_number(events_flush_interval, 1.0)
  @events_batch_size = positive_integer(events_batch_size, 50)
  @connect_timeout = positive_number(connect_timeout, 5.0)
  @read_timeout = positive_number(read_timeout, 10.0)
  @reconnect_delay = positive_number(reconnect_delay, 1.0)
  @data_store = data_store
  @synchronizer_factory = synchronizer_factory
  @event_processor_factory = event_processor_factory
  freeze
rescue StandardError => e
  warn("FeatBit options error: #{e.message}")
  @env_secret = ""
  @streaming_url = DEFAULT_STREAMING_URL
  @event_url = DEFAULT_EVENT_URL
  @start_wait = 5.0
  @offline = true
  @bootstrap = nil
  @disable_events = true
  @logger = Logger.new($stderr, level: Logger::WARN)
  @events_capacity = 10_000
  @events_flush_interval = 1.0
  @events_batch_size = 50
  @connect_timeout = 5.0
  @read_timeout = 10.0
  @reconnect_delay = 1.0
  freeze
end

Instance Attribute Details

#bootstrapObject (readonly)

Returns the value of attribute bootstrap.



11
12
13
# File 'lib/featbit/options.rb', line 11

def bootstrap
  @bootstrap
end

#connect_timeoutObject (readonly)

Returns the value of attribute connect_timeout.



11
12
13
# File 'lib/featbit/options.rb', line 11

def connect_timeout
  @connect_timeout
end

#data_storeObject (readonly)

Returns the value of attribute data_store.



11
12
13
# File 'lib/featbit/options.rb', line 11

def data_store
  @data_store
end

#disable_eventsObject (readonly)

Returns the value of attribute disable_events.



11
12
13
# File 'lib/featbit/options.rb', line 11

def disable_events
  @disable_events
end

#env_secretObject (readonly)

Returns the value of attribute env_secret.



11
12
13
# File 'lib/featbit/options.rb', line 11

def env_secret
  @env_secret
end

#event_processor_factoryObject (readonly)

Returns the value of attribute event_processor_factory.



11
12
13
# File 'lib/featbit/options.rb', line 11

def event_processor_factory
  @event_processor_factory
end

#event_urlObject (readonly)

Returns the value of attribute event_url.



11
12
13
# File 'lib/featbit/options.rb', line 11

def event_url
  @event_url
end

#events_batch_sizeObject (readonly)

Returns the value of attribute events_batch_size.



11
12
13
# File 'lib/featbit/options.rb', line 11

def events_batch_size
  @events_batch_size
end

#events_capacityObject (readonly)

Returns the value of attribute events_capacity.



11
12
13
# File 'lib/featbit/options.rb', line 11

def events_capacity
  @events_capacity
end

#events_flush_intervalObject (readonly)

Returns the value of attribute events_flush_interval.



11
12
13
# File 'lib/featbit/options.rb', line 11

def events_flush_interval
  @events_flush_interval
end

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/featbit/options.rb', line 11

def logger
  @logger
end

#offlineObject (readonly)

Returns the value of attribute offline.



11
12
13
# File 'lib/featbit/options.rb', line 11

def offline
  @offline
end

#read_timeoutObject (readonly)

Returns the value of attribute read_timeout.



11
12
13
# File 'lib/featbit/options.rb', line 11

def read_timeout
  @read_timeout
end

#reconnect_delayObject (readonly)

Returns the value of attribute reconnect_delay.



11
12
13
# File 'lib/featbit/options.rb', line 11

def reconnect_delay
  @reconnect_delay
end

#start_waitObject (readonly)

Returns the value of attribute start_wait.



11
12
13
# File 'lib/featbit/options.rb', line 11

def start_wait
  @start_wait
end

#streaming_urlObject (readonly)

Returns the value of attribute streaming_url.



11
12
13
# File 'lib/featbit/options.rb', line 11

def streaming_url
  @streaming_url
end

#synchronizer_factoryObject (readonly)

Returns the value of attribute synchronizer_factory.



11
12
13
# File 'lib/featbit/options.rb', line 11

def synchronizer_factory
  @synchronizer_factory
end

Instance Method Details

#events_uriObject



66
67
68
# File 'lib/featbit/options.rb', line 66

def events_uri
  append_path(event_url, "/api/public/insight/track")
end

#streaming_uriObject



62
63
64
# File 'lib/featbit/options.rb', line 62

def streaming_uri
  append_path(streaming_url, "/streaming")
end

#valid?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
# File 'lib/featbit/options.rb', line 70

def valid?
  return true if offline

  !env_secret.empty? && valid_uri?(streaming_uri, %w[ws wss]) && valid_uri?(events_uri, %w[http https])
rescue StandardError
  false
end