Class: Turning::FileStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/turning/file_storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ FileStorage

Returns a new instance of FileStorage.



3
4
5
# File 'lib/turning/file_storage.rb', line 3

def initialize(root_path)
  @root_path = root_path
end

Instance Method Details

#get(file_path) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/turning/file_storage.rb', line 14

def get(file_path)
  begin
    IO.read(resolve(file_path))
  rescue Errno::ENOENT
    nil
  end
end

#put(file_path, contents) ⇒ Object



7
8
9
10
11
12
# File 'lib/turning/file_storage.rb', line 7

def put(file_path, contents)
  FileUtils.mkdir_p(parent_directory(file_path))
  File.open(resolve(file_path), 'w') do |file|
    file.write(contents)
  end
end