Class: Split::GoalsCollection
- Inherits:
-
Object
- Object
- Split::GoalsCollection
- Defined in:
- lib/split/goals_collection.rb
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(experiment_name, goals = nil) ⇒ GoalsCollection
constructor
A new instance of GoalsCollection.
- #load_from_configuration ⇒ Object
- #load_from_redis ⇒ Object
- #save ⇒ Object
- #validate! ⇒ Object
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
#delete ⇒ Object
36 37 38 |
# File 'lib/split/goals_collection.rb', line 36 def delete Split.redis.del(goals_key) end |
#load_from_configuration ⇒ Object
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_redis ⇒ Object
11 12 13 |
# File 'lib/split/goals_collection.rb', line 11 def load_from_redis Split.redis.lrange(goals_key, 0, -1) end |
#save ⇒ Object
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 |