Class: Status
- Inherits:
-
Object
- Object
- Status
- Defined in:
- lib/confoog/status.rb
Overview
Provide error messages and console output when required.
Constant Summary collapse
- ERR_NO_ERROR =
No error condition exists
0
- ERR_FILE_NOT_EXIST =
The specified file does not exist
1
- ERR_CANT_CHANGE =
You cannot change location or filename after class is instantiated
2
- ERR_CANT_CREATE_FILE =
Was unable to create the specified file
4
- ERR_NOT_WRITING_EMPTY_FILE =
There are no configuration variables set, so not writing empty file
8
- ERR_CANT_SAVE_CONFIGURATION =
Cannot save to the specified file for some reason
16
- ERR_NOT_LOADING_EMPTY_FILE =
The specified file is empty so not trying to load settings from it
32
- ERR_CANT_LOAD =
Cannot load the specified file for some reason.
64
- INFO_FILE_CREATED =
Information - file was created successfully
256
- INFO_FILE_LOADED =
Information - configuration was successfully loaded
512
- OUTPUT_SEVERITY =
Hash containing text versions of the assorted error severity.
{ ERR: 'Error', WARN: 'Warning', INFO: 'Information' }
- ERROR_STRINGS =
Hash containing the error messages for each ERR condition. If an ERR does not have a message, there will be no output.
{ ERR_FILE_NOT_EXIST => 'The specified Configuration file does not exist.', ERR_CANT_CHANGE => 'Cannot change filename after creation', ERR_CANT_CREATE_FILE => 'Cannot create the specified Configuration file!', ERR_NOT_WRITING_EMPTY_FILE => 'Not saving empty configuration data!', ERR_CANT_SAVE_CONFIGURATION => 'Cannot save configuration data!', ERR_NOT_LOADING_EMPTY_FILE => 'The configuration file is empty!', ERR_CANT_LOAD => 'Cannot load configuration Data!' }
Instance Attribute Summary collapse
-
#prefix ⇒ String
String to pre-pend on any error put to console.
-
#quiet ⇒ Boolean
Do we output anything to console or not.
Instance Method Summary collapse
-
#[](key) ⇒ <various>
Read the value of a status.
-
#[]=(key, value) ⇒ <various>
Set the value of status.
-
#clear_error ⇒ Integer
Clear the error status.
-
#initialize(quiet, prefix) ⇒ Status
constructor
Class initializer.
-
#set(status) ⇒ Object
Set one or multiple status variables, optionally outputing a console message if one exists for that status.
Constructor Details
#initialize(quiet, prefix) ⇒ Status
Class initializer.
55 56 57 58 59 60 61 |
# File 'lib/confoog/status.rb', line 55 def initialize(quiet, prefix) # Initialize the status container to an empty hash. Will return nil # for missing keys by default. @status = {} @quiet = quiet @prefix = prefix end |
Instance Attribute Details
#prefix ⇒ String
Returns String to pre-pend on any error put to console.
5 6 7 |
# File 'lib/confoog/status.rb', line 5 def prefix @prefix end |
#quiet ⇒ Boolean
Returns Do we output anything to console or not.
8 9 10 |
# File 'lib/confoog/status.rb', line 8 def quiet @quiet end |
Instance Method Details
#[](key) ⇒ <various>
Read the value of a status.
75 76 77 |
# File 'lib/confoog/status.rb', line 75 def [](key) @status[key] end |
#[]=(key, value) ⇒ <various>
Set the value of status.
86 87 88 |
# File 'lib/confoog/status.rb', line 86 def []=(key, value) @status[key] = value end |
#clear_error ⇒ Integer
Clear the error status.
67 68 69 |
# File 'lib/confoog/status.rb', line 67 def clear_error @status[:errors] = ERR_NO_ERROR end |
#set(status) ⇒ Object
Set one or multiple status variables, optionally outputing a console message if one exists for that status.
96 97 98 99 100 101 102 103 |
# File 'lib/confoog/status.rb', line 96 def set(status) status.each do |key, value| @status[key] = value end return if ERROR_STRINGS[@status[:errors]].nil? severity = (@status[:errors] <= 64) ? 'Error' : 'Info' console_output(ERROR_STRINGS[@status[:errors]], severity) end |