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.



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

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

Instance Method Details

#deleteObject



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

def delete
  Split.redis.del(goals_key)
end

#load_from_configurationObject



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

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

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

#load_from_redisObject



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

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

#saveObject



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

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

#validate!Object



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

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