Class: IgnoreIt::List
- Inherits:
-
Object
- Object
- IgnoreIt::List
- Defined in:
- lib/ignore_it/list.rb
Instance Attribute Summary collapse
-
#jsonResponse ⇒ Object
readonly
Returns the value of attribute jsonResponse.
-
#ownFiles ⇒ Object
readonly
Returns the value of attribute ownFiles.
Instance Method Summary collapse
-
#check_list(file) ⇒ Object
Check the API List.
-
#check_own_files(file) ⇒ Object
Check if the requested template exists.
-
#initialize ⇒ List
constructor
A new instance of List.
-
#load_own_files ⇒ Object
Load own gitignore templates from the directory specified in the config file.
-
#show_list ⇒ Object
Print all gitignore templates fetched by the API.
-
#show_own_files ⇒ Object
Print all own gitignore templates.
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
9 10 11 12 13 14 |
# 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 |
Instance Attribute Details
#jsonResponse ⇒ Object (readonly)
Returns the value of attribute jsonResponse.
16 17 18 |
# File 'lib/ignore_it/list.rb', line 16 def jsonResponse @jsonResponse end |
#ownFiles ⇒ Object (readonly)
Returns the value of attribute ownFiles.
16 17 18 |
# File 'lib/ignore_it/list.rb', line 16 def ownFiles @ownFiles end |
Instance Method Details
#check_list(file) ⇒ Object
Check the API List
51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
Check if the requested template exists
36 37 38 39 40 41 |
# 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 ⇒ Object
Load own gitignore templates from the directory specified in the config file
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 ⇒ Object
Print all gitignore templates fetched by the API
65 66 67 68 69 70 |
# 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 ⇒ Object
Print all own gitignore templates
44 45 46 47 48 |
# File 'lib/ignore_it/list.rb', line 44 def show_own_files @ownFiles.each do |file| puts file end end |