Class: Optimizely::OptimizelyFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/optimizely/optimizely_factory.rb

Class Method Summary collapse

Class Method Details

.blocking_timeout(blocking_timeout) ⇒ Object

Convenience method for setting timeout to block the config call until config has been initialized.



82
83
84
# File 'lib/optimizely/optimizely_factory.rb', line 82

def self.blocking_timeout(blocking_timeout)
  @blocking_timeout = blocking_timeout
end

.custom_instance(sdk_key, datafile = nil, event_dispatcher = nil, logger = nil, error_handler = nil, skip_json_validation = false, user_profile_service = nil, config_manager = nil, notification_center = nil) ⇒ Object

Returns a new optimizely instance.

if @max_event_batch_size and @max_event_flush_interval are nil then default batchsize and flush_interval will be used to setup batchEventProcessor.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/optimizely/optimizely_factory.rb', line 132

def self.custom_instance(
  sdk_key,
  datafile = nil,
  event_dispatcher = nil,
  logger = nil,
  error_handler = nil,
  skip_json_validation = false,
   = nil,
  config_manager = nil,
  notification_center = nil
)

  error_handler ||= NoOpErrorHandler.new
  logger ||= NoOpLogger.new
  notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(logger, error_handler)

  event_processor = BatchEventProcessor.new(
    event_dispatcher: event_dispatcher || EventDispatcher.new,
    batch_size: @max_event_batch_size,
    flush_interval: @max_event_flush_interval,
    logger: logger,
    notification_center: notification_center
  )

  config_manager ||= Optimizely::HTTPProjectConfigManager.new(
    sdk_key: sdk_key,
    polling_interval: @polling_interval,
    blocking_timeout: @blocking_timeout,
    datafile: datafile,
    logger: logger,
    error_handler: error_handler,
    skip_json_validation: skip_json_validation,
    notification_center: notification_center
  )

  Optimizely::Project.new(
    datafile,
    event_dispatcher,
    logger,
    error_handler,
    skip_json_validation,
    ,
    sdk_key,
    config_manager,
    notification_center,
    event_processor
  )
end

.default_instance(sdk_key, datafile = nil) ⇒ Object

Returns a new optimizely instance.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/optimizely/optimizely_factory.rb', line 90

def self.default_instance(sdk_key, datafile = nil)
  error_handler = NoOpErrorHandler.new
  logger = NoOpLogger.new
  notification_center = NotificationCenter.new(logger, error_handler)

  config_manager = Optimizely::HTTPProjectConfigManager.new(
    sdk_key: sdk_key,
    polling_interval: @polling_interval,
    blocking_timeout: @blocking_timeout,
    datafile: datafile,
    logger: logger,
    error_handler: error_handler,
    notification_center: notification_center
  )

  Optimizely::Project.new(
    datafile, nil, logger, error_handler, nil, nil, sdk_key, config_manager, notification_center
  )
end

.default_instance_with_config_manager(config_manager) ⇒ Object

Returns a new optimizely instance.



113
114
115
# File 'lib/optimizely/optimizely_factory.rb', line 113

def self.default_instance_with_config_manager(config_manager)
  Optimizely::Project.new(nil, nil, nil, nil, nil, nil, nil, config_manager)
end

.max_event_batch_size(batch_size, logger = NoOpLogger.new) ⇒ Object

Convenience method for setting the maximum number of events contained within a batch.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/optimizely/optimizely_factory.rb', line 31

def self.max_event_batch_size(batch_size, logger = NoOpLogger.new)
  unless batch_size.is_a? Integer
    logger.log(
      Logger::ERROR,
      "Batch size is invalid, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}."
    )
    return
  end

  unless batch_size.positive?
    logger.log(
      Logger::ERROR,
      "Batch size is negative, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}."
    )
    return
  end
  @max_event_batch_size = batch_size
end

.max_event_flush_interval(flush_interval, logger = NoOpLogger.new) ⇒ Object

Convenience method for setting the maximum time interval in milliseconds between event dispatches.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/optimizely/optimizely_factory.rb', line 53

def self.max_event_flush_interval(flush_interval, logger = NoOpLogger.new)
  unless flush_interval.is_a? Numeric
    logger.log(
      Logger::ERROR,
      "Flush interval is invalid, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}."
    )
    return
  end

  unless flush_interval.positive?
    logger.log(
      Logger::ERROR,
      "Flush interval is negative, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}."
    )
    return
  end
  @max_event_flush_interval = flush_interval
end

.polling_interval(polling_interval) ⇒ Object

Convenience method for setting frequency at which datafile has to be polled and ProjectConfig updated.



75
76
77
# File 'lib/optimizely/optimizely_factory.rb', line 75

def self.polling_interval(polling_interval)
  @polling_interval = polling_interval
end