Class: Scriptster::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/scriptster/configuration.rb

Overview

The configuration obejct used in the configure method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration



40
41
42
43
44
45
46
# File 'lib/scriptster/configuration.rb', line 40

def initialize
  @name = File.basename($0)
  @verbosity = :verbose
  @file = nil
  @colours = :dark
  @log_format = "%{timestamp} %{name} %{type} %{message}"
end

Instance Attribute Details

#coloursSymbol, Proc

Desired colour theme (either predefined or custom Proc).



37
38
39
# File 'lib/scriptster/configuration.rb', line 37

def colours
  @colours
end

#fileString, ...

A log file that all messages will be written to.



37
38
39
# File 'lib/scriptster/configuration.rb', line 37

def file
  @file
end

#log_formatString

Template for each line in the logs



37
38
39
# File 'lib/scriptster/configuration.rb', line 37

def log_format
  @log_format
end

#nameString

The name of the script to be displayed in the logs.



37
38
39
# File 'lib/scriptster/configuration.rb', line 37

def name
  @name
end

#timestampsBoolean

Include timestamps in log messages.



37
38
39
# File 'lib/scriptster/configuration.rb', line 37

def timestamps
  @timestamps
end

#verbositySymbol

The minimum verbosity to of messages to be displayed.



37
38
39
# File 'lib/scriptster/configuration.rb', line 37

def verbosity
  @verbosity
end

Instance Method Details

#applyObject

Put the settings from this object in effect.

This function will distribute the configuration to the appropriate objects and modules.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/scriptster/configuration.rb', line 52

def apply
  Logger.set_name @name if @name
  Logger.set_verbosity @verbosity if @verbosity
  Logger.set_file @file if @file
  Logger.set_format @log_format if @log_format

  if @colours.is_a? Proc
    @colours.call
  else
    ColourThemes.send @colours.to_sym
  end
end