Sha256: 4218b32c4bcdeb2362790bae69143a99de2043d299bce349c016c72c3b3a7313
Contents?: true
Size: 1014 Bytes
Versions: 187
Compression:
Stored size: 1014 Bytes
Contents
require 'pathname' module Generator module Files def self.read(filename) File.read(filename) if File.exist?(filename) end class Readable attr_reader :filename, :repository_root def initialize(filename:, repository_root: nil) @filename = filename @repository_root = repository_root end def to_s Files.read(filename) end def abbreviated_commit_hash GitCommand.abbreviated_commit_hash(git_path, relative_filename) end private def relative_filename Pathname.new(filename).relative_path_from(Pathname.new(repository_root)).to_s end def git_path File.join(repository_root, '.git') end end class Writable < Readable def save(content) write(content) unless content == to_s content end private def write(content) File.open(filename, 'w') do |file| file.write content end end end end end
Version data entries
187 entries across 187 versions & 1 rubygems