Class: Gitignores::GitignoreBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitignores/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitignoreBuilder

Returns a new instance of GitignoreBuilder.



8
9
10
# File 'lib/gitignores/builder.rb', line 8

def initialize
  @local_repository = ENV['HOME'] + '/.gitignores'
end

Instance Attribute Details

#local_repository=(value) ⇒ Object (writeonly)

Sets the attribute local_repository

Parameters:

  • value

    the value to set the attribute local_repository to.



6
7
8
# File 'lib/gitignores/builder.rb', line 6

def local_repository=(value)
  @local_repository = value
end

Instance Method Details

#build(ignores, out) ⇒ Object



12
13
14
# File 'lib/gitignores/builder.rb', line 12

def build(ignores, out)
  concatenate_files(find_gitignores_by_name(ignores), out)
end

#concatenate_files(files, out) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/gitignores/builder.rb', line 26

def concatenate_files(files, out)
  files.each { |f_name|
      basename = File.basename f_name, ".gitignore"
    out << "\n\# #{basename}\n\n"
    File.open(f_name) { |f_in|
      IO.copy_stream f_in, out
      out << "\n"
    }
  }
end

#find_gitignores_by_name(ignores) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/gitignores/builder.rb', line 16

def find_gitignores_by_name(ignores) 
  ignores.collect { |x| 
    path = File.exist?("#{@local_repository}/#{x}.gitignore") ? "#{@local_repository}/#{x}.gitignore" : "#{@local_repository}/Global/#{x}.gitignore"
    unless File.exist? path
      raise GitignoreNotFoundException.new(x), "File #{path} does not exist"
    end
    File.expand_path(path)
  }
end