Sha256: f12fa129d0b88b3e724a95c4e58bef7fc900de525ec921b829860005b722d7f3

Contents?: true

Size: 826 Bytes

Versions: 8

Compression:

Stored size: 826 Bytes

Contents

module Split
  class GoalsCollection

    def initialize(experiment_name, goals=nil)
      @experiment_name = experiment_name
      @goals = goals
    end

    def load_from_redis
      Split.redis.lrange(goals_key, 0, -1)
    end

    def load_from_configuration
      goals = Split.configuration.experiment_for(@experiment_name)[:goals]

      if goals.nil?
        goals = []
      else
        goals.flatten
      end
    end

    def save
      return false if @goals.nil?
      RedisInterface.new.persist_list(goals_key, @goals)
    end

    def validate!
      unless @goals.nil? || @goals.kind_of?(Array)
        raise ArgumentError, 'Goals must be an array'
      end
    end

    def delete
      Split.redis.del(goals_key)
    end

    private

    def goals_key
      "#{@experiment_name}:goals"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
split-3.3.2 lib/split/goals_collection.rb
split-3.3.1 lib/split/goals_collection.rb
split-3.3.0 lib/split/goals_collection.rb
split-3.2.0 lib/split/goals_collection.rb
split-3.1.1 lib/split/goals_collection.rb
split-3.1.0 lib/split/goals_collection.rb
split-3.0.0 lib/split/goals_collection.rb
split-2.2.0 lib/split/goals_collection.rb