class RemoteFiles::MemoryStore

Public Class Methods

clear!() click to toggle source
# File lib/remote_files/memory_store.rb, line 14
def self.clear!
  RemoteFiles::CONFIGURATIONS.values.each do |config|
    next unless config.configured?
    config.stores.each do |store|
      store.clear! if store.is_a?(RemoteFiles::MemoryStore)
    end
  end
end

Public Instance Methods

clear!() click to toggle source
# File lib/remote_files/memory_store.rb, line 10
def clear!
  data.clear
end
copy_to_store!(file, target_store) click to toggle source
# File lib/remote_files/memory_store.rb, line 28
def copy_to_store!(file, target_store)
  target_store.data[file.identifier] = data[file.identifier]
end
data() click to toggle source
# File lib/remote_files/memory_store.rb, line 6
def data
  @data ||= {}
end
delete!(identifier) click to toggle source
# File lib/remote_files/memory_store.rb, line 59
def delete!(identifier)
  raise NotFoundError, "#{identifier} not found in #{self.identifier} store" unless data.has_key?(identifier)
  data.delete(identifier)
end
directory_name() click to toggle source
# File lib/remote_files/memory_store.rb, line 55
def directory_name
  self.identifier.to_s
end
files(prefix = '') click to toggle source
# File lib/remote_files/memory_store.rb, line 43
def files(prefix = '')
  @data.reject do |identifier|
    !identifier.start_with? prefix
  end.map do |identifier, data|
    File.new(identifier,
             :content_type => data[:content_type],
             :last_update_ts => data[:last_update_ts],
             :stored_in => [self]
    )
  end
end
retrieve!(identifier) click to toggle source
# File lib/remote_files/memory_store.rb, line 32
def retrieve!(identifier)
  raise NotFoundError, "#{identifier} not found in #{self.identifier} store" unless data.has_key?(identifier)

  File.new(identifier,
    :content      => data[identifier][:content],
    :content_type => data[identifier][:content_type],
    :last_update_ts => data[identifier][:last_update_ts],
    :stored_in    => [self]
  )
end
store!(file) click to toggle source
# File lib/remote_files/memory_store.rb, line 23
def store!(file)
  content = file.content.respond_to?(:read) ? file.content.read : file.content
  data[file.identifier] = { :content => content, :content_type => file.content_type, :last_update_ts => file.last_update_ts}
end
url(identifier) click to toggle source
# File lib/remote_files/memory_store.rb, line 64
def url(identifier)
  "memory://#{self.identifier}/#{identifier}"
end
url_matcher() click to toggle source
# File lib/remote_files/memory_store.rb, line 68
def url_matcher
  @url_matcher ||= /memory:\/\/#{identifier}\/(.*)/
end