Sha256: 39747e40d8cf825b051a4d172064a79c339b361b846e24e408d44112d7481045

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'forgitter'

module Forgitter
  class Runner
    def initialize(options = Forgitter::DEFAULT_OPTIONS)
      @types = Forgitter.filter_types(options[:tags])
      @stdout = options[:stdout]
    end

    def run
      failcnt = 0
      output = ''
      @types.each do |type|
        ignore_file = get_ignore_file(type[:path])
        if ignore_file
          output += "# Information from #{type}\n"
          output += ignore_file
        else
          failcnt += 1
        end
      end
      exit(1) if failcnt == @types.length

      if @stdout
        puts output
      else
        File.open('.gitignore', 'w') do |file|
          file.write(output)
        end
      end
    end

    private

    # Given a filename on the gitignore repo, return a string with the contents of the file
    def get_ignore_file(filename)
      STDERR.puts "Using #{filename}"
      begin
        IO.read(File.join(DATA_PATH, filename))
      rescue Errno::ENOENT
        STDERR.puts "#{filename} does not exist!"
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forgitter-0.0.7 lib/forgitter/runner.rb