Class: Ignore::Storage
- Inherits:
-
Object
- Object
- Ignore::Storage
- Defined in:
- lib/ignore/storage.rb
Constant Summary collapse
- GITIGNORES_ZIP =
"https://github.com/github/gitignore/archive/master.zip"
Instance Method Summary collapse
- #clear ⇒ Object
- #exists?(filename) ⇒ Boolean
-
#initialize ⇒ Storage
constructor
A new instance of Storage.
- #list ⇒ Object
- #load(filetype) ⇒ Object
- #match(filetype, exact = true) ⇒ Object
- #path_to(filename) ⇒ Object
- #root ⇒ Object
- #update ⇒ Object
- #write(filename, contents) ⇒ Object
Constructor Details
#initialize ⇒ Storage
Returns a new instance of Storage.
6 7 8 9 10 |
# File 'lib/ignore/storage.rb', line 6 def initialize() @root ||= File.join(File.('~'),'.ignores') @gitignores||= File.join(@root,'/*.gitignore') fetch unless list end |
Instance Method Details
#clear ⇒ Object
34 35 36 |
# File 'lib/ignore/storage.rb', line 34 def clear nuke_directory! end |
#exists?(filename) ⇒ Boolean
38 39 40 |
# File 'lib/ignore/storage.rb', line 38 def exists?(filename) File.exists?( path_to(name) ) end |
#list ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ignore/storage.rb', line 50 def list @list ||= if Dir.glob(@gitignores).length > 1 Dir.glob(@gitignores).map{|file| file.split('/').last.gsub(/\.gitignore/,'') } else nil end end |
#load(filetype) ⇒ Object
21 22 23 |
# File 'lib/ignore/storage.rb', line 21 def load(filetype) File.open( path_to(filetype) ,'r'){ |f|f.read } end |
#match(filetype, exact = true) ⇒ Object
16 17 18 19 |
# File 'lib/ignore/storage.rb', line 16 def match(filetype, exact = true ) fname = filetype.downcase list.select{|names| not names.downcase.scan( ( exact ? /^#{fname}$/i : /#{fname}/i ) ).empty? } end |
#path_to(filename) ⇒ Object
25 26 27 28 |
# File 'lib/ignore/storage.rb', line 25 def path_to(filename) filepath = filename.chomp(".gitignore") File.join(@root, filepath+".gitignore") end |
#root ⇒ Object
12 13 14 |
# File 'lib/ignore/storage.rb', line 12 def root @root end |
#update ⇒ Object
30 31 32 |
# File 'lib/ignore/storage.rb', line 30 def update fetch end |
#write(filename, contents) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ignore/storage.rb', line 42 def write(filename, contents) if exists?( filename ) outprint "Selected ignore #{name} already exists? overwrite it? [Ny]: " return unless input.gets.strip.downcase.split("").first == "y" end write!( filename, contents ) end |