Module: LaserLemon::HasToken::InstanceMethods

Defined in:
lib/has_token.rb

Instance Method Summary collapse

Instance Method Details

#has_token_optionsObject



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

def has_token_options
  self.class.has_token_options
end

#has_token_valueObject



40
41
42
# File 'lib/has_token.rb', line 40

def has_token_value
  Array.new(has_token_options[:length]){ has_token_options[:characters].rand }.join
end

#set_tokenObject



44
45
46
47
48
49
50
51
# File 'lib/has_token.rb', line 44

def set_token
  begin
    token_value = has_token_options[:constructor].call(self)
  end while Token.exists?(:value => token_value)
  
  build_global_token(:value => token_value)
  write_attribute(has_token_options[:column], token_value)
end