module StatsLite::Helper

Public Class Methods

_cache(options, command, proc) click to toggle source
# File lib/stats_lite/helper.rb, line 22
def _cache(options, command, proc)
  expires_s = options[:expires_in] || 0

  options[:cache] ? Cache.fetch(command, proc, expires_s) : proc.call
end
_prepare_command(command) click to toggle source
# File lib/stats_lite/helper.rb, line 32
def _prepare_command(command)
  _sys_command(command).gsub("\n", " ").strip
end
_sys_command(command) click to toggle source
# File lib/stats_lite/helper.rb, line 28
def _sys_command(command)
  %x(#{command})
end
command(command, options = {}) click to toggle source
# File lib/stats_lite/helper.rb, line 12
def command(command, options = {})
  proc = -> { _prepare_command(command) }

  _cache(options, command, proc)
end
fetch(name, proc, expires_in: 0) click to toggle source
# File lib/stats_lite/helper.rb, line 18
def fetch(name, proc, expires_in: 0)
  _cache({ cache: true,  expires_in: expires_in }, name, proc)
end
raw_command(command, options) click to toggle source
# File lib/stats_lite/helper.rb, line 6
def raw_command(command, options)
  proc = -> { _sys_command(command) }

  _cache(options, command, proc)
end