Class: Jackfs::FileAdapter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_root, app_env) ⇒ FileAdapter

Returns a new instance of FileAdapter.



5
6
7
8
9
10
11
12
13
# File 'lib/jackfs/adapters/file_adapter.rb', line 5

def initialize(app_root, app_env)
  @app_root = app_root
  @app_env = app_env
  begin
    @location = YAML.load_file(File.join(@app_root, Jackfs::FileStore::CONFIG_FILE))[@app_env.to_s]["location"]
  rescue
    raise InvalidFileStore
  end
end

Instance Attribute Details

#app_envObject

Returns the value of attribute app_env.



3
4
5
# File 'lib/jackfs/adapters/file_adapter.rb', line 3

def app_env
  @app_env
end

#app_rootObject

Returns the value of attribute app_root.



3
4
5
# File 'lib/jackfs/adapters/file_adapter.rb', line 3

def app_root
  @app_root
end

#locationObject

Returns the value of attribute location.



3
4
5
# File 'lib/jackfs/adapters/file_adapter.rb', line 3

def location
  @location
end

Instance Method Details

#get(name) ⇒ Object



20
21
22
# File 'lib/jackfs/adapters/file_adapter.rb', line 20

def get(name)
  File.open(File.join(app_root, @location, name), 'r')
end

#store(this_file, name) ⇒ Object



15
16
17
18
# File 'lib/jackfs/adapters/file_adapter.rb', line 15

def store(this_file, name)
  File.open(File.join(@app_root, @location, name), 'w') { |file| file.write this_file.read }
  name
end