Sha256: 581e28bf5cfec6f89f938d463c35d959027a221c3894763dcd96c582aaec1cc2

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

begin
  require 'uuidtools'
rescue LoadError
  puts 'gem uuidtools is required'
end

require File.dirname(__FILE__) + '/adapters/file_adapter'
require File.dirname(__FILE__) + '/adapters/db_adapter'

module Jackfs
  class FileStore
    CONFIG_FILE = File.join('config','filestore.yml')

    attr_accessor :file, :guid, :adapter, :app_root, :app_env

    def initialize(app_root, app_env)
      @app_root = app_root
      @app_env = app_env
      @adapter = load_adapter
    end

    def store(this_file)
      @file = this_file
      @guid = create_guid
      # call adapter passing the file and guid as file identifier
      @adapter.store(this_file, @guid)
    end

    def get(guid)
      # Need call adapter passing the guid and returning the file
      @adapter.get(guid)
    end

    def create_guid
      UUIDTools::UUID.random_create.to_s
    end

    def load_adapter
      adapter_type = YAML.load_file(File.join(@app_root,CONFIG_FILE))[@app_env.to_s]["adapter"].to_sym
      case adapter_type
        when :db then Jackfs::DbAdapter.new(@app_root, @app_env)
        else Jackfs::FileAdapter.new(@app_root, @app_env)
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jackfs-0.1.1 lib/jackfs/file_store.rb
jackfs-0.1.0 lib/jackfs/file_store.rb