Sha256: db452cfb0890d92de9e48fdac5635db7caee4f9a5f6bb04532830f01abaa8d83

Contents?: true

Size: 871 Bytes

Versions: 3

Compression:

Stored size: 871 Bytes

Contents

require 'pathname'
require 'mate/git'

module Mate
  class TmProperties
    def self.create(dir, options)
      new(Git.toplevel(dir) || dir, options).save
    end

    def initialize(dir, options)
      @dir = Pathname(dir).expand_path
      @file = @dir + '.tm_properties'
      @lines = @file.exist? ? @file.read.split("\n") : []
      @other_lines = @lines.reject{ |line| line =~ Ignores::GENERATED_R }
      @options = options
    end

    def save
      ignores = Ignores.new(@dir, @options)

      write(ignores.lines + @other_lines)
    end

    def cleanup
      if @other_lines.empty?
        @file.unlink if @file.exist?
      else
        write(@other_lines)
      end
    end

  private

    def write(lines)
      return if lines == @lines

      @file.open('w') do |f|
        f.puts lines
      end
    end
  end
end

require 'mate/tm_properties/ignores'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mate-3.2.0 lib/mate/tm_properties.rb
mate-3.1.0 lib/mate/tm_properties.rb
mate-3.0.0 lib/mate/tm_properties.rb