Class: TokenMaster::Config
- Inherits:
-
Object
- Object
- TokenMaster::Config
- Defined in:
- lib/token_master/config.rb
Overview
TokenMaster::Config
manages the configuration options for tokenable actions. These can be set with the initializer provided with the generator. Default values will be used if options are not specified
Constant Summary collapse
- DEFAULT_VALUES =
Provides default values for a tokenable action:
token_lifetime
is an integer representing the number of days before the token expiresrequired_params
is an array of symbols, e.g.,[:password, :password_confirmation]
token_length
is an integer representing the number of characters in the token
{ token_lifetime: 14, required_params: [], token_length: 20 }
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#add_tokenable_options(key, **params) ⇒ Object
Sets the key-value pairs needed to complete a tokenable action
Key-value pairs used to complete a tokenable action are thetoken_lifetime
,required_params
(can be blank), andtoken_length
. -
#get_required_params(key) ⇒ Array
Retrieves the
required_params
for a tokenable_action, either as set by the application, or by the default
Used to update model attributes as needed for a given tokenable action. -
#get_token_length(key) ⇒ Integer
Retrieves the
token_length
for a tokenable action, either as set by the application, or by the default. -
#get_token_lifetime(key) ⇒ Integer
Retrieves the
token_lifetime
for a tokenable action, either as set by the application, or by the default. -
#initialize ⇒ Config
constructor
Creates a new instance of
TokenMaster::Config
. -
#options_set?(key) ⇒ Boolean
Determines whether options are provided for a tokenable action.
Constructor Details
#initialize ⇒ Config
Creates a new instance of TokenMaster::Config
18 19 20 |
# File 'lib/token_master/config.rb', line 18 def initialize @options = {} end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/token_master/config.rb', line 15 def @options end |
Instance Method Details
#add_tokenable_options(key, **params) ⇒ Object
Sets the key-value pairs needed to complete a tokenable action
Key-value pairs used to complete a tokenable action are the token_lifetime
, required_params
(can be blank), and token_length
33 34 35 |
# File 'lib/token_master/config.rb', line 33 def (key, **params) @options[key] = params end |
#get_required_params(key) ⇒ Array
Retrieves the required_params
for a tokenable_action, either as set by the application, or by the default
Used to update model attributes as needed for a given tokenable action
40 41 42 |
# File 'lib/token_master/config.rb', line 40 def get_required_params(key) get_option(key, :required_params) end |
#get_token_length(key) ⇒ Integer
Retrieves the token_length
for a tokenable action, either as set by the application, or by the default
54 55 56 |
# File 'lib/token_master/config.rb', line 54 def get_token_length(key) get_option(key, :token_length) end |
#get_token_lifetime(key) ⇒ Integer
Retrieves the token_lifetime
for a tokenable action, either as set by the application, or by the default
47 48 49 |
# File 'lib/token_master/config.rb', line 47 def get_token_lifetime(key) get_option(key, :token_lifetime) end |
#options_set?(key) ⇒ Boolean
Determines whether options are provided for a tokenable action
61 62 63 |
# File 'lib/token_master/config.rb', line 61 def (key) @options.key? key end |