class MiGA::MiGA

Generic class used to handle system-wide information and methods, and parent of all other MiGA::* classes.

Public Class Methods

CITATION() click to toggle source

Reference of MiGA

# File lib/miga/version.rb, line 58
def self.CITATION
  CITATION
end
DEBUG(*args) click to toggle source

Send debug message

# File lib/miga/common/base.rb, line 31
def DEBUG(*args)
  $stderr.puts(*args) if @@DEBUG
  $stderr.puts(
    caller.map { |v| v.gsub(/^/, '     ') }.join("\n")
  ) if @@DEBUG_TRACE
end
DEBUG_OFF() click to toggle source

Turn off debugging

# File lib/miga/common/base.rb, line 12
def DEBUG_OFF
  @@DEBUG = false
end
DEBUG_ON() click to toggle source

Turn on debugging

# File lib/miga/common/base.rb, line 6
def DEBUG_ON
  @@DEBUG = true
end
DEBUG_TRACE_OFF() click to toggle source

Turn off debug tracing (but not debugging)

# File lib/miga/common/base.rb, line 25
def DEBUG_TRACE_OFF
  @@DEBUG_TRACE = false
end
DEBUG_TRACE_ON() click to toggle source

Turn on debug tracing (and debugging)

# File lib/miga/common/base.rb, line 18
def DEBUG_TRACE_ON
  @@DEBUG_TRACE = true
  DEBUG_ON()
end
FULL_VERSION() click to toggle source

Complete version as string

# File lib/miga/version.rb, line 40
def self.FULL_VERSION
  VERSION.join('.')
end
LONG_VERSION() click to toggle source

Complete version with nickname and date as string

# File lib/miga/version.rb, line 46
def self.LONG_VERSION
  "MiGA #{VERSION.join('.')} - #{VERSION_NAME} - #{VERSION_DATE}"
end
VERSION() click to toggle source

Major.minor version as Float

# File lib/miga/version.rb, line 34
def self.VERSION
  VERSION[0]
end
VERSION_DATE() click to toggle source

Date of the current gem release

# File lib/miga/version.rb, line 52
def self.VERSION_DATE
  VERSION_DATE
end
initialized?() click to toggle source

Has MiGA been initialized?

# File lib/miga/common.rb, line 24
def self.initialized?
  File.exist?(File.expand_path('.miga_rc', ENV['MIGA_HOME'])) and
    File.exist?(File.expand_path('.miga_daemon.json', ENV['MIGA_HOME']))
end

Public Instance Methods

advance(step, n = 0, total = nil, bin = true) click to toggle source

Reports the advance of a task at step (String), the n out of total. The advance is reported in powers of 1,024 if bin is true, or powers of 1,000 otherwise. The report goes to $stderr iff –verborse

# File lib/miga/common.rb, line 54
def advance(step, n = 0, total = nil, bin = true)
  adv = total.nil? ? (n == 0 ? '' : num_suffix(n, bin)) :
    ('%.1f%% (%s/%s)' % [100.0 * n / total,
                         num_suffix(n, bin), num_suffix(total, bin)])
  $stderr.print("[%s] %s %s    \r" % [Time.now, step, adv])
end
like_io?(obj) click to toggle source
# File lib/miga/common.rb, line 77
def like_io?(obj)
  obj.is_a?(IO) || obj.is_a?(StringIO)
end
num_suffix(n, bin = false) click to toggle source

Return formatted number n with the appropriate units as powers of 1,000 (if bin if false) or 1,024 (otherwise)

# File lib/miga/common.rb, line 64
def num_suffix(n, bin = false)
  p = ''
  { T: 4, G: 3, M: 2, K: 1 }.each do |k, x|
    v = (bin ? 1024 : 1e3)**x
    if n > v
      n = '%.1f' % (n / v)
      p = k
      break
    end
  end
  "#{n}#{p}"
end
result_files_exist?(base, ext) click to toggle source

Check if the result files exist with base name (String) followed by the ext values (Array of String).

# File lib/miga/common.rb, line 32
def result_files_exist?(base, ext)
  ext = [ext] unless ext.is_a? Array
  ext.all? do |f|
    File.exist?(base + f) or File.exist?("#{base}#{f}.gz")
  end
end
say(*par) click to toggle source

Print par ensuring new line at the end. Date/time-stamp each line. If the first parameter is IO or StringIO the output is sent there, otherwise it's sent to +$stderr+

# File lib/miga/common.rb, line 44
def say(*par)
  io = like_io?(par.first) ? par.shift : $stderr
  io.puts(*par.map { |i| "[#{Time.now}] #{i}" })
end