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.



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

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

Instance Method Details

#deleteObject



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

def delete
  Split.redis.del(goals_key)
end

#load_from_configurationObject



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

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

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

#load_from_redisObject



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

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

#saveObject



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

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

#validate!Object



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

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