Sha256: 72e123e18a630deeecc6e0b6e538ab39293adcaf21c4b7c46e03d58482c645cd

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'service.rb'

class LocalSecureFileStoreApp<Service
  
  class MyFile
    
  end
  
  class FileDoesNotExist<Exception
    
  end
  
  def initialize(cluster,options)
    super(cluster,options,:localSecureFileStore)
  end
  
  def load(name,key)
    key=hash(key)
    name=check(name)
    filename=name+"_"+key
    p=path(filename)
    raise FileDoesNotExist unless File.exists?(p)
    read(p)
  end
  
  def files(key)
    key=hash(key)
    filename="*_"+key
    Dir[path(filename)].map{|f|File.split(f)[1].gsub("_"+key,"")}
  end
  
  def store(name,key,content)
    key=hash(key)
    name=check(name)
    if name.length>0
      p=path(name+"_"+key)
      f=File.open(p,"w")
      f.print content
      f.close
      true
    else
      false
    end
  end
  
  private
  
  def hash(value)
    Crypt::hexdigest(value.to_s)
  end
  
  def path(file)
    File.join(getAppDataPath,file)
  end
  def read(file)
    f=File.open(file)
    c=f.read
    f.close
    c
  end
  def check(name)
    name.gsub(/[^a-zA-Z0-9_]/,"")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appswarm-0.0.1 apps/local_secure_file_store/local_secure_file_store.rb