Module: StatsLite::Helper

Defined in:
lib/stats_lite/helper.rb

Class Method Summary collapse

Class Method Details

._cache(options, command, proc) ⇒ Object



22
23
24
25
26
# 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) ⇒ Object



32
33
34
# File 'lib/stats_lite/helper.rb', line 32

def _prepare_command(command)
  _sys_command(command).gsub("\n", " ").strip
end

._sys_command(command) ⇒ Object



28
29
30
# File 'lib/stats_lite/helper.rb', line 28

def _sys_command(command)
  %x(#{command})
end

.command(command, options = {}) ⇒ Object



12
13
14
15
16
# 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) ⇒ Object



18
19
20
# 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) ⇒ Object



6
7
8
9
10
# File 'lib/stats_lite/helper.rb', line 6

def raw_command(command, options)
  proc = -> { _sys_command(command) }

  _cache(options, command, proc)
end