sj_ignore 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bdfbff1b6214d0d84e372c5b4c995abc65c31f15
4
+ data.tar.gz: 945b2a72bf68be2edde2ca5e4dcbb750c3a4063b
5
+ SHA512:
6
+ metadata.gz: 310236b2f6a7a27f8b3e6b75ed4f5700cad94692f40e4e14548fc155d6641091cc3594bfc4bf4b66e63bff122dfdf1d6ab140794480fcb1b9b635ad513f379e8
7
+ data.tar.gz: ccdd8a8c32b8670d7eb977cc8ab548d88f1c9e740559e19608cbab32e41b363c6d310174fe0c6c61da54be334a7a4e415e8c430c84389118577b3684428f5f15
data/.gitignore ADDED
@@ -0,0 +1,74 @@
1
+ ################################################################################
2
+ # Ruby.gitignore
3
+ ################################################################################
4
+
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /test/tmp/
13
+ /test/version_tmp/
14
+ /tmp/
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+
21
+ ## Documentation cache and generated files:
22
+ /.yardoc/
23
+ /_yardoc/
24
+ /doc/
25
+ /rdoc/
26
+
27
+ ## Environment normalisation:
28
+ /.bundle/
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ # Gemfile.lock
34
+ # .ruby-version
35
+ # .ruby-gemset
36
+
37
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
+ .rvmrc
39
+
40
+ ################################################################################
41
+ # Vim.gitignore
42
+ ################################################################################
43
+
44
+ [._]*.s[a-w][a-z]
45
+ [._]s[a-w][a-z]
46
+ *.un~
47
+ Session.vim
48
+ .netrwhist
49
+ *~
50
+
51
+ ################################################################################
52
+ # OSX.gitignore
53
+ ################################################################################
54
+
55
+ .DS_Store
56
+ .AppleDouble
57
+ .LSOverride
58
+
59
+ # Icon must end with two \r
60
+ Icon
61
+
62
+ # Thumbnails
63
+ ._*
64
+
65
+ # Files that might appear on external disk
66
+ .Spotlight-V100
67
+ .Trashes
68
+
69
+ # Directories potentially created on remote AFP share
70
+ .AppleDB
71
+ .AppleDesktop
72
+ Network Trash Folder
73
+ Temporary Items
74
+ .apdisk
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sj_ignore.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 sjdev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # sj-ignore
2
+
3
+ This small utility makes generating a .gitignore file for a new project as
4
+ painless as possible when dealing with multiple platforms or languages that you
5
+ require .gitignore info for.
6
+
7
+ ## Example
8
+
9
+ sj-ignore ruby vim osx > .gitignore
10
+
11
+ ## TODO
12
+
13
+ Pull `github/gitignore` repository so there is a local copy on the machine in
14
+ order to speed up setup time and to avert the issue with github api rate
15
+ limiting.
16
+
17
+ Give option to define your own github repository of .gitignore files.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/sj_ignore ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sj_ignore'
4
+
5
+ # Define basic command line options
6
+ help = false
7
+ list = false
8
+ api = false
9
+ langs = []
10
+
11
+ # Return a directory with the project libraries.
12
+ def gem_libdir
13
+ t = ["#{File.dirname(File.expand_path($0))}/../lib/#{Meta::NAME}",
14
+ "#{Gem.dir}/gems/#{Meta::NAME}-#{Meta::VERSION}/lib/#{Meta::NAME}"]
15
+ t.each {|i| return i if File.readable?(i) }
16
+ raise "both paths are invalid: #{t}"
17
+ end
18
+
19
+ # Sort command line options, this is really stupid logic right now but it does
20
+ # exactly what I need it to
21
+ ARGV.each do |arg|
22
+ case arg
23
+ when '-h', '--help'
24
+ help = true
25
+ when '-l', '--list'
26
+ list = true
27
+ when '-a', '--api'
28
+ api = true
29
+ else
30
+ langs << arg
31
+ end
32
+ end
33
+
34
+ if help
35
+ print "Usage: ignore [--help] [--sync] [--list] [LANGUAGES]\n"
36
+ print " --sync: Updates list of available .gitignore files\n"
37
+ print " --list: Lists available\n"
38
+
39
+ exit
40
+ end
41
+
42
+ if not list and not api and langs.length == 0
43
+ STDERR.puts "No options passed into program"
44
+
45
+ exit
46
+ end
47
+
48
+ builder = SjIgnore::Builder.new api
49
+
50
+ if list
51
+ builder.list
52
+ end
53
+
54
+ if langs
55
+ print builder.download_files langs
56
+ end
data/lib/meta.rb ADDED
@@ -0,0 +1,6 @@
1
+ module SjIgnore
2
+ module Meta
3
+ NAME = 'sj_ignore'
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
data/lib/sj-ignore.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'github_api'
2
+ require 'open-uri'
3
+
4
+ module SJIgnore
5
+ class Builder
6
+ def initialize(list, langs)
7
+ contents = gh_load
8
+
9
+ # Print out a list of all available .gitignore files
10
+ if list
11
+ contents.each do |path, ref|
12
+ p path
13
+ end
14
+ end
15
+
16
+ # Begin fetching each .gitignore file requested
17
+ if langs
18
+ ignores = []
19
+
20
+ # Fetch each file
21
+ langs.each do |name|
22
+ # Check if the requested language/platform is available in the list of
23
+ # known .gitignore files
24
+ if contents.include? name.downcase
25
+ ref = contents[name]
26
+
27
+ # Download the file
28
+ open(ref.download_url, 'rb') do |file|
29
+ content = file.read
30
+
31
+ # Append the separator header before adding it to the downloaded list
32
+ content = header(ref.path.split('/').last) + content
33
+
34
+ ignores << content
35
+ end
36
+ else
37
+ STDERR.puts "Cannot find a .gitignore file for: #{name}"
38
+ end
39
+ end
40
+
41
+ # Join all .gitignore files together and print them to console
42
+ print ignores.join "\n"
43
+ end
44
+ end
45
+
46
+ def gh_load
47
+ # Create an interface with github's repo of gitignore files and pull a list of
48
+ # all of them
49
+ github = Github.new
50
+ contents_top = github.repos.contents.get user: 'github', repo: 'gitignore', path: '/'
51
+ contents_global = github.repos.contents.get user: 'github', repo: 'gitignore', path: '/Global'
52
+ contents = {}
53
+
54
+ # Filter out all non-gitignore files and add them to a lookup map
55
+ content_filter = Proc.new do |ref|
56
+ if ref.path.include? '.gitignore'
57
+ # Remove any possible path components and grab only the platform or
58
+ # language part of the file name, which will be used later
59
+ name = ref.path.split('/').last.split('.').first.downcase
60
+
61
+ contents[name] = ref
62
+ end
63
+ end
64
+
65
+ # Combine the two different directories of .gitignore files
66
+ contents_top.each(&content_filter)
67
+ contents_global.each(&content_filter)
68
+
69
+ contents
70
+ end
71
+
72
+ # This just generates a custom header used to separate the different
73
+ # .gitignore files once they are merged
74
+ def header(lang)
75
+ head = "#" * 80 + "\n"
76
+ head += "# #{lang}" + "\n"
77
+ head += "#" * 80 + "\n"
78
+ head += "\n"
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module SjIgnore
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sj_ignore.rb ADDED
@@ -0,0 +1,131 @@
1
+ require 'github_api'
2
+ require 'open-uri'
3
+ require 'pathname'
4
+
5
+ require_relative 'utils'
6
+
7
+ module SjIgnore
8
+ class Builder
9
+ def initialize(use_api)
10
+ if use_api
11
+ @contents = gh_load_remote
12
+ else
13
+ @contents = gh_load_local
14
+ end
15
+ end
16
+
17
+ def download_files(langs)
18
+ # Begin fetching each .gitignore file requested
19
+ ignores = []
20
+
21
+ # Fetch each file
22
+ langs.each do |name|
23
+ # Check if the requested language/platform is available in the list of
24
+ # known .gitignore files
25
+ if @contents.include? name.downcase
26
+ ref = @contents[name]
27
+
28
+ # Download the file
29
+ open(ref.file_path, 'rb') do |file|
30
+ content = file.read
31
+
32
+ # Append the separator header before adding it to the downloaded list
33
+ content = header(ref.name) + content
34
+
35
+ ignores << content
36
+ end
37
+ else
38
+ STDERR.puts "Cannot find a .gitignore file for: #{name}"
39
+ end
40
+ end
41
+
42
+ # Join all .gitignore files together and print them to console
43
+ return ignores.join "\n"
44
+ end
45
+
46
+ def list
47
+ # Print out a list of all available .gitignore files
48
+ @contents.each do |path, ref|
49
+ p path
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def gh_load_local
56
+ git_repo = 'https://github.com/github/gitignore.git'
57
+ lib_dir = Pathname.new SjIgnore::Utils.gem_libdir
58
+ gitignore_dir = lib_dir + 'gitignore/'
59
+
60
+ if gitignore_dir.directory?
61
+ `cd \"#{gitignore_dir}\"
62
+ git pull`
63
+ else
64
+ `cd \"#{lib_dir}\"
65
+ git clone \"#{git_repo}\"`
66
+ end
67
+
68
+ local_files = Dir[gitignore_dir + "*.gitignore"]
69
+ global_files = Dir[gitignore_dir + "Global/*.gitignore"]
70
+
71
+ contents = {}
72
+
73
+ content_filter = Proc.new do |file|
74
+ if file.include? '.gitignore'
75
+ name = file.split('/').last.split('.').first.downcase
76
+ contents[name] = IgnoreFile.new(file.split('/').last, file)
77
+ end
78
+ end
79
+
80
+ local_files.each(&content_filter)
81
+ global_files.each(&content_filter)
82
+
83
+ contents
84
+ end
85
+
86
+ def gh_load_remote
87
+ # Create an interface with github's repo of gitignore files and pull a list of
88
+ # all of them
89
+ github = Github.new
90
+ contents_top = github.repos.contents.get user: 'github', repo: 'gitignore', path: '/'
91
+ contents_global = github.repos.contents.get user: 'github', repo: 'gitignore', path: '/Global'
92
+ contents = {}
93
+
94
+ # Filter out all non-gitignore files and add them to a lookup map
95
+ content_filter = Proc.new do |ref|
96
+ if ref.path.include? '.gitignore'
97
+ # Remove any possible path components and grab only the platform or
98
+ # language part of the file name, which will be used later
99
+ name = ref.path.split('/').last.split('.').first.downcase
100
+
101
+ contents[name] = IgnoreFile.new(ref.path.split('/').last, ref.download_url)
102
+ end
103
+ end
104
+
105
+ # Combine the two different directories of .gitignore files
106
+ contents_top.each(&content_filter)
107
+ contents_global.each(&content_filter)
108
+
109
+ contents
110
+ end
111
+
112
+ # This just generates a custom header used to separate the different
113
+ # .gitignore files once they are merged
114
+ def header(lang)
115
+ head = "#" * 80 + "\n"
116
+ head += "# #{lang}" + "\n"
117
+ head += "#" * 80 + "\n"
118
+ head += "\n"
119
+ end
120
+ end
121
+
122
+ class IgnoreFile
123
+ attr_accessor :name
124
+ attr_accessor :file_path
125
+
126
+ def initialize(name, file_path)
127
+ self.name = name
128
+ self.file_path = file_path
129
+ end
130
+ end
131
+ end
data/lib/utils.rb ADDED
@@ -0,0 +1,14 @@
1
+ require_relative 'meta'
2
+
3
+ module SjIgnore
4
+ module Utils
5
+ def self.gem_libdir
6
+ t = ["#{File.dirname(File.expand_path($0))}/../lib/#{Meta::NAME}",
7
+ "#{Gem.dir}/gems/#{Meta::NAME}-#{Meta::VERSION}/lib/#{Meta::NAME}"]
8
+ t.each {|i| return i if File.readable?(i) }
9
+ raise "both paths are invalid: #{t}"
10
+ end
11
+
12
+ # [...]
13
+ end
14
+ end
data/sj_ignore.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sj_ignore/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sj_ignore"
8
+ spec.version = SjIgnore::VERSION
9
+ spec.authors = ["sjdev"]
10
+ spec.email = ["shane@gianel.li"]
11
+ spec.summary = "Easy command line utility to create a multi-faceted .gitignore file"
12
+ spec.description = "sj-ignore uses github's gitignore repository to make it easy to list all the languages and platforms you would like included in your .gitignore file"
13
+ spec.homepage = "https://github.com/sjdev/sj-ignore"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['sj_ignore']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "github_api", "~> 0.12.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sj_ignore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - sjdev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: github_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: sj-ignore uses github's gitignore repository to make it easy to list
56
+ all the languages and platforms you would like included in your .gitignore file
57
+ email:
58
+ - shane@gianel.li
59
+ executables:
60
+ - sj_ignore
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/sj_ignore
70
+ - lib/meta.rb
71
+ - lib/sj-ignore.rb
72
+ - lib/sj_ignore.rb
73
+ - lib/sj_ignore/version.rb
74
+ - lib/utils.rb
75
+ - sj_ignore.gemspec
76
+ homepage: https://github.com/sjdev/sj-ignore
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.14
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Easy command line utility to create a multi-faceted .gitignore file
100
+ test_files: []