Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
 * Remove attr_accessor :quiet. Replace with getter & setter methods
   to access the new options hash.
 * Remove attr_accessor :prefix. No need for setting or getting this
   at any time. It's set by #new and no need to change.
 * Replace both the above instance variables with an options hash
   that the Settings class can use to store any internal settings.

Now even 'reek' notes no problems or code smells.

Signed-off-by: Seapagan <seapagan@gmail.com>
  • Loading branch information
seapagan committed Sep 14, 2015
1 parent af1b47a commit c6a090f
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/confoog/status.rb
Expand Up @@ -38,13 +38,6 @@ class Status
ERR_CANT_LOAD => 'Cannot load configuration Data!'
}

# @!attribute prefix
# @return [String] String to pre-pend on any error put to console
attr_accessor :prefix
# @!attribute quiet
# @return [Boolean] Do we output anything to console or not
attr_accessor :quiet

# Class initializer.
# @example
# status = Status.new(quiet: true, prefix: "My Fab App")
Expand All @@ -54,8 +47,24 @@ 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
# ititialize a hash to store our own internal options.
@options = {}
# and fill it.
@options[:quiet] = quiet
@options[:prefix] = prefix
end

# Set whether we output to the console or not
# @param quiet [Boolean] True to output Errors to the console.
# @return [Boolean] Value of #quiet
def quiet=(quiet)
@options[:quiet] = quiet
end

# return the current 'quiet' status
# @return [Boolean] Value of #quiet
def quiet
@options[:quiet]
end

# Clear the error status.
Expand Down Expand Up @@ -107,7 +116,7 @@ def error_string
# Display output to the console with the severity noted, unless we are quiet.
# @param [String] message
def console_output(message, severity)
return unless @quiet == false
$stderr.puts "#{@prefix} : #{severity} - #{message}"
return unless @options[:quiet] == false
$stderr.puts "#{@options[:prefix]} : #{severity} - #{message}"
end
end

0 comments on commit c6a090f

Please sign in to comment.