Class: Gitignores::GitignoreBuilder
- Inherits:
-
Object
- Object
- Gitignores::GitignoreBuilder
- Defined in:
- lib/gitignores/builder.rb
Instance Attribute Summary collapse
-
#local_repository ⇒ Object
writeonly
Sets the attribute local_repository.
Instance Method Summary collapse
- #build(ignores, out) ⇒ Object
- #concatenate_files(files, out) ⇒ Object
- #find_gitignores_by_name(ignores) ⇒ Object
-
#initialize ⇒ GitignoreBuilder
constructor
A new instance of GitignoreBuilder.
Constructor Details
#initialize ⇒ GitignoreBuilder
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
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.(path) } end |