Class: IgnoreIt::Creator
- Inherits:
-
Object
- Object
- IgnoreIt::Creator
- Defined in:
- lib/ignore_it/creator.rb
Instance Method Summary collapse
- #check_output_path(name) ⇒ Object
- #create_api_ignore(name) ⇒ Object
- #create_file(contents, name) ⇒ Object
- #create_own_ignore(name) ⇒ Object
-
#initialize ⇒ Creator
constructor
A new instance of Creator.
Constructor Details
Instance Method Details
#check_output_path(name) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/ignore_it/creator.rb', line 83 def check_output_path(name) if Dir.exist?(name) true else puts "The Output Path you provided does currently not exist, please create it manually before using --output".colorize(:red) end end |
#create_api_ignore(name) ⇒ Object
77 78 79 80 81 |
# File 'lib/ignore_it/creator.rb', line 77 def create_api_ignore(name) template = @jsonResponse[name] contents = template["contents"] create_file(contents, name) end |
#create_file(contents, name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ignore_it/creator.rb', line 14 def create_file(contents, name) puts "Creating .gitignore for " + name.colorize(:green) unless $glob_settings[:force] if File.exist?($glob_settings[:output]) sttySave = %x(stty -g).chomp # Store the state of the terminal overwrite = false append = false begin puts "File" + " .gitignore ".colorize(:yellow) + "already exists!" puts "Overwrite or append? [y => yes | a => append | n => no]?" while (line = Readline.readline('> ', true).downcase) if line == "y" overwrite = true break elsif line == "n" break elsif line == "a" append = true break elsif (line != "y") || (line != "n") || (line != "a") puts "Please provide a correct format (y or n)".colorize(:red) end end rescue Interrupt system('stty', sttySave) # Restore exit end if overwrite File.write($glob_settings[:output], contents) puts ".gitignore has been created!".colorize(:green) elsif append gitignoreContents = File.read($glob_settings[:output]) puts "Adding .gitignore content from " + name.colorize(:green) + " to existing .gitignore File" gitignoreContents += contents File.write($glob_settings[:output], gitignoreContents) else puts ".gitignore has NOT been created! Terminating process!".colorize(:red) end else File.write($glob_settings[:output], contents) puts ".gitignore has been created!".colorize(:green) end else File.write($glob_settings[:output], contents) puts ".gitignore has been created!".colorize(:green) end end |
#create_own_ignore(name) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ignore_it/creator.rb', line 63 def create_own_ignore(name) contents = "" if $glob_settings["own_gitignore_path"] == "default" Dir.chdir(Dir.home) do contents = File.read(".ignore-it/gitignores/" + name) end else Dir.chdir($glob_settings["own_gitignore_path"]) do contents = File.read(name) end end create_file(contents, name) end |