class JwtMe::InputContainer
Encapsulates user's input and delegate running validations to specific Validator
Constants
- VALIDATORS
Attributes
storage[R]
Public Class Methods
new()
click to toggle source
# File lib/jwt_me/input_container.rb, line 15 def initialize @storage = {} end
Public Instance Methods
add_key_value()
click to toggle source
# File lib/jwt_me/input_container.rb, line 19 def add_key_value key = ask(key_number) if @storage.key?(key) || key.empty? say "Key is invalid or it's taken. Please choose another one." add_key_value else ask_value(key) end end
Private Instance Methods
ask_value(key)
click to toggle source
# File lib/jwt_me/input_container.rb, line 32 def ask_value(key) value = ask "Enter #{key} value:" validate(key, value) @storage[key] = value rescue JwtMe::ValidationError => e say e.to_s ask_value(key) end
key_number()
click to toggle source
# File lib/jwt_me/input_container.rb, line 41 def key_number "Enter key #{@storage.count + 1}" end
validate(key, value)
click to toggle source
# File lib/jwt_me/input_container.rb, line 45 def validate(key, value) VALIDATORS[key].call(value) if VALIDATORS.keys.include?(key) end