Module: SplitCat::Helpers

Defined in:
lib/split_cat/helpers.rb

Instance Method Summary collapse

Instance Method Details

#set_split_cat_cookie



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/split_cat/helpers.rb', line 47

def set_split_cat_cookie( options = {} )
  @split_cat_token = cookies[ :split_cat_token ]

  # Create a Subject for the cookie token, if it doesn't exist

 if @split_cat_token && !Subject.where( :token => @split_cat_token ).first
   split_cat_token( @split_cat_token )
 end

 if options[ :force ] || !@split_cat_token
   expires = SplitCat.config.cookie_expiration.from_now
   @split_cat_token = split_cat_token
   cookies[ :split_cat_token ] = { :value => @split_cat_token, :expires => expires }
 end

  return @split_cat_token
end

#split_cat_goal(name, goal, token) ⇒ Object

#split_cat_goal



14
15
16
17
18
19
20
21
# File 'lib/split_cat/helpers.rb', line 14

def split_cat_goal( name, goal, token )
  unless experiment = Experiment.factory( name )
    Rails.logger.error( "Experiment.goal failed to find experiment: #{name}" )
    return false
  end

  return experiment.record_goal( goal, token )
end

#split_cat_hypothesis(name, token) ⇒ Object

#split_cat_hypothesis



26
27
28
29
30
31
32
33
34
# File 'lib/split_cat/helpers.rb', line 26

def split_cat_hypothesis( name, token )
  unless experiment = Experiment.factory( name )
    Rails.logger.error( "Experiment.hypothesis failed to find experiment: #{name}" )
    return nil
  end

  h = experiment.get_hypothesis( token )
  return h ? h.name.to_sym : nil
end

#split_cat_scope(root, name, token, hypothesis = nil) ⇒ Object

#split_cat_scope



39
40
41
42
# File 'lib/split_cat/helpers.rb', line 39

def split_cat_scope( root, name, token, hypothesis = nil )
  hypothesis = split_cat_hypothesis( name, token ) unless hypothesis
  return root + '_' + hypothesis.to_s
end

#split_cat_token(value = nil) ⇒ Object

#split_cat_token



7
8
9
# File 'lib/split_cat/helpers.rb', line 7

def split_cat_token( value = nil )
  SplitCat::Subject.create( :token => value ).token
end