Class: Helena::Session

Inherits:
Object
  • Object
show all
Includes:
Concerns::ApplicationModel
Defined in:
app/models/helena/session.rb

Instance Method Summary collapse

Instance Method Details

#answers_as_hashObject



44
45
46
# File 'app/models/helena/session.rb', line 44

def answers_as_hash
  Hash[*answers.map { |answer| [answer[:code], answer[:value]] }.flatten]
end

#answers_as_yamlObject



22
23
24
# File 'app/models/helena/session.rb', line 22

def answers_as_yaml
  Hash[answers.map { |answer| [answer.code, answer.value] }.sort].to_yaml
end

#answers_as_yaml=(yaml) ⇒ Object



26
27
28
29
# File 'app/models/helena/session.rb', line 26

def answers_as_yaml=(yaml)
  parsed_answers = YAML.load yaml # rubocop:disable Security/YAMLLoad
  update_answers parsed_answers
end

#as_json(options) ⇒ Object



38
39
40
41
42
# File 'app/models/helena/session.rb', line 38

def as_json(options)
  session = super(options)
  session[:answer] = answers_as_hash
  session
end

#reset_tokensObject



31
32
33
34
35
36
# File 'app/models/helena/session.rb', line 31

def reset_tokens
  # NOTE: there are (2*26+10)^k tokens available
  # To not run into performance issues we could pregenerate unique tokens in the future
  self.token = generate_token(5) until unique_token_for?
  self.view_token = generate_token(25) until unique_token_for?(:view_token)
end