ignorify 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e419bd3eecf5e8066451ac9fe2f6ad65eaf54879
4
- data.tar.gz: 9d7a6aaa75ccf48da42f946b84c7970a3b0a9888
3
+ metadata.gz: 19f1bb2a3a8d0e2ac4f26e6f92c2edc537c09b68
4
+ data.tar.gz: 05ecbfd9098740c0c3a303dcdb26d08e409b5962
5
5
  SHA512:
6
- metadata.gz: c00bb8edc378b3768cd9b851995967961baa8f96c699ce50d2c21ef7c09b069097d023e5dce39eeb5daa0798850e99c4c8eaee09948262588ad2ef79230fe5be
7
- data.tar.gz: c80f1f064d5a7bc09bd01749e3778a092d6f0a0dcc23392522c72c8ff0ece1d5412689f24dee3c81dcdb954b081b64e166e9df878982d117bb67b6e6f7a9d88f
6
+ metadata.gz: cf33051a374cd5cff851441a81f019454b31022508ca127b7f6f2d1c89c28547b691e3713b07f2bdf68fb07bcc3642a011a617669d0c65fdc6cb3fb0d28975e0
7
+ data.tar.gz: c84e67ba13d8eb255fa0cf111d6156f38cf17f9bb082a392c5da7b1072d532af11657e2bd7f0dd5af1df9ab54e551f4c1ff3afe89f83b3c95000f3c00f9a84c8
data/.gitignore CHANGED
File without changes
data/.travis.yml CHANGED
@@ -12,7 +12,11 @@ rvm:
12
12
  # Install dependencies
13
13
  install: bundle install
14
14
 
15
- #Test
15
+ # Test command
16
16
  script: rspec
17
17
 
18
+ # Turn off notifications
19
+ notifications:
20
+ email: false
21
+
18
22
 
data/README.md CHANGED
@@ -5,6 +5,26 @@
5
5
 
6
6
  A simple command line tool to pull and save .gitignore files!
7
7
 
8
+ ## TODO
9
+
10
+ - Peek into .gitignore files before downloading them (v1.2.0)
11
+
12
+ ## Changelog
13
+
14
+ ### v1.1.1 (12-02-2015)
15
+
16
+ - Add search command to filter files.
17
+ - Check for existing gitignore and prompt to overwrite.
18
+
19
+ ### v1.0.1 (15-01-2015)
20
+
21
+ - Fix some issues with the Ruby gem install.
22
+ - Changed main executable path to relative.
23
+
24
+ ### v1.0.0 (15-01-2015)
25
+
26
+ - First release with all core functionality
27
+
8
28
  ## Installation
9
29
 
10
30
  Install using gem
@@ -39,6 +59,7 @@ But, if cURL is not installed, it manually grabs by crawling.
39
59
  - `list`: Shows a list of all available files.
40
60
  - `help`: Shows available commands.
41
61
  - `version`: Returns the current version number.
62
+ - `search <filename>`: Searches for a gitignore and returns results.
42
63
  - `create <filename>`: Places a .gitignore file in the current directory.
43
64
 
44
65
  ### Usage
@@ -52,6 +73,8 @@ Fetching gitignore...
52
73
  ######################################################################## 100.0%
53
74
  .gitignore created
54
75
  ```
76
+ If there is an already existing .gitignore in the directory, you may choose to overwrite it.
77
+ If you dont want to, the command will exit without changing any files.
55
78
 
56
79
  If the file searched for is not available, an error message will be shown.
57
80
 
data/bin/ignorify CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require_relative '../lib/ignorify'
4
3
 
5
4
  Ignorify::Ignorify.start(ARGV)
data/ignorify.gemspec CHANGED
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "codeclimate-test-reporter", "~>0.4", ">= 0.4.5"
27
- spec.add_development_dependency "rspec", "~>3.1", ">= 3.1.0"
25
+ spec.add_development_dependency "rake", "~> 10.0", ">=10.4.2"
26
+ spec.add_development_dependency "codeclimate-test-reporter", "~>0.4", ">= 0.4.6"
27
+ spec.add_development_dependency "rspec", "~>3.1", ">= 3.2.0"
28
28
 
29
29
  spec.add_dependency "thor", "~>0.19", ">= 0.19.1"
30
- spec.add_dependency "nokogiri", "~>1.6", ">= 1.6.5"
30
+ spec.add_dependency "nokogiri", "~>1.6.6.2", ">= 1.6.6"
31
31
  spec.add_dependency "colorize", "~>0.7", ">= 0.7.5"
32
32
  end
@@ -0,0 +1,95 @@
1
+ require_relative "version"
2
+ require "thor"
3
+ require_relative "util"
4
+ require "colorize"
5
+
6
+ module Ignorify
7
+ class Ignorify < Thor
8
+
9
+ # Lists all available ignorify commands.
10
+ #
11
+ # Example:
12
+ # >> ignorify list
13
+ #
14
+ # Prints to stdout.
15
+ desc "list", "List available .gitignore files."
16
+ def list
17
+ $stdout.puts Utils.file_list.keys
18
+ end
19
+
20
+ # Prints the current ignorify version.
21
+ #
22
+ # Example:
23
+ # >> ignorify version
24
+ #
25
+ # Prints to stdout.
26
+ desc "version", "Get current ignorify version."
27
+ def version
28
+ $stdout.puts VERSION
29
+ end
30
+
31
+ # Downloads the specified .gitignore file.
32
+ # Saves it to the working directory.
33
+ #
34
+ # Example:
35
+ # >> ignorify create java
36
+ #
37
+ # Arguments:
38
+ # name: (String)
39
+ #
40
+ # Prints to stdout.
41
+ desc "create <FILENAME>", "Downloads required .gitignore file."
42
+ def create(name)
43
+ file_list = Utils.file_list
44
+
45
+ # Create a file
46
+ create_file = Proc.new do |file_list|
47
+ if Utils.create_file(file_list[name])
48
+ $stdout.puts ".gitignore created".green
49
+ else
50
+ $stdout.puts "Error creating .gitignore".red
51
+ end
52
+ end
53
+
54
+ if file_list.has_key?(name)
55
+ if Utils.check_existing_gitignore
56
+ response = ask("There is an already existing .gitignore file.\nDo you wish to overwrite?".red,
57
+ :limited_to => ["y", "n"])
58
+
59
+ case response
60
+ when "y"
61
+ create_file.call(file_list)
62
+ when "n"
63
+ $stdout.puts "Exiting.."
64
+ exit 1
65
+ end
66
+ else
67
+ create_file.call(file_list)
68
+ end
69
+ else
70
+ $stdout.puts "File was not found in the git repository".red
71
+ end
72
+ end
73
+
74
+ # Search for a filename <FILENAME>.
75
+ # Returns any matches in the gitignore list.
76
+ #
77
+ # Example:
78
+ # >> ignorify search ruby
79
+ #
80
+ # Arguments:
81
+ # term: (String)
82
+ #
83
+ # Prints to stdout.
84
+ desc "search <FILENAME>", "Search for a gitignore and filter results."
85
+ def search(term)
86
+ results = Utils.search(term)
87
+ if results.length > 0
88
+ $stdout.puts "Available gitignore files:".green
89
+ $stdout.puts "#{results.join(", ")}"
90
+ else
91
+ $stdout.puts "No gitignore for #{term} was found".red
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,118 @@
1
+ require "nokogiri"
2
+ require "open-uri"
3
+
4
+ module Ignorify
5
+
6
+ # Utility class.
7
+ # Generates file list and downloads gitignores.
8
+ # Also contians strategies depending on cURL.
9
+ class Utils
10
+
11
+ REPOSITORY_URL = "https://github.com/github/gitignore"
12
+ REPOSITORY_RAW_URL = "https://raw.githubusercontent.com/github/gitignore/master/"
13
+ FILENAME = ".gitignore"
14
+
15
+ # Get file list from Github repository.
16
+ # Crawls the github repository.
17
+ # Generates a hash with lowercase values mapped to crawled values.
18
+ #
19
+ # Returns:
20
+ # Hash
21
+ def self.file_list
22
+ file_list = {}
23
+
24
+ page = Nokogiri::HTML(open(REPOSITORY_URL))
25
+ page.css('td.content span.css-truncate a').each do |tr|
26
+ if tr.content.end_with?(FILENAME)
27
+ trimmed_name = tr.content.chomp(FILENAME)
28
+ file_list[trimmed_name.downcase] = trimmed_name
29
+ end
30
+ end
31
+ return file_list
32
+ end
33
+
34
+ # Grabs the latest gitignore.
35
+ # Saves .gitignore.
36
+ # We check to see if cURL is installed.
37
+ # If installed, fetch using cURL
38
+ #
39
+ # As a fallback, scrape the file.
40
+ # Arguments:
41
+ # name: (String)
42
+ #
43
+ # Returns:
44
+ # Boolean
45
+ def self.create_file(name)
46
+ request_url = REPOSITORY_RAW_URL + name + FILENAME
47
+ system("curl -V > /dev/null")
48
+
49
+ if $? == 0
50
+ return fetch_using_curl(request_url)
51
+ else
52
+ return crawl_and_fetch(request_url)
53
+ end
54
+ end
55
+
56
+ # Strategy to fetch using cURL.
57
+ #
58
+ # Arguments:
59
+ # request_url: (String)
60
+ #
61
+ # Returns:
62
+ # Boolean
63
+ def self.fetch_using_curl(request_url)
64
+ system("echo Fetching gitignore...")
65
+ file_created = system("curl --progress -o #{FILENAME} #{request_url}")
66
+ return file_created
67
+ end
68
+
69
+ # Strategy to fetch by crawling the page.
70
+ #
71
+ # Arguments:
72
+ # request_url: (String)
73
+ #
74
+ # Returns:
75
+ # Boolean
76
+ def self.crawl_and_fetch(request_url)
77
+ page = Nokogiri::HTML(open(request_url))
78
+ page_content = file.css('body p').text
79
+
80
+ File.open(FILENAME, "w") do |file|
81
+ file.write(page_content)
82
+ end
83
+
84
+ if File.exist?(FILENAME) && FILENAME.size > 0
85
+ return true
86
+ else
87
+ return false
88
+ end
89
+ end
90
+
91
+ # Search for a term in the gitignore list.
92
+ #
93
+ # Arguments:
94
+ # term: (String)
95
+ #
96
+ # Returns:
97
+ # Array
98
+ def self.search(term)
99
+ return file_list.keys.grep(/#{term}/)
100
+ end
101
+
102
+ # Check for existing .gitignore.
103
+ #
104
+ # Returns:
105
+ # Boolean
106
+ #
107
+ def self.check_existing_gitignore
108
+ if File.exist?(FILENAME) && FILENAME.size > 0
109
+ return true
110
+ else
111
+ return false
112
+ end
113
+ end
114
+
115
+ private_class_method :fetch_using_curl
116
+ private_class_method :crawl_and_fetch
117
+ end
118
+ end
@@ -1,3 +1,3 @@
1
1
  module Ignorify
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.1"
3
3
  end
data/lib/ignorify.rb CHANGED
@@ -1,55 +1 @@
1
- require "ignorify/version"
2
- require "thor"
3
- require_relative "util"
4
- require "colorize"
5
-
6
- module Ignorify
7
- class Ignorify < Thor
8
-
9
- # Lists all available ignorify commands.
10
- #
11
- # Example:
12
- # >> ignorify list
13
- #
14
- # Prints to stdout.
15
- desc "list", "List available .gitignore files."
16
- def list
17
- $stdout.puts Utils.file_list.keys
18
- end
19
-
20
- # Prints the current ignorify version.
21
- #
22
- # Example:
23
- # >> ignorify version
24
- #
25
- # Prints to stdout.
26
- desc "version", "Get current ignorify version."
27
- def version
28
- $stdout.puts VERSION
29
- end
30
-
31
- # Downloads the specified .gitignore file.
32
- # Saves it to the working directory.
33
- #
34
- # Example:
35
- # >> ignorify create java
36
- #
37
- # Arguments:
38
- # name: (String)
39
- #
40
- # Prints to stdout.
41
- desc "create <FILENAME>", "Downloads required .gitignore file"
42
- def create(name)
43
- file_list = Utils.file_list
44
- if file_list.has_key? name
45
- if Utils.create_file(file_list[name])
46
- $stdout.puts ".gitignore created".green
47
- else
48
- $stdout.puts "Error creating .gitignore".red
49
- end
50
- else
51
- $stdout.puts "File was not found in the git repository".red
52
- end
53
- end
54
- end
55
- end
1
+ require 'ignorify/core'
@@ -4,6 +4,10 @@ require_relative '../lib/ignorify/version'
4
4
  require "colorize"
5
5
 
6
6
  describe Ignorify::Ignorify do
7
+ before(:all) do
8
+ FileUtils.rm(".gitignore")
9
+ end
10
+
7
11
  describe "#list" do
8
12
  it "should list all available .gitignore files" do
9
13
  file_list = Ignorify::Utils.file_list.keys.join("\n") + "\n"
@@ -34,6 +38,19 @@ describe Ignorify::Ignorify do
34
38
  end
35
39
  end
36
40
 
41
+ describe "#search" do
42
+ it "should search the list for a term" do
43
+ args = %w[search ruby]
44
+ search_task = capture(:stdout) { Ignorify::Ignorify.start(args) }
45
+ expect(search_task).to eq("Available gitignore files:".green + "\n" + "ruby\n")
46
+ end
47
+ it "should show an error if a file cannot be found" do
48
+ args = %w[search xxctgft]
49
+ search_task = capture(:stdout) { Ignorify::Ignorify.start(args) }
50
+ expect(search_task).to eq("No gitignore for xxctgft was found".red + "\n")
51
+ end
52
+ end
53
+
37
54
  # Teardown modified .gitignore
38
55
  after(:all) do
39
56
  FileUtils.cp('spec/original/gitignore', '.gitignore')
data/spec/util_spec.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/ignorify/util'
3
+ require "colorize"
4
+
5
+ describe Ignorify::Utils do
6
+ describe "#file_list" do
7
+ files = Ignorify::Utils.file_list
8
+ it "should return a Hash" do
9
+ expect(files).to be_an_instance_of(Hash)
10
+ end
11
+ it "should have a length greater than zero" do
12
+ expect(files.length).to be > 0
13
+ end
14
+ end
15
+
16
+ describe "#create_file" do
17
+ it "should return true when a valid file is passed" do
18
+ file_created = Ignorify::Utils.create_file("ruby")
19
+ expect(file_created).to be true
20
+ end
21
+ end
22
+
23
+ describe "#search" do
24
+ results = Ignorify::Utils.search("ruby")
25
+ it "should return results for a term" do
26
+ expect(results).to eq(["ruby"])
27
+ end
28
+ it "should return an Array" do
29
+ expect(results).to be_an_instance_of(Array)
30
+ end
31
+ it "should return an empty array for an invalid term" do
32
+ expect(Ignorify::Utils.search("xrbgt").length).to eq(0)
33
+ end
34
+ end
35
+
36
+ # Teardown modified .gitignore
37
+ after(:all) do
38
+ FileUtils.cp('spec/original/gitignore', '.gitignore')
39
+ end
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ignorify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - vivangkumar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 10.4.2
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
43
  version: '10.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.4.2
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: codeclimate-test-reporter
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -47,7 +53,7 @@ dependencies:
47
53
  version: '0.4'
48
54
  - - ">="
49
55
  - !ruby/object:Gem::Version
50
- version: 0.4.5
56
+ version: 0.4.6
51
57
  type: :development
52
58
  prerelease: false
53
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +63,7 @@ dependencies:
57
63
  version: '0.4'
58
64
  - - ">="
59
65
  - !ruby/object:Gem::Version
60
- version: 0.4.5
66
+ version: 0.4.6
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: rspec
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +73,7 @@ dependencies:
67
73
  version: '3.1'
68
74
  - - ">="
69
75
  - !ruby/object:Gem::Version
70
- version: 3.1.0
76
+ version: 3.2.0
71
77
  type: :development
72
78
  prerelease: false
73
79
  version_requirements: !ruby/object:Gem::Requirement
@@ -77,7 +83,7 @@ dependencies:
77
83
  version: '3.1'
78
84
  - - ">="
79
85
  - !ruby/object:Gem::Version
80
- version: 3.1.0
86
+ version: 3.2.0
81
87
  - !ruby/object:Gem::Dependency
82
88
  name: thor
83
89
  requirement: !ruby/object:Gem::Requirement
@@ -104,20 +110,20 @@ dependencies:
104
110
  requirements:
105
111
  - - "~>"
106
112
  - !ruby/object:Gem::Version
107
- version: '1.6'
113
+ version: 1.6.6.2
108
114
  - - ">="
109
115
  - !ruby/object:Gem::Version
110
- version: 1.6.5
116
+ version: 1.6.6
111
117
  type: :runtime
112
118
  prerelease: false
113
119
  version_requirements: !ruby/object:Gem::Requirement
114
120
  requirements:
115
121
  - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: '1.6'
123
+ version: 1.6.6.2
118
124
  - - ">="
119
125
  - !ruby/object:Gem::Version
120
- version: 1.6.5
126
+ version: 1.6.6
121
127
  - !ruby/object:Gem::Dependency
122
128
  name: colorize
123
129
  requirement: !ruby/object:Gem::Requirement
@@ -158,11 +164,13 @@ files:
158
164
  - bin/ignorify
159
165
  - ignorify.gemspec
160
166
  - lib/ignorify.rb
167
+ - lib/ignorify/core.rb
168
+ - lib/ignorify/util.rb
161
169
  - lib/ignorify/version.rb
162
- - lib/util.rb
163
170
  - spec/ignorify_spec.rb
164
171
  - spec/original/gitignore
165
172
  - spec/spec_helper.rb
173
+ - spec/util_spec.rb
166
174
  homepage: https://github.com/vivangkumar/ignorify
167
175
  licenses:
168
176
  - MIT
@@ -191,3 +199,4 @@ test_files:
191
199
  - spec/ignorify_spec.rb
192
200
  - spec/original/gitignore
193
201
  - spec/spec_helper.rb
202
+ - spec/util_spec.rb
data/lib/util.rb DELETED
@@ -1,67 +0,0 @@
1
- require "nokogiri"
2
- require "open-uri"
3
-
4
- module Ignorify
5
-
6
- # Utility class.
7
- # Generates file list and downloads gitignores.
8
- class Utils
9
-
10
- REPOSITORY_URL = "https://github.com/github/gitignore"
11
- REPOSITORY_RAW_URL = "https://raw.githubusercontent.com/github/gitignore/master/"
12
- FILENAME = ".gitignore";
13
-
14
- # Get file list from Github repository.
15
- # Crawls the github repository.
16
- # Generates a hash with lowercase values mapped to crawled values.
17
- #
18
- # Returns:
19
- # Hash
20
- def self.file_list
21
- file_list = {}
22
-
23
- page = Nokogiri::HTML(open(REPOSITORY_URL))
24
- page.css('td.content span.css-truncate a').each do |tr|
25
- if tr.content.end_with?(FILENAME)
26
- trimmed_name = tr.content.chomp(FILENAME)
27
- file_list[trimmed_name.downcase] = trimmed_name
28
- end
29
- end
30
- return file_list
31
- end
32
-
33
- # Grabs the latest gitignore.
34
- # Saves .gitignore.
35
- # We check to see if cURL is installed.
36
- #
37
- # As a fallback, scrape the file.
38
- # Arguments:
39
- # name: (String)
40
- #
41
- # Returns:
42
- # Boolean
43
- def self.create_file(name)
44
- request_url = REPOSITORY_RAW_URL + name + FILENAME
45
- system("curl -V > /dev/null")
46
-
47
- if $? == 0
48
- system("echo Fetching gitignore...")
49
- file_created = system("curl --progress -o #{FILENAME} #{request_url}")
50
- return file_created
51
- else
52
- file = Nokogiri::HTML(open(request_url))
53
- file_content = file.css('body p').text
54
-
55
- File.open(FILENAME, "w") do |file|
56
- file.write(file_content)
57
- end
58
-
59
- if File.exist?(FILENAME) && FILENAME.size > 0
60
- return true
61
- else
62
- return false
63
- end
64
- end
65
- end
66
- end
67
- end