filestore 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,19 +11,31 @@ require 'log.rb'
11
11
  require 'uuidtools'
12
12
  require 'fileutils'
13
13
  require 'yaml'
14
+ require 'singleton'
14
15
 
15
16
  module FileStore
16
17
  #
17
- # Class implementing a multitenant file store
18
+ # Singleton class implementing a multitenant file store
18
19
  #
19
20
  class MultiTenantFileStore
20
- attr_reader :stores
21
+ # Make this class a singleton class
22
+ include Singleton
23
+ # Accessors
24
+ attr_reader :stores, :rootPath
21
25
  #
22
26
  # Initializes a new instance of MultiTenantFileStore
23
- # @rootPath The path where all file stores are located
24
27
  #
25
- def initialize(rootPath = '.')
26
- raise FileStoreException, "Given root path isn't accessable" if not File.directory?(rootPath)
28
+ def initialize()
29
+ @rootPath = Dir.getwd
30
+ @stores = {}
31
+ end
32
+ #
33
+ # Sets the root path of the multitenant store. As FileStore::MultiTenantFileStore
34
+ # is a singleton class, this method must be used before any other
35
+ # @param rootPath The path to be used
36
+ #
37
+ def set_root_path(rootPath)
38
+ raise FileStoreException, "Root path #{rootPath} doesn't exist" if not File.exists?(rootPath)
27
39
 
28
40
  @rootPath = rootPath
29
41
  @stores = MultiTenantFileStore.recover(rootPath)
@@ -11,16 +11,16 @@ require 'fileutils'
11
11
 
12
12
  include FileStore
13
13
 
14
- basePath = "/Users/thomas/Documents/DEV/ruby/FileStoreGEM/test/multi_store_test"
15
- testFile = "/Users/thomas/Documents/DEV/ruby/FileStoreGEM/test/testfile.txt"
14
+ basePath = "/Users/thomas/Documents/DEV/ruby/FileStoreRepo/test/multi_store_test"
15
+ testFile = "/Users/thomas/Documents/DEV/ruby/FileStoreRepo/test/testfile.txt"
16
16
 
17
17
  begin
18
- mtfs = MultiTenantFileStore.new basePath
19
- tenant = mtfs.create_tenant_store
20
- mtfs.add_to_tenant tenant, testFile, { :hugo => "boss" }
18
+ MultiTenantFileStore.instance.set_root_path basePath
19
+ tenant = MultiTenantFileStore.instance.create_tenant_store
20
+ MultiTenantFileStore.instance.add_to_tenant tenant, testFile, { :hugo => "boss" }
21
21
 
22
- puts mtfs.stores
23
- mtfs.shutdown
22
+ puts MultiTenantFileStore.instance.stores
23
+ MultiTenantFileStore.instance.shutdown
24
24
  rescue Exception => e
25
25
  puts e
26
26
  puts e.backtrace
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filestore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: