Sha256: 1611d6bdb2137c397b7f88d93fdf203ad59b25998d0dfb2c8ceb3497eebbd26c

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 Bytes

Contents

require 'ostruct'

module AbPanel
  class Config
    def initialize
      OpenStruct.new settings
    end

    def experiments
      settings.keys.map(&:to_sym)
    end

    def scenarios(experiment)
      raise ArgumentError.new( "Fatal: Experiment config not found for #{experiment}" ) unless experiments.include? experiment.to_sym
      ( settings[experiment.to_sym].keys.map(&:to_sym)).uniq
    end

    def weights(experiment)
      raise ArgumentError.new( "Fatal: Experiment config not found for #{experiment}" ) unless experiments.include? experiment.to_sym
      settings[experiment.to_sym].map { |s| s[1] }
    end

    def settings
      @settings ||= YAML.load(
        ERB.new(File.read(File.join(Rails.root, 'config', 'ab_panel.yml'))).result)
        .symbolize_keys
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ab_panel-0.3.0 lib/ab_panel/config.rb