Sha256: f4326fa6bdb653bd7af3e8992b4ee81cb1594ce690d6a14bd92f01b256a48a60

Contents?: true

Size: 895 Bytes

Versions: 8

Compression:

Stored size: 895 Bytes

Contents

require 'ostruct'

module AbPanel
  class Config
    def initialize
      OpenStruct.new settings
    end

    def experiments
      return {} if !settings
      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
      return @settings if defined?(@settings)
      results = YAML.load(ERB.new(File.read(File.join(Rails.root, 'config', 'ab_panel.yml'))).result)
      @settings = results ? results.symbolize_keys : nil
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ab_panel-0.4.4 lib/ab_panel/config.rb
ab_panel-0.4.3 lib/ab_panel/config.rb
ab_panel-0.4.2 lib/ab_panel/config.rb
ab_panel-0.4.1 lib/ab_panel/config.rb
ab_panel-0.4.0 lib/ab_panel/config.rb
ab_panel-0.3.3 lib/ab_panel/config.rb
ab_panel-0.3.2 lib/ab_panel/config.rb
ab_panel-0.3.1 lib/ab_panel/config.rb