ignore 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.md +10 -0
- data/README.md +8 -0
- data/Rakefile +9 -0
- data/bin/gitignore +8 -0
- data/completion/_ignore +18 -0
- data/ignore.gemspec +22 -0
- data/lib/ignore.rb +18 -0
- data/lib/ignore/command.rb +116 -0
- data/lib/ignore/gitignore.rb +30 -0
- data/lib/ignore/storage.rb +122 -0
- data/test/helper.rb +7 -0
- data/test/test_gitignore.rb +24 -0
- data/test/test_storage.rb +22 -0
- metadata +119 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ignore (0.0.1)
|
5
|
+
httparty (~> 0.10.2)
|
6
|
+
rubyzip (~> 0.9.9)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
httparty (0.10.2)
|
12
|
+
multi_json (~> 1.0)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
multi_xml (0.5.3)
|
16
|
+
rake (0.9.6)
|
17
|
+
rubyzip (0.9.9)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
ignore!
|
24
|
+
rake (~> 0.9.2)
|
data/LICENSE.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
Copyright (c) 2013 Samir Ahmed
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
9
|
+
|
10
|
+
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/gitignore
ADDED
data/completion/_ignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#compdef ignore
|
2
|
+
|
3
|
+
local state line lang
|
4
|
+
|
5
|
+
_arguments -C '1: :->lang'
|
6
|
+
|
7
|
+
case $state in
|
8
|
+
lang)
|
9
|
+
#local -a cmds
|
10
|
+
#cmds=(
|
11
|
+
#'update: update your gitignores'
|
12
|
+
#'clean: clear local cache'
|
13
|
+
#'help:help text'
|
14
|
+
#)
|
15
|
+
#_describe -t commands 'boom command' cmds
|
16
|
+
_values 'lists' $(ls ~/.ignores | tr '[:upper:]' '[:lower:]' | grep '.gitignore' | sed 's/\.gitignore$//')
|
17
|
+
;;
|
18
|
+
esac
|
data/ignore.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ignore'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.executables << 'gitignore'
|
5
|
+
s.date = '2013-03-06'
|
6
|
+
s.summary = "Super easy way to manage gitignores from github/gitignore"
|
7
|
+
s.description = "Super easy manage gitignores from Github.com/github or add your own custom one"
|
8
|
+
s.authors = ["Samir Ahmed"]
|
9
|
+
s.email = 'samirahmed2013@gmail.com'
|
10
|
+
s.homepage = 'http://github.com/samirahmed/ignore'
|
11
|
+
s.files = `git ls-files`.split($/)
|
12
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
14
|
+
|
15
|
+
# runtime dependencies
|
16
|
+
s.add_runtime_dependency("httparty","~> 0.10.2")
|
17
|
+
s.add_runtime_dependency("rubyzip", "~> 0.9.9")
|
18
|
+
|
19
|
+
# development dependencies
|
20
|
+
s.add_development_dependency("rake","~>0.9.2")
|
21
|
+
|
22
|
+
end
|
data/lib/ignore.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
require 'httparty'
|
8
|
+
require 'zip/zipfilesystem'
|
9
|
+
|
10
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
11
|
+
|
12
|
+
require 'ignore/command'
|
13
|
+
require 'ignore/storage'
|
14
|
+
require 'ignore/gitignore'
|
15
|
+
|
16
|
+
module Ignore
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Ignore
|
2
|
+
class Command
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def execute(*args)
|
6
|
+
first = args.shift
|
7
|
+
second = args.shift
|
8
|
+
delegate(first, second)
|
9
|
+
end
|
10
|
+
|
11
|
+
def delegate(first, second)
|
12
|
+
return help if first == 'help'
|
13
|
+
return list if first == 'list'
|
14
|
+
return clean if first == 'clean'
|
15
|
+
return update if first == 'update'
|
16
|
+
return saveas(second) if first == 'saveas' and second
|
17
|
+
return getfile(second,:show) if first == 'show' and second
|
18
|
+
return getfile(first,:append) if first and second.nil?
|
19
|
+
|
20
|
+
storage #fetch and print help
|
21
|
+
help
|
22
|
+
end
|
23
|
+
|
24
|
+
def list
|
25
|
+
list = storage.list
|
26
|
+
output( list.reduce(""){|res,line| res+= line.chomp('.gitignore')+"\n" })
|
27
|
+
end
|
28
|
+
|
29
|
+
def getfile(language, callback)
|
30
|
+
exact = storage.match(language)
|
31
|
+
|
32
|
+
return self.send(callback, exact.first) unless exact.empty?
|
33
|
+
|
34
|
+
loose = storage.match(language, false)
|
35
|
+
|
36
|
+
case
|
37
|
+
when loose.length < 1
|
38
|
+
output("No such gitignore #{language}")
|
39
|
+
|
40
|
+
when loose.length == 1
|
41
|
+
self.send( callback, loose.first )
|
42
|
+
|
43
|
+
when (loose.length > 1 and loose.length < 5)
|
44
|
+
output "Please specify: \n#{loose.reduce(""){|res,name| res+=name+"\n"}}"
|
45
|
+
|
46
|
+
when loose.length > 5
|
47
|
+
output "Please be more specific"
|
48
|
+
|
49
|
+
else
|
50
|
+
output("uh-oh? something went wrong")
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def show(name)
|
56
|
+
contents = storage.load(name)
|
57
|
+
output(contents)
|
58
|
+
end
|
59
|
+
|
60
|
+
def append(name)
|
61
|
+
contents = storage.load(name)
|
62
|
+
gitignore.append(contents,name)
|
63
|
+
end
|
64
|
+
|
65
|
+
def update
|
66
|
+
storage.update
|
67
|
+
end
|
68
|
+
|
69
|
+
def clean
|
70
|
+
storage.clear
|
71
|
+
end
|
72
|
+
|
73
|
+
def saveas( name )
|
74
|
+
return storage.write(name,gitignore.read) if gitignore.exists?
|
75
|
+
return output ("No .gitignore found in the #{gitignore.path}")
|
76
|
+
end
|
77
|
+
|
78
|
+
def help()
|
79
|
+
text= %{
|
80
|
+
ignore : help -------------------------------------------------------
|
81
|
+
|
82
|
+
ignore <language> add specified languages gitignore to working directory
|
83
|
+
ignore list list available gitignores
|
84
|
+
ignore show <language> print the language to STDOUT (use with '| less')
|
85
|
+
ignore update update from github.com/github/gitignore
|
86
|
+
ignore clean empty your local ~/.ignores folder
|
87
|
+
ignore help show help
|
88
|
+
|
89
|
+
see https://github.com/samirahmed/ignore for more documentation
|
90
|
+
}
|
91
|
+
output(text)
|
92
|
+
end
|
93
|
+
|
94
|
+
def storage
|
95
|
+
@storage ||= Storage.new
|
96
|
+
end
|
97
|
+
|
98
|
+
def gitignore
|
99
|
+
@gitignore ||= Gitignore.new
|
100
|
+
end
|
101
|
+
|
102
|
+
def input
|
103
|
+
$stdin
|
104
|
+
end
|
105
|
+
|
106
|
+
def outprint(s)
|
107
|
+
print(s)
|
108
|
+
end
|
109
|
+
|
110
|
+
def output(s)
|
111
|
+
puts(s)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Ignore
|
4
|
+
class Gitignore
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@path = File.join(Dir.pwd(),'.gitignore')
|
8
|
+
end
|
9
|
+
|
10
|
+
def append( content , lang = "" )
|
11
|
+
FileUtils.touch @path
|
12
|
+
data="#\n#AutoGenerated #{lang} Gitignore\n#\n"+content+"\n##\n"
|
13
|
+
File.open(@path, 'a'){|f| f.write(data) }
|
14
|
+
Command.output "Updated .gitignore"
|
15
|
+
end
|
16
|
+
|
17
|
+
def read
|
18
|
+
return File.open(@path,'r'){|f| f.read } if exists?
|
19
|
+
""
|
20
|
+
end
|
21
|
+
|
22
|
+
def exists?
|
23
|
+
File.exists?( @path )
|
24
|
+
end
|
25
|
+
|
26
|
+
def path
|
27
|
+
@path
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Ignore
|
2
|
+
class Storage
|
3
|
+
|
4
|
+
GITIGNORES_ZIP = "https://github.com/github/gitignore/archive/master.zip"
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@root ||= File.join(File.expand_path('~'),'.ignores')
|
8
|
+
@gitignores||= File.join(@root,'/*.gitignore')
|
9
|
+
fetch unless list
|
10
|
+
end
|
11
|
+
|
12
|
+
def root
|
13
|
+
@root
|
14
|
+
end
|
15
|
+
|
16
|
+
def match(filetype, exact = true )
|
17
|
+
fname = filetype.downcase
|
18
|
+
list.select{|names| not names.downcase.scan( ( exact ? /^#{fname}$/i : /#{fname}/i ) ).empty? }
|
19
|
+
end
|
20
|
+
|
21
|
+
def load(filetype)
|
22
|
+
File.open( path_to(filetype) ,'r'){ |f|f.read }
|
23
|
+
end
|
24
|
+
|
25
|
+
def path_to(filename)
|
26
|
+
filepath = filename.chomp(".gitignore")
|
27
|
+
File.join(@root, filepath+".gitignore")
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
fetch
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear
|
35
|
+
nuke_directory!
|
36
|
+
end
|
37
|
+
|
38
|
+
def exists?(filename)
|
39
|
+
File.exists?( path_to(name) )
|
40
|
+
end
|
41
|
+
|
42
|
+
def write(filename, contents)
|
43
|
+
if exists?( filename )
|
44
|
+
outprint "Selected ignore #{name} already exists? overwrite it? [Ny]: "
|
45
|
+
return unless input.gets.strip.downcase.split("").first == "y"
|
46
|
+
end
|
47
|
+
write!( filename, contents )
|
48
|
+
end
|
49
|
+
|
50
|
+
def list
|
51
|
+
@list ||= if Dir.glob(@gitignores).length > 1
|
52
|
+
Dir.glob(@gitignores).map{|file| file.split('/').last.gsub(/\.gitignore/,'') }
|
53
|
+
else
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def update!
|
61
|
+
nuke_directory!
|
62
|
+
fetch
|
63
|
+
end
|
64
|
+
|
65
|
+
def write!( filename, contents )
|
66
|
+
File.open( path_to(filename) ,'w' ){|f| f.write(contents) }
|
67
|
+
end
|
68
|
+
|
69
|
+
def nuke_directory!
|
70
|
+
outprint "Delete all files in #{@root} ? [Ny]: "
|
71
|
+
if input.gets.strip.downcase.split('').first == 'y'
|
72
|
+
FileUtils.rm_rf @root
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def input
|
77
|
+
Command.input
|
78
|
+
end
|
79
|
+
|
80
|
+
def outprint(s)
|
81
|
+
Command.outprint(s)
|
82
|
+
end
|
83
|
+
|
84
|
+
def output(s)
|
85
|
+
Command.output(s)
|
86
|
+
end
|
87
|
+
|
88
|
+
def fetch
|
89
|
+
FileUtils.mkdir @root if not Dir.exists? @root
|
90
|
+
begin
|
91
|
+
output "Downloading gitignores from github.com/github/gitignore"
|
92
|
+
download = HTTParty.get(GITIGNORES_ZIP).body
|
93
|
+
rescue Exception => ex
|
94
|
+
output "ERROR: Unable fetch gitignores from #{GITIGNORES_ZIP}"
|
95
|
+
end
|
96
|
+
zipfile = File.join(@root,'ignores.zip')
|
97
|
+
|
98
|
+
File.open(zipfile,'w'){|f| f.write download}
|
99
|
+
unzip zipfile
|
100
|
+
FileUtils.rm zipfile
|
101
|
+
|
102
|
+
output "#{list.length} gitignores total"
|
103
|
+
list
|
104
|
+
end
|
105
|
+
|
106
|
+
def unzip(source , path=@root )
|
107
|
+
Zip::ZipFile.open(source) do |zipfile|
|
108
|
+
zipfile.each do |entry|
|
109
|
+
if entry.name.end_with?(".gitignore")
|
110
|
+
fpath = File.join(path, File.basename(entry.name) )
|
111
|
+
|
112
|
+
File.delete(fpath) if File.exists?(fpath) # Overwrite
|
113
|
+
zipfile.extract(entry, fpath)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
rescue Zip::ZipDestinationFileExistsError => ex
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class TestGitIgnore< Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@gitignore = Ignore::Gitignore.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
FileUtils.rm @gitignore.path
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_append
|
14
|
+
@gitignore.append("hello\nworld\n","mylang")
|
15
|
+
assert(@gitignore.read.split("\n").length == 7)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_exists
|
19
|
+
assert( !@gitignore.exists?)
|
20
|
+
FileUtils.touch @gitignore.path
|
21
|
+
assert( @gitignore.exists? )
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class TestStorage < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@storage = Ignore::Storage.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_load
|
10
|
+
assert(@storage.load("ruby").split("\n").length == 18)
|
11
|
+
assert(@storage.load("yii").split("\n").length == 3)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_match
|
15
|
+
assert(@storage.match("text",true).length == 0)
|
16
|
+
assert(@storage.match("text",false).length == 3)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_update
|
20
|
+
assert(@storage.update.length > 100 )
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ignore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Samir Ahmed
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rubyzip
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.9
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.9
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.2
|
62
|
+
description: Super easy manage gitignores from Github.com/github or add your own custom
|
63
|
+
one
|
64
|
+
email: samirahmed2013@gmail.com
|
65
|
+
executables:
|
66
|
+
- gitignore
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- LICENSE.md
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- bin/gitignore
|
77
|
+
- completion/_ignore
|
78
|
+
- ignore.gemspec
|
79
|
+
- lib/ignore.rb
|
80
|
+
- lib/ignore/command.rb
|
81
|
+
- lib/ignore/gitignore.rb
|
82
|
+
- lib/ignore/storage.rb
|
83
|
+
- test/helper.rb
|
84
|
+
- test/test_gitignore.rb
|
85
|
+
- test/test_storage.rb
|
86
|
+
homepage: http://github.com/samirahmed/ignore
|
87
|
+
licenses: []
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: -1933714610239891608
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -1933714610239891608
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.24
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Super easy way to manage gitignores from github/gitignore
|
116
|
+
test_files:
|
117
|
+
- test/helper.rb
|
118
|
+
- test/test_gitignore.rb
|
119
|
+
- test/test_storage.rb
|