Sha256: 9bd62dc95879d2e152a1a14efc9936055a62664ab7834e50578b8d0ee998726a

Contents?: true

Size: 1.2 KB

Versions: 19

Compression:

Stored size: 1.2 KB

Contents

module Relaton
  module Index
    #
    # File storage module contains methods to read and write files
    #
    module FileStorage
      #
      # Return file creation time
      #
      # @param [String] file file path
      #
      # @return [Time, nil] file creation time or nil if file does not exist
      #
      def ctime(file)
        File.exist?(file) && File.ctime(file)
      end

      #
      # Read file
      #
      # @param [String] file file path
      #
      # @return [String, nil] file content or nil if file does not exist
      #
      def read(file)
        return unless File.exist?(file)

        File.read file, encoding: "UTF-8"
      end

      #
      # Write file
      #
      # @param [String] file file path
      # @param [String] data content to write
      #
      # @return [void]
      #
      def write(file, data)
        dir = File.dirname file
        FileUtils.mkdir_p dir
        File.write file, data, encoding: "UTF-8"
      end

      #
      # Remove file
      #
      # @param [String] file file path
      #
      # @return [void]
      #
      def remove(file)
        return unless File.exist? file

        File.delete file
      end

      extend self
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
relaton-index-0.2.16 lib/relaton/index/file_storage.rb
relaton-index-0.2.15 lib/relaton/index/file_storage.rb
relaton-index-0.2.14 lib/relaton/index/file_storage.rb
relaton-index-0.2.13 lib/relaton/index/file_storage.rb
relaton-index-0.2.12 lib/relaton/index/file_storage.rb
relaton-index-0.2.11 lib/relaton/index/file_storage.rb
relaton-index-0.2.10 lib/relaton/index/file_storage.rb
relaton-index-0.2.9 lib/relaton/index/file_storage.rb
relaton-index-0.2.8 lib/relaton/index/file_storage.rb
relaton-index-0.2.7 lib/relaton/index/file_storage.rb
relaton-index-0.2.6 lib/relaton/index/file_storage.rb
relaton-index-0.2.5 lib/relaton/index/file_storage.rb
relaton-index-0.2.4 lib/relaton/index/file_storage.rb
relaton-index-0.2.3 lib/relaton/index/file_storage.rb
relaton-index-0.2.2 lib/relaton/index/file_storage.rb
relaton-index-0.2.1 lib/relaton/index/file_storage.rb
relaton-index-0.2.0 lib/relaton/index/file_storage.rb
relaton-index-0.1.9 lib/relaton/index/file_storage.rb
relaton-index-0.1.8 lib/relaton/index/file_storage.rb