Class: EDango::Environment

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/edango/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



31
32
33
34
35
36
37
38
39
# File 'lib/edango/environment.rb', line 31

def initialize
  @arguments = ARGV

  @logger  = SERVICES[:logger]

  @options = PARAMETERS[:options]
  @modes   = PARAMETERS[:modes]
  @tasks   = PARAMETERS[:tasks]
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



26
27
28
# File 'lib/edango/environment.rb', line 26

def arguments
  @arguments
end

#loggerObject (readonly)

Returns the value of attribute logger.



28
29
30
# File 'lib/edango/environment.rb', line 28

def logger
  @logger
end

#modesObject (readonly)

Returns the value of attribute modes.



29
30
31
# File 'lib/edango/environment.rb', line 29

def modes
  @modes
end

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/edango/environment.rb', line 29

def options
  @options
end

#tasksObject (readonly)

Returns the value of attribute tasks.



29
30
31
# File 'lib/edango/environment.rb', line 29

def tasks
  @tasks
end

Instance Method Details

#log_error(exception, message) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/edango/environment.rb', line 41

def log_error(exception, message)
  @logger.error(message)
  @logger.error(exception.message)

  unless @modes.nil?
    @logger.error(exception.backtrace) if @modes[:verbose] or
                                          @modes[:debug]
  end

  GLOBALS[:errors_number] ||= 0
  GLOBALS[:errors_number] += 1
end

#log_message(text) ⇒ Object



58
59
60
# File 'lib/edango/environment.rb', line 58

def log_message(text)
  @logger.info(text)
end

#log_warning(text) ⇒ Object



54
55
56
# File 'lib/edango/environment.rb', line 54

def log_warning(text)
  @logger.warn(text)
end

#save_options(*args) ⇒ Object



72
73
74
# File 'lib/edango/environment.rb', line 72

def save_options(*args)
  PARAMETERS.update(*args)
end

#show_message(message, log = false) ⇒ Object



62
63
64
65
# File 'lib/edango/environment.rb', line 62

def show_message(message, log = false)
  puts(message) unless @modes[:quiet]
  log_message(message) if log
end

#state(message) ⇒ Object



67
68
69
70
# File 'lib/edango/environment.rb', line 67

def state(message)
  puts(message) if @modes[:verbose]
  log_message(message)
end