Module: Kameleoon::Utils::VisitorCode
- Defined in:
- lib/kameleoon/utils.rb
Constant Summary collapse
- VISITOR_CODE_MAX_LENGTH =
255
- VISITOR_CODE_LENGTH =
16
Class Method Summary collapse
Class Method Details
.generate ⇒ Object
30 31 32 |
# File 'lib/kameleoon/utils.rb', line 30 def self.generate Utils.generate_random_string(VISITOR_CODE_LENGTH) end |
.validate(visitor_code) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/kameleoon/utils.rb', line 22 def self.validate(visitor_code) raise Kameleoon::Exception::VisitorCodeInvalid, 'Visitor Code is nil or invalidate type' unless visitor_code.is_a?(String) raise Kameleoon::Exception::VisitorCodeInvalid, 'Empty visitor Code' if visitor_code&.empty? if visitor_code.size > VISITOR_CODE_MAX_LENGTH raise Kameleoon::Exception::VisitorCodeInvalid, "Visitor Code is longer than #{VISITOR_CODE_MAX_LENGTH} chars" end end |