Class: KnifeSolo::Gitignore

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/knife-solo/gitignore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Gitignore

Returns a new instance of Gitignore.



7
8
9
# File 'lib/knife-solo/gitignore.rb', line 7

def initialize(dir)
  @ignore_file = File.join(dir, '.gitignore')
end

Instance Attribute Details

#ignore_fileObject

Returns the value of attribute ignore_file.



5
6
7
# File 'lib/knife-solo/gitignore.rb', line 5

def ignore_file
  @ignore_file
end

Instance Method Details

#add(*new_entries) ⇒ Object



19
20
21
22
23
24
# File 'lib/knife-solo/gitignore.rb', line 19

def add(*new_entries)
  new_entries = (entries + new_entries.flatten).uniq
  File.open(ignore_file, 'w') do |f|
    f.puts new_entries
  end
end

#eachObject



11
12
13
14
15
16
17
# File 'lib/knife-solo/gitignore.rb', line 11

def each
  if File.exist? ignore_file
    File.new(ignore_file).each do |line|
      yield line.chomp
    end
  end
end