Sha256: d1c1fef3dfcffffc1ac1706a73d7c19c0e8f6ebf4ee61554fb45b704a615a43a
Contents?: true
Size: 1.08 KB
Versions: 83
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true require 'eac_ruby_utils/core_ext' require 'fileutils' module EacFs class StorageTree CONTENT_FILE_NAME = '__content__' attr_reader :path def initialize(*path_parts) raise ArgumentError, "\"#{path_parts}\" is empty" if path_parts.empty? @path = ::File.expand_path(::File.join(*path_parts.map(&:to_s))) end def clear return unless stored? ::File.unlink(content_path) end def read return nil unless stored? ::File.read(content_path) end def read_or_store write(yield) unless stored? read end def write(value) assert_directory_on_path ::File.write(content_path, value) value end def child(*child_path_parts) self.class.new(path, *child_path_parts) end def stored? ::File.exist?(content_path) end def content_path ::File.join(path, CONTENT_FILE_NAME) end private def assert_directory_on_path raise "#{path} is a file" if ::File.file?(path) ::FileUtils.mkdir_p(path) end end end
Version data entries
83 entries across 83 versions & 3 rubygems