Sha256: c98497a4baa215a92fb0e4afa4dabdb904128a73a4a1d69b0c137061950b6116

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

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

1 entries across 1 versions & 1 rubygems

Version Path
prometheus-splash-0.1.0 lib/splash/backends/file.rb