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.
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
#delete ⇒ Object
35 36 37 |
# File 'lib/split/goals_collection.rb', line 35 def delete Split.redis.del(goals_key) end |
#load_from_configuration ⇒ Object
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 goals.flatten else [] end end |
#load_from_redis ⇒ Object
10 11 12 |
# File 'lib/split/goals_collection.rb', line 10 def load_from_redis Split.redis.lrange(goals_key, 0, -1) end |
#save ⇒ Object
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 |