Class: Ignorify::Utils
- Inherits:
-
Object
- Object
- Ignorify::Utils
- Defined in:
- lib/ignorify/util.rb
Overview
Utility class. Generates file list and downloads gitignores. Also contians strategies depending on cURL.
Constant Summary collapse
- REPOSITORY_URL =
"https://github.com/github/gitignore"
- REPOSITORY_RAW_URL =
"https://raw.githubusercontent.com/github/gitignore/master/"
- FILENAME =
".gitignore"
Class Method Summary collapse
-
.check_existing_gitignore ⇒ Object
Check for existing .gitignore.
-
.create_file(name) ⇒ Object
Grabs the latest gitignore.
-
.file_list ⇒ Object
Get file list from Github repository.
-
.search(term) ⇒ Object
Search for a term in the gitignore list.
Class Method Details
.check_existing_gitignore ⇒ Object
Check for existing .gitignore.
Returns:
Boolean
107 108 109 110 111 112 113 |
# File 'lib/ignorify/util.rb', line 107 def self.check_existing_gitignore if File.exist?(FILENAME) && FILENAME.size > 0 return true else return false end end |
.create_file(name) ⇒ Object
Grabs the latest gitignore. Saves .gitignore. We check to see if cURL is installed. If installed, fetch using cURL
As a fallback, scrape the file. Arguments:
name: (String)
Returns:
Boolean
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ignorify/util.rb', line 45 def self.create_file(name) request_url = REPOSITORY_RAW_URL + name + FILENAME system("curl -V > /dev/null") if $? == 0 return fetch_using_curl(request_url) else return crawl_and_fetch(request_url) end end |
.file_list ⇒ Object
Get file list from Github repository. Crawls the github repository. Generates a hash with lowercase values mapped to crawled values.
Returns:
Hash
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ignorify/util.rb', line 21 def self.file_list file_list = {} page = Nokogiri::HTML(open(REPOSITORY_URL)) page.css('td.content span.css-truncate a').each do |tr| if tr.content.end_with?(FILENAME) trimmed_name = tr.content.chomp(FILENAME) file_list[trimmed_name.downcase] = trimmed_name end end return file_list end |
.search(term) ⇒ Object
Search for a term in the gitignore list.
Arguments:
term: (String)
Returns:
Array
98 99 100 |
# File 'lib/ignorify/util.rb', line 98 def self.search(term) return file_list.keys.grep(/#{term}/) end |