Class: Jackfs::FileStore
- Inherits:
-
Object
- Object
- Jackfs::FileStore
- Defined in:
- lib/jackfs/file_store.rb
Constant Summary collapse
- CONFIG_FILE =
File.join('config','filestore.yml')
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#app_env ⇒ Object
Returns the value of attribute app_env.
-
#app_root ⇒ Object
Returns the value of attribute app_root.
-
#file ⇒ Object
Returns the value of attribute file.
-
#guid ⇒ Object
Returns the value of attribute guid.
Instance Method Summary collapse
- #create_guid ⇒ Object
- #get(guid) ⇒ Object
-
#initialize(app_root, app_env) ⇒ FileStore
constructor
A new instance of FileStore.
- #load_adapter ⇒ Object
- #store(this_file) ⇒ Object
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
#adapter ⇒ Object
Returns the value of attribute adapter.
14 15 16 |
# File 'lib/jackfs/file_store.rb', line 14 def adapter @adapter end |
#app_env ⇒ Object
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_root ⇒ Object
Returns the value of attribute app_root.
14 15 16 |
# File 'lib/jackfs/file_store.rb', line 14 def app_root @app_root end |
#file ⇒ Object
Returns the value of attribute file.
14 15 16 |
# File 'lib/jackfs/file_store.rb', line 14 def file @file end |
#guid ⇒ Object
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_guid ⇒ Object
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_adapter ⇒ Object
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 |