Class: Experimental::Loader
- Inherits:
-
Object
- Object
- Experimental::Loader
- Defined in:
- lib/experimental/loader.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Loader
constructor
A new instance of Loader.
- #sync ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Loader
Returns a new instance of Loader.
5 6 7 |
# File 'lib/experimental/loader.rb', line 5 def initialize( = {}) @logger = [:logger] || Logger.new('/dev/null') end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/experimental/loader.rb', line 9 def logger @logger end |
Instance Method Details
#sync ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/experimental/loader.rb', line 11 def sync logger.info "Synchronizing experiments..." Experimental::Experiment.transaction do active = Experimental.experiment_data.map do |name, attributes| experiment = Experimental::Experiment.find_or_initialize_by_name(name) logger.info " * #{experiment.id ? 'updating' : 'creating'} #{name}" defaults = {'num_buckets' => nil, 'notes' => nil, 'population' => nil} experiment.assign_attributes(defaults.merge(attributes)) experiment.start_date ||= Time.now experiment.tap(&:save!) end scope = Experimental::Experiment.in_code scope = scope.where('id NOT IN (?)', active.map(&:id)) unless active.empty? scope.find_each do |experiment| next if experiment.admin? logger.info " * removing #{experiment.name}" experiment.remove end end logger.info "Done." end |