Sha256: 4975dc6ee45b935a9ee1dcab4ae0b8200d6e835b49d55b637a85fef2b5b4e52c

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

class ExperimentLight::Experiment
  class << self
    def on?(experiment_name)
      experiment_feature_data

      reload! unless @experiment_data.has_key?(experiment_name)

      unless @experiment_data.has_key?(experiment_name)
        raise "Cannot find experiment '#{experiment_name}', check out your experiment.yml file"
      end

      @experiment_data[experiment_name][Rails.env]
    end

    def off?(experiment_name)
      !on?(experiment_name)
    end

    private
    def default_experiment_file_name
      'experiment.yml'
    end

    def load(file_name)
      file_path = Rails.root.join('config', file_name)
      HashWithIndifferentAccess.new(YAML::load(File.open(file_path)))
    end

    def reload!
      @experiment_data = load(default_experiment_file_name)
    end

    def experiment_feature_data
      @experiment_data ||= load(default_experiment_file_name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
experiment_light-0.2.0 lib/experiment_light/experiment.rb
experiment_light-0.1.0 lib/experiment_light/experiment.rb