Class: ActiveGenie::Config::LogConfig

Inherits:
BaseConfig
  • Object
show all
Defined in:
lib/active_genie/configs/log_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseConfig

#attributes, #initialize, #to_h

Constructor Details

This class inherits a constructor from ActiveGenie::Config::BaseConfig

Instance Attribute Details

#file_pathObject



11
12
13
# File 'lib/active_genie/configs/log_config.rb', line 11

def file_path
  @file_path ||= 'log/active_genie.log'
end

#fine_tune_file_pathObject



15
16
17
# File 'lib/active_genie/configs/log_config.rb', line 15

def fine_tune_file_path
  @fine_tune_file_path ||= 'log/active_genie_fine_tune.log'
end

#outputObject

Returns the value of attribute output.



8
9
10
# File 'lib/active_genie/configs/log_config.rb', line 8

def output
  @output
end

Instance Method Details

#add_observer(observers: [], scope: {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_genie/configs/log_config.rb', line 44

def add_observer(observers: [], scope: {}, &block)
  @observers ||= []

  raise ArgumentError, 'Scope must be a hash' if scope && !scope.is_a?(Hash)

  Array(observers).each do |observer|
    next unless observer.respond_to?(:call)

    @observers << { observer:, scope: }
  end
  @observers << { observer: block, scope: } if block_given?
end

#additional_contextObject



29
30
31
# File 'lib/active_genie/configs/log_config.rb', line 29

def additional_context
  @additional_context ||= {}
end

#additional_context=(context) ⇒ Object



33
34
35
# File 'lib/active_genie/configs/log_config.rb', line 33

def additional_context=(context)
  @additional_context = additional_context.merge(context || {}).compact
end

#clear_observersObject



63
64
65
# File 'lib/active_genie/configs/log_config.rb', line 63

def clear_observers
  @observers = []
end

#observersObject



25
26
27
# File 'lib/active_genie/configs/log_config.rb', line 25

def observers
  @observers ||= []
end

#observers=(observers) ⇒ Object



19
20
21
22
23
# File 'lib/active_genie/configs/log_config.rb', line 19

def observers=(observers)
  Array(observers).each do |observer|
    add_observer(observers: [observer[:observer]], scope: observer[:scope] || {})
  end
end

#remove_observer(observers) ⇒ Object



57
58
59
60
61
# File 'lib/active_genie/configs/log_config.rb', line 57

def remove_observer(observers)
  Array(observers).each do |observer|
    @observers.delete_if { |obs| obs[:observer] == observer }
  end
end