Class: Split::GoalsCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/split/goals_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(experiment_name, goals = nil) ⇒ GoalsCollection

Returns a new instance of GoalsCollection.


4
5
6
7
# File 'lib/split/goals_collection.rb', line 4

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

Instance Method Details

#deleteObject


34
35
36
# File 'lib/split/goals_collection.rb', line 34

def delete
  Split.redis.del(goals_key)
end

#load_from_configurationObject


13
14
15
16
17
18
19
20
21
# File 'lib/split/goals_collection.rb', line 13

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

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

#load_from_redisObject


9
10
11
# File 'lib/split/goals_collection.rb', line 9

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

#saveObject


23
24
25
26
# File 'lib/split/goals_collection.rb', line 23

def save
  return false if @goals.nil?
  @goals.reverse.each { |goal| Split.redis.lpush(goals_key, goal) }
end

#validate!Object


28
29
30
31
32
# File 'lib/split/goals_collection.rb', line 28

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