Module: StatsLite::Helper
- Defined in:
- lib/stats_lite/helper.rb
Class Method Summary collapse
- ._cache(options, command, proc) ⇒ Object
- ._prepare_command(command) ⇒ Object
- ._sys_command(command) ⇒ Object
- .command(command, options = {}) ⇒ Object
- .fetch(name, proc, expires_in: 0) ⇒ Object
- .raw_command(command, options) ⇒ Object
Class Method Details
._cache(options, command, proc) ⇒ Object
22 23 24 25 26 |
# File 'lib/stats_lite/helper.rb', line 22 def _cache(, command, proc) expires_s = [:expires_in] || 0 [: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, = {}) proc = -> { _prepare_command(command) } _cache(, 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, ) proc = -> { _sys_command(command) } _cache(, command, proc) end |