Class: Experimental::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/experimental/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Loader

Returns a new instance of Loader.



5
6
7
# File 'lib/experimental/loader.rb', line 5

def initialize(options = {})
  @logger = options[:logger] || Logger.new('/dev/null')
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/experimental/loader.rb', line 9

def logger
  @logger
end

Instance Method Details

#syncObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/experimental/loader.rb', line 11

def sync
  logger.info "Synchronizing experiments..."

  Experimental::Experiment.transaction do
    all_experiments = Experimental::Experiment.in_code
    active_experiments = create_or_update_active_experiments

    if active_experiments.present?
      active_ids = active_experiments.map(&:id)
      remove(all_experiments.where('id NOT IN (?)', active_ids))
    else
      remove(all_experiments)
    end
  end

  logger.info "Done."
end