Sha256: c9dda78b1ac93f58cca11023932f7861c30340601b5f9213bfab569831f567c2

Contents?: true

Size: 837 Bytes

Versions: 14

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

module StatsLite
  module Helper
    class << self
      def raw_command(command, options)
        proc = -> { _sys_command(command) }

        _cache(options, command, proc)
      end

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

        _cache(options, command, proc)
      end

      def fetch(name, proc, expires_in: 0)
        _cache({ cache: true,  expires_in: expires_in }, name, proc)
      end

      def _cache(options, command, proc)
        expires_s = options[:expires_in] || 0

        options[:cache] ? Cache.fetch(command, proc, expires_s) : proc.call
      end

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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
stats_lite-0.8.1 lib/stats_lite/helper.rb
stats_lite-0.8.0 lib/stats_lite/helper.rb
stats_lite-0.7.2 lib/stats_lite/helper.rb
stats_lite-0.7.1 lib/stats_lite/helper.rb
stats_lite-0.7.0 lib/stats_lite/helper.rb
stats_lite-0.6.2 lib/stats_lite/helper.rb
stats_lite-0.6.1 lib/stats_lite/helper.rb
stats_lite-0.6.0 lib/stats_lite/helper.rb
stats_lite-0.5.4 lib/stats_lite/helper.rb
stats_lite-0.5.3 lib/stats_lite/helper.rb
stats_lite-0.5.2 lib/stats_lite/helper.rb
stats_lite-0.5.1 lib/stats_lite/helper.rb
stats_lite-0.5.0 lib/stats_lite/helper.rb
stats_lite-0.1.0 lib/stats_lite/helper.rb