Class: Jackfs::FileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/jackfs/file_store.rb

Constant Summary collapse

CONFIG_FILE =
File.join('config','filestore.yml')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_root, app_env) ⇒ FileStore

Returns a new instance of FileStore.



16
17
18
19
20
# File 'lib/jackfs/file_store.rb', line 16

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

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



14
15
16
# File 'lib/jackfs/file_store.rb', line 14

def adapter
  @adapter
end

#app_envObject

Returns the value of attribute app_env.



14
15
16
# File 'lib/jackfs/file_store.rb', line 14

def app_env
  @app_env
end

#app_rootObject

Returns the value of attribute app_root.



14
15
16
# File 'lib/jackfs/file_store.rb', line 14

def app_root
  @app_root
end

#fileObject

Returns the value of attribute file.



14
15
16
# File 'lib/jackfs/file_store.rb', line 14

def file
  @file
end

#guidObject

Returns the value of attribute guid.



14
15
16
# File 'lib/jackfs/file_store.rb', line 14

def guid
  @guid
end

Instance Method Details

#create_guidObject



34
35
36
# File 'lib/jackfs/file_store.rb', line 34

def create_guid
  UUIDTools::UUID.random_create.to_s
end

#get(guid) ⇒ Object



29
30
31
32
# File 'lib/jackfs/file_store.rb', line 29

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

#load_adapterObject



38
39
40
41
42
43
44
# File 'lib/jackfs/file_store.rb', line 38

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

#store(this_file) ⇒ Object



22
23
24
25
26
27
# File 'lib/jackfs/file_store.rb', line 22

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