Class: TrailGuide::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- TrailGuide::Engine
- Defined in:
- lib/trail_guide/engine.rb
Defined Under Namespace
Classes: DSL
Class Method Summary collapse
Class Method Details
.load_experiments ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trail_guide/engine.rb', line 15 def self.load_experiments # Load experiments from YAML configs if any exists load_yaml_experiments(Rails.root.join("config/experiments.yml")) Dir[Rails.root.join("config/experiments/**/*.yml")].each { |f| load_yaml_experiments(f) } # Load experiments from ruby configs if any exist DSL.instance_eval(File.read(Rails.root.join("config/experiments.rb"))) if File.exists?(Rails.root.join("config/experiments.rb")) Dir[Rails.root.join("config/experiments/**/*.rb")].each { |f| DSL.instance_eval(File.read(f)) } # Load any experiment classes defined in the app Dir[Rails.root.join("app/experiments/**/*.rb")].each { |f| load f } end |
.load_yaml_experiments(file) ⇒ Object
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 |
# File 'lib/trail_guide/engine.rb', line 28 def self.load_yaml_experiments(file) experiments = (YAML.load_file(file) || {} rescue {}) .symbolize_keys.map { |k,v| [k, v.symbolize_keys] }.to_h experiments.each do |name, | expvars = [:variants].map do |var| if var.is_a?(Array) [var[0], var[1].symbolize_keys] else [var] end end DSL.experiment(name) do expvars.each do |expvar| variant *expvar end control [:control] if [:control] algorithm [:algorithm] if [:algorithm] goals [:goals] if [:goals] metric [:metric] if [:metric] resettable [:resettable] if .key?(:resettable) allow_multiple_conversions [:allow_multiple_conversions] if .key?(:allow_multiple_conversions) allow_multiple_goals [:allow_multiple_goals] if .key?(:allow_multiple_goals) end end end |