class IgnoreIt::List

Attributes

jsonResponse[R]
ownFiles[R]

Public Class Methods

new() click to toggle source
# File lib/ignore_it/list.rb, line 9
def initialize
  @url = "https://www.toptal.com/developers/gitignore/api/list?format=json"
  @response = Net::HTTP.get(URI(@url))
  @jsonResponse = JSON.parse(@response)
  load_own_files
end

Public Instance Methods

check_list(file) click to toggle source

Check the API List

# File lib/ignore_it/list.rb, line 51
def check_list(file)
  exists = false

  @jsonResponse.each do |extension|
    if file == extension.first
      exists = true
      break
    end
  end

  exists
end
check_own_files(file) click to toggle source

Check if the requested template exists

# File lib/ignore_it/list.rb, line 36
def check_own_files(file)
  if @ownFiles.include?(file)
    exists = true
  end
  exists
end
load_own_files() click to toggle source

Load own gitignore templates from the directory specified in the config file

# File lib/ignore_it/list.rb, line 19
def load_own_files
  @ownFiles = if $glob_settings["own_gitignore_path"] == "default"
    Dir.chdir(Dir.home) do
      Dir.entries(".ignore-it/gitignores/").select do |files|
        files unless files =~ /^..?$/ # some regex magic to remove "." and ".."
      end
    end
  else
    Dir.chdir($glob_settings["own_gitignore_path"]) do
      Dir.entries(".").select do |files|
        files unless files =~ /^..?$/
      end
    end
  end
end
show_list() click to toggle source

Print all gitignore templates fetched by the API

# File lib/ignore_it/list.rb, line 65
def show_list
  sortedArray = @jsonResponse.sort
  sortedArray.each do |entry|
    puts entry.first
  end
end
show_own_files() click to toggle source

Print all own gitignore templates

# File lib/ignore_it/list.rb, line 44
def show_own_files
  @ownFiles.each do |file|
    puts file
  end
end