Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config documentation #35

Merged
merged 3 commits into from
Apr 24, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/token_master/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module TokenMaster
# `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
class Config

# Provides default values for a tokenable action
DEFAULT_VALUES = {
token_lifetime: 14,
required_params: [],
Expand All @@ -8,26 +11,39 @@ class Config

attr_accessor :options

# Creates a new instance of `TokenMaster::Config`
def initialize
@options = {}
end

# Sets the option parameters for the tokenable action
# @param [Symbol] key the tokenable action
# @param [Symbol=>[Integer, String, Array]] params the option parameters
def add_tokenable_options(key, **params)
@options[key] = params
end

# @param [Symbol] key the tokenable action
# @return [Array] the `required_params` for a tokenable action
def get_required_params(key)
get_option(key, :required_params)
end

# @param [Symbol] key the tokenable action
# @return [Integer] the `token_lifetime` for a tokenable action
def get_token_lifetime(key)
get_option(key, :token_lifetime)
end

# @param [Symbol] key the tokenable action
# @return [Integer] the `token_length` for a tokenable action
def get_token_length(key)
get_option(key, :token_length)
end

# Determines whether options are provided for a tokenable action
# @param [Symbol] key the tokenable action
# @return [Boolean] `true` => options are set; `false` => options are not set
def options_set?(key)
@options.key? key
end
Expand Down