Skip to content
This repository
tree: 7d98e0c779
Fetching contributors…

Cannot retrieve contributors at this time

file 167 lines (153 sloc) 4.205 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
require 'yaml'
require 'erb'
require 'pathname'

module Loops
  # @return [String]
  # a full path to the loops "lib" directory.
  LIB_ROOT = File.expand_path(File.dirname(__FILE__)) unless const_defined?('LIB_ROOT')
  # @return [String]
  # a full path to the loops binary file.
  BINARY = File.expand_path(File.join(LIB_ROOT, '../bin/loops')) unless const_defined?('BINARY')

  # Loops root directory.
  #
  # Usually it is initialized with framework's root dir (RAILS_ROOT or MERB_ROOT),
  # but you can specify another directory using command line arguments.
  #
  # Loops current directory will is set to this value (chdir).
  #
  # @return [Pathname, nil]
  # the loops root directory.
  #
  def self.root
    @@root
  end

  # Set loops root directory.
  #
  # This is internal method used to set the loops root directory.
  #
  # @param [String] path
  # the absolute path of the loops root directory.
  # @return [Pathname]
  # the loops root directory.
  #
  # @private
  #
  def self.root=(path)
    @@root = Pathname.new(path).realpath
  end

  # Get loops config file full path.
  #
  # @return [Pathname]
  # the loops config file path.
  #
  def self.config_file
    @@config_file ||= root.join('config/loops.yml')
  end

  # Set loops config file path.
  #
  # This is internal method used to set the loops config file path.
  #
  # @param [String] path
  # the absolute or relative to the loops root path of the loops
  # config file.
  # @return [Pathname]
  # the loops config file path.
  #
  # @private
  #
  def self.config_file=(config_file)
    @@config_file = root.join(config_file) if config_file
  end

  # Get directory containing loops classes.
  #
  # @return [Pathname]
  # the loops directory path.
  #
  def self.loops_root
    @@loops_root ||= root.join('app/loops')
  end

  # Set loops classes directory path.
  #
  # This is internal method used to set directory where loops classes
  # will be searched.
  #
  # @param [String] path
  # the absolute or relative to the loops classes directory.
  # @return [Pathname]
  # the loops classes directory path.
  #
  # @private
  #
  def self.loops_root=(loops_root)
    @@loops_root = root.join(loops_root) if loops_root
  end

  # Get the loops monitor process pid file path.
  #
  # @return [Pathname]
  # the loops monitor process pid file path.
  #
  def self.pid_file
    @@pid_file ||= root.join('loops.pid')
  end

  # Set the loops monitor pid file path.
  #
  # This is internal method used to set the loops monitor pid file path.
  #
  # @param [String] path
  # the absolute or relative to the loops monitor pid file.
  # @return [Pathname]
  # the loops monitor pid file path.
  #
  # @private
  #
  def self.pid_file=(pid_file)
    @@pid_file = root.join(pid_file) if pid_file
  end

  # Get the current loops logger.
  #
  # There are two contexts where different devices (usually) will be
  # configured for this logger instance:
  #
  # 1. In context of loops monitor logger device will be retrieved from
  # the global section of the loops config file, or STDOUT when it
  # was not configured.
  # 2. In context of loop proccess logger device will be configured
  # based on logger value of the particular loop section in the config
  # file.
  #
  # @example Put all Rails logging into the loop log file (add this to the environment.rb)
  # Rails.logger = Loops.logger
  #
  # @return [Loops::Logger]
  # the current loops logger instance.
  #
  def self.logger
    @@logger ||= ::Loops::Logger.new($stdout)
  end

  # Set the current loops logger.
  #
  def self.logger=(logger)
    @@logger = logger
  end

  # Get the current framework's default logger.
  #
  # @return [Logger]
  # the default logger for currently used framework.
  #
  def self.default_logger
    @@default_logger
  end

  # Set the current framework's default logger.
  #
  # @param [Logger] logger
  # the default logger for currently used framework.
  # @return [Logger]
  # the default logger for currently used framework.
  #
  # @private
  #
  def self.default_logger=(logger)
    @@default_logger = logger
  end
end

require File.join(Loops::LIB_ROOT, 'loops/autoload')
Something went wrong with that request. Please try again.