module Kernel

Public Instance Methods

ap(object, **options) click to toggle source

Global AwesomePrint method (which triggers the loading of AwesomePrint the first time it’s called)

# File lib/epitools/minimal.rb, line 256
def ap(object, **options)
  AwesomePrint
  Kernel.ap(object, options)
end
backtick(*cmd)
Alias for: run
backtick_with_stderr(*cmd)
Alias for: run_with_stderr
daemonize(chdir=nil, &on_sighup) click to toggle source

This method causes the current running process to become a daemon All further printing is relied to the error.log FIXME doesn’t belong into Butler::Bot, rather into botcontrol

# File lib/epitools/daemonize.rb, line 5
def daemonize(chdir=nil, &on_sighup)
  srand # Split rand streams between spawning and daemonized process
  safe_fork and exit # Fork and exit from the parent

  # Detach from the controlling terminal
  raise "Can't detach from controlling terminal" unless sess_id = Process.setsid

  # Prevent the possibility of acquiring a controlling terminal
  trap('SIGHUP', 'IGNORE')
  exit if safe_fork

  # In daemon mode, a SIGHUP means termination
  trap('SIGHUP', &on_sighup)

  # We can't get the originally controlling terminals stdout/stdin anymore
  STDIN.reopen("/dev/null")
  STDOUT.reopen("/dev/null", "a")
  STDERR.reopen(STDOUT)

  Dir.chdir(chdir) if chdir
  File.umask 0033 # FIXME ask somebody knowledgable about a sensible value

  sess_id
end
displayln(out=$stdout) click to toggle source

Print “self” with a linefeed at the end

# File lib/epitools/minimal.rb, line 249
def displayln(out=$stdout)
  out.puts self
end
run(*cmd) { |io| ... } click to toggle source

Executes a command and returns its output. (Like the backtick operator, but doesn’t require shell ecaping arguments.)

# File lib/epitools/minimal.rb, line 227
def run(*cmd)
  result = IO.popen(cmd) do |io|
    block_given? ? yield(io) : io.read
  end
  String === result && result.empty? ? nil : result
end
Also aliased as: backtick
run_with_stderr(*cmd) { |io| ... } click to toggle source

Same as Kernel#run, but includes stderr in the result.

# File lib/epitools/minimal.rb, line 238
def run_with_stderr(*cmd)
  result = IO.popen(cmd, err: [:child, :out]) do |io|
    block_given? ? yield(io) : io.read
  end
  String === result && result.empty? ? nil : result
end
Also aliased as: backtick_with_stderr
safe_fork(delay=5) click to toggle source

Try to fork if at all possible retrying every delay sec (5s default) if the maximum process limit for the system has been reached

# File lib/epitools/daemonize.rb, line 32
def safe_fork(delay=5)
  fork
rescue Errno::EWOULDBLOCK
  sleep(delay)
  retry
end

Protected Instance Methods

it() click to toggle source

Magic “its” Mapping


The pure-Ruby way:

User.find(:all).map{|x| x.contacts.map{|y| y.last_name.capitalize }}

With Symbol#to_proc:

User.find(:all).map{|x|x.contacts.map(&:last_name).map(&:capitalize)}

Magic “its” way:

User.find(:all).map &its.contacts.map(&its.last_name.capitalize)
# File lib/epitools/its.rb, line 19
def it()
  It.new
end
Also aliased as: its
its()
Alias for: it