<commit_before>$:.unshift File.dirname(__FILE__)     # For use/testing when no gem is installed

# core
require 'stringio'
require 'logger'

# stdlib
require 'syslog'

# internal requires
require 'god/errors'
require 'god/logger'
require 'god/system/process'
require 'god/dependency_graph'
require 'god/timeline'
require 'god/configurable'

require 'god/task'

require 'god/behavior'
require 'god/behaviors/clean_pid_file'
require 'god/behaviors/notify_when_flapping'

require 'god/condition'
require 'god/conditions/process_running'
require 'god/conditions/process_exits'
require 'god/conditions/tries'
require 'god/conditions/memory_usage'
require 'god/conditions/cpu_usage'
require 'god/conditions/always'
require 'god/conditions/lambda'
require 'god/conditions/degrading_lambda'
require 'god/conditions/flapping'
require 'god/conditions/http_response_code'

require 'god/contact'
require 'god/contacts/email'

require 'god/reporter'
require 'god/server'
require 'god/timer'
require 'god/hub'

require 'god/metric'
require 'god/watch'

require 'god/trigger'
require 'god/event_handler'
require 'god/registry'
require 'god/process'

require 'god/sugar'

$:.unshift File.join(File.dirname(__FILE__), *%w[.. ext god])

LOG = God::Logger.new
LOG.datetime_format = "%Y-%m-%d %H:%M:%S "

GOD_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))

CONFIG_FILE = ''
def __CONFIG__
  CONFIG_FILE
end

begin
  Syslog.open('god')
rescue RuntimeError
  Syslog.reopen('god')
end

def with_stdout_captured
  old_stdout = $stdout
  out = StringIO.new
  $stdout = out
  begin
    yield
  ensure
    $stdout = old_stdout
  end
  out.string
end

God::EventHandler.load

module Kernel
  alias_method :abort_orig, :abort
  
  def abort(text = nil)
    $run = false
    LOG.log(nil, :error, text) if text
    text ? abort_orig(text) : exit(1)
  end
  
  alias_method :exit_orig, :exit
  
  def exit(code = 0)
    $run = false
    exit_orig(code)
  end
end

class Module
  def safe_attr_accessor(*args)
    args.each do |arg|
      define_method((arg.to_s + "=").intern) do |other|
        if !self.running && self.inited
          abort "God.#{arg} must be set before any Tasks are defined"
        end
        
        if self.running && self.inited
          LOG.log(nil, :warn, "God.#{arg} can't be set while god is running")
          return
        end
        
        instance_variable_set(('@' + arg.to_s).intern, other)
      end
      
      define_method(arg) do
        instance_variable_get(('@' + arg.to_s).intern)
      end
    end
  end
end

module God
  VERSION = '0.5.0'
  
  LOG_BUFFER_SIZE_DEFAULT = 1000
  PID_FILE_DIRECTORY_DEFAULT = '/var/run/god'
  DRB_PORT_DEFAULT = 17165
  DRB_ALLOW_DEFAULT = ['127.0.0.1']
  
  class << self
    # user configurable
    safe_attr_accessor :host,
                       :port,
                       :allow,
                       :log_buffer_size,
                       :pid_file_directory
    
    # internal
    attr_accessor :inited,
                  :running,
                  :pending_watches,
                  :pending_watch_states,
                  :server,
                  :watches,
                  :groups,
                  :contacts,
                  :contact_groups
  end
  
  # deprecated
  def self.init
    yield self if block_given?
  end
  <commit_msg>initialize safe class variables<commit_after>$:.unshift File.dirname(__FILE__)     # For use/testing when no gem is installed

# core
require 'stringio'
require 'logger'

# stdlib
require 'syslog'

# internal requires
require 'god/errors'
require 'god/logger'
require 'god/system/process'
require 'god/dependency_graph'
require 'god/timeline'
require 'god/configurable'

require 'god/task'

require 'god/behavior'
require 'god/behaviors/clean_pid_file'
require 'god/behaviors/notify_when_flapping'

require 'god/condition'
require 'god/conditions/process_running'
require 'god/conditions/process_exits'
require 'god/conditions/tries'
require 'god/conditions/memory_usage'
require 'god/conditions/cpu_usage'
require 'god/conditions/always'
require 'god/conditions/lambda'
require 'god/conditions/degrading_lambda'
require 'god/conditions/flapping'
require 'god/conditions/http_response_code'

require 'god/contact'
require 'god/contacts/email'

require 'god/reporter'
require 'god/server'
require 'god/timer'
require 'god/hub'

require 'god/metric'
require 'god/watch'

require 'god/trigger'
require 'god/event_handler'
require 'god/registry'
require 'god/process'

require 'god/sugar'

$:.unshift File.join(File.dirname(__FILE__), *%w[.. ext god])

LOG = God::Logger.new
LOG.datetime_format = "%Y-%m-%d %H:%M:%S "

GOD_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))

CONFIG_FILE = ''
def __CONFIG__
  CONFIG_FILE
end

begin
  Syslog.open('god')
rescue RuntimeError
  Syslog.reopen('god')
end

def with_stdout_captured
  old_stdout = $stdout
  out = StringIO.new
  $stdout = out
  begin
    yield
  ensure
    $stdout = old_stdout
  end
  out.string
end

God::EventHandler.load

module Kernel
  alias_method :abort_orig, :abort
  
  def abort(text = nil)
    $run = false
    LOG.log(nil, :error, text) if text
    text ? abort_orig(text) : exit(1)
  end
  
  alias_method :exit_orig, :exit
  
  def exit(code = 0)
    $run = false
    exit_orig(code)
  end
end

class Module
  def safe_attr_accessor(*args)
    args.each do |arg|
      # instance_variable_set(('@' + arg.to_s).intern, 'foo')
      
      define_method((arg.to_s + "=").intern) do |other|
        if !self.running && self.inited
          abort "God.#{arg} must be set before any Tasks are defined"
        end
        
        if self.running && self.inited
          LOG.log(nil, :warn, "God.#{arg} can't be set while god is running")
          return
        end
        
        instance_variable_set(('@' + arg.to_s).intern, other)
      end
      
      define_method(arg) do
        instance_variable_get(('@' + arg.to_s).intern)
      end
    end
  end
end

module God
  VERSION = '0.5.0'
  
  LOG_BUFFER_SIZE_DEFAULT = 1000
  PID_FILE_DIRECTORY_DEFAULT = '/var/run/god'
  DRB_PORT_DEFAULT = 17165
  DRB_ALLOW_DEFAULT = ['127.0.0.1']
  
  class << self
    # user configurable
    safe_attr_accessor :host,
                       :port,
                       :allow,
                       :log_buffer_size,
                       :pid_file_directory
    
    # internal
    attr_accessor :inited,
                  :running,
                  :pending_watches,
                  :pending_watch_states,
                  :server,
                  :watches,
                  :groups,
                  :contacts,
                  :contact_groups
  end
  
  self.host = nil
  self.allow = nil
  self.log_buffer_size = nil
  self.pid_file_directory = nil
  
  # deprecated
  def self.init
    yield self if block_given?
  end
  
{'fraction_non_alphanumeric': 0.10913335278669391, 'fraction_numerical': 0.005836008170411439, 'mean_word_length': 2.6835034927458357, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3244974', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2271, 'n_words': 516}