Sha256: 7e94119b22fcd375a1edf90dd6c894335c6bb5d0e304fc9f771fc87ce964a244

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# coding: utf-8
module Splash
  module Backends
    class File
      include Splash::Config
      def initialize(store)
        @config = get_config[:backends][:stores][store]
        @path = @config[:path]
      end

      def list(pattern='*')
        pattern = suffix_trace(pattern)
        return Dir.glob("#{@path}/#{pattern}").map{|item| ::File.basename(item,".trace") }
      end

      def get(options)
        return ::File.readlines("#{@path}/#{suffix_trace(options[:key])}").join
      end

      def put(options)
        ::File.open("#{@path}/#{suffix_trace(options[:key])}", 'w') { |file|
          file.write options[:value]
        }
      end

      def del(options)
        ::File.unlink("#{@path}/#{suffix_trace(options[:key])}") if File.exist?("#{@path}/#{suffix_trace(options[:key])}")
      end

      def exist?(options)
        return ::File.exist?("#{@path}/#{suffix_trace(options[:key])}")
      end

      private
      def suffix_trace(astring)
        return "#{astring}.trace"
      end

    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prometheus-splash-0.3.0 lib/splash/backends/file.rb
prometheus-splash-0.2.0 lib/splash/backends/file.rb
prometheus-splash-0.1.1 lib/splash/backends/file.rb