gitignores 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -4,18 +4,22 @@ Tool for building a .gitignore from community templates at [github/gitignore](ht
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ $ gem install gitignores
8
8
 
9
- gem 'gitignores'
9
+ ## Usage
10
10
 
11
- And then execute:
11
+ **add** append a list of .gitignores to the `.gitignore` in the current directory. Example:
12
12
 
13
- $ bundle
13
+ gitignores add Java IntelliJ Eclipse
14
14
 
15
- Or install it yourself as:
15
+ Adds gitignores for Java, IntelliJ, Eclipse to CURRENT_DIR/.gitignore
16
16
 
17
- $ gem install gitignores
17
+ **show** prints a concatenation of .gitignores to std_out
18
18
 
19
- ## Usage
19
+ gitignores show Java IntelliJ Eclipse
20
+
21
+ Prints gitignores for Java, IntelliJ, Eclipse to standard out
22
+
23
+ **list** prints a list of available gitignores
20
24
 
21
- TODO: Write usage instructions here
25
+ gitignores list
data/bin/gitignores CHANGED
@@ -11,24 +11,42 @@ class App
11
11
  include Methadone::CLILogging
12
12
  include Methadone::ExitNow
13
13
 
14
- main do |*ignores|
14
+ main do |command, *ignores|
15
15
  opts = {
16
16
  :ignores_dir => options['use-directory'],
17
- :update_ignores => options['update'],
18
- # :out => STDOUT
17
+ :update_ignores => options['update']
19
18
  }
19
+
20
+ gitignores = Gitignores::Gitignores.new(options)
21
+
22
+ if(options[:os])
23
+ ignores.concat ["OSX", "Windows", "Linux"]
24
+ end
25
+ ignores.uniq!
26
+
20
27
  begin
21
- Gitignores.main(ignores, opts)
28
+ case command
29
+ when "add"
30
+ gitignores.add(ignores)
31
+ when "show"
32
+ gitignores.show(ignores)
33
+ when "list"
34
+ gitignores.list
35
+ else
36
+ help_now! "Command \"#{command}\" not recognized"
37
+ end
22
38
  rescue Gitignores::GitignoreNotFoundException => e
23
- exit_now!(1, "Couldn't find ignore \"#{e.ignore_name}\"")
39
+ exit_now(1, "Couldn't find ignore \"#{e.ignore_name}\"")
24
40
  end
25
41
  end
26
42
 
27
43
  options['use-directory'] = ENV['HOME'] + '/.gitignores'
28
44
  on("-d ignore-repository", "--use-directory", "The directory in which to store the github/gitignore directory")
29
45
  on("--update", "Update the github/gitignore repository")
46
+ on("--os", "Include ignores for all operating systems")
30
47
 
31
- arg :ignores, :many
48
+ arg :command, :required
49
+ arg :ignores, :any
32
50
 
33
51
  description Gitignores::DESCRIPTION
34
52
 
@@ -37,4 +55,4 @@ class App
37
55
  use_log_level_option
38
56
 
39
57
  go!
40
- end
58
+ end
data/lib/gitignores.rb CHANGED
@@ -1,23 +1,39 @@
1
1
  require 'logger'
2
+ require 'methadone'
2
3
  require 'gitignores/builder'
3
4
  require 'gitignores/fetcher'
4
5
 
5
6
  module Gitignores
7
+ class Gitignores
8
+ include Methadone::CLILogging
6
9
 
7
- def self.main(ignores, options = {})
8
- out_file = File.open('.gitignore', 'a')
9
- options = {
10
- :update_ignores => false,
11
- :ignores_dir => ENV['HOME'] + '/.gitignores',
12
- :out => out_file
13
- }.merge(options)
10
+ def initialize(options = {})
11
+ options = {
12
+ :update_ignores => false,
13
+ :ignores_dir => ENV['HOME'] + '/.gitignores'
14
+ }.merge(options)
14
15
 
15
- builder = GitignoreBuilder.new
16
- builder.ignores_dir = options[:ignores_dir]
17
- fetcher = GitignoreFetcher.new
18
- fetcher.update_ignores = options[:update_ignores]
16
+ @builder = GitignoreBuilder.new
17
+ @builder.ignores_dir = options[:ignores_dir]
18
+ @fetcher = GitignoreFetcher.new(options[:ignores_dir])
19
+ @fetcher.update_ignores = options[:update_ignores]
19
20
 
20
- fetcher.fetch_gitignores options[:ignores_dir]
21
- builder.build(ignores, options[:out])
21
+ @fetcher.fetch_gitignores
22
+ end
23
+
24
+ def add(ignores)
25
+ out_file = File.open('.gitignore', 'a')
26
+ @builder.build(ignores, out_file)
27
+ end
28
+
29
+ def show(ignores)
30
+ @builder.build(ignores, STDOUT)
31
+ end
32
+
33
+ def list()
34
+ @fetcher.list_gitignores.each { |x|
35
+ info(x)
36
+ }
37
+ end
22
38
  end
23
39
  end
@@ -3,12 +3,12 @@ require 'gitignores'
3
3
 
4
4
  module Gitignores
5
5
  class GitignoreFetcher
6
- include Gitignores
7
6
  include Methadone::CLILogging
8
7
 
9
- attr_writer :git, :update_ignores
8
+ attr_writer :git, :update_ignores, :ignores_dir
10
9
 
11
- def initialize
10
+ def initialize(ignores_dir)
11
+ @ignores_dir = ignores_dir
12
12
  @update_ignores = false
13
13
  @git = Git.new
14
14
  end
@@ -16,16 +16,24 @@ module Gitignores
16
16
  # If needed, retrieves gitignores from Github and places them in @ignores_dir
17
17
  # If @update_ignores? is set, will try to update the latest gitignores
18
18
  # Will store all gitignores in the @ignores_dir
19
- def fetch_gitignores(ignores_dir)
20
- unless (Dir.exists?(ignores_dir))
21
- debug "Cloning github/gitignores to #{ignores_dir}"
22
- @git.clone 'https://github.com/github/gitignore.git', ignores_dir
19
+ def fetch_gitignores()
20
+ unless (Dir.exists?(@ignores_dir))
21
+ debug "Cloning github/gitignores to #{@ignores_dir}"
22
+ @git.clone 'https://github.com/github/gitignore.git', @ignores_dir
23
23
  end
24
24
  if @update_ignores
25
- debug "Updating repository at #{ignores_dir}"
26
- @git.pull ignores_dir
25
+ debug "Updating repository at #{@ignores_dir}"
26
+ @git.pull @ignores_dir
27
27
  end
28
28
  end
29
+
30
+ def list_gitignores()
31
+ fetch_gitignores
32
+
33
+ Dir.glob(@ignores_dir + "/**/*.gitignore").collect { |x|
34
+ File.basename x, ".gitignore"
35
+ }
36
+ end
29
37
  end
30
38
 
31
39
  # Encapsulate Git commands in this helper class in order to help mock the command line
@@ -34,12 +42,12 @@ module Gitignores
34
42
  include Methadone::CLILogging
35
43
 
36
44
  def clone(repo, directory)
37
- sh "git clone #{repo} #{directory}"
45
+ sh! "git clone #{repo} #{directory}"
38
46
  end
39
47
 
40
48
  def pull(directory)
41
49
  Dir.chdir(directory) {
42
- sh "git pull"
50
+ sh! "git pull"
43
51
  }
44
52
  end
45
53
  end
@@ -1,5 +1,5 @@
1
1
  module Gitignores
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
 
4
4
  SUMMARY = "Generates .gitignore"
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitignores
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-23 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &10702520 !ruby/object:Gem::Requirement
16
+ requirement: &16625400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *10702520
24
+ version_requirements: *16625400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &10726680 !ruby/object:Gem::Requirement
27
+ requirement: &16608200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *10726680
35
+ version_requirements: *16608200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: methadone
38
- requirement: &10724840 !ruby/object:Gem::Requirement
38
+ requirement: &16605440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.3.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *10724840
46
+ version_requirements: *16605440
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &10722260 !ruby/object:Gem::Requirement
49
+ requirement: &16603200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *10722260
57
+ version_requirements: *16603200
58
58
  description: Tool for building .gitignore from community templates at github/gitignore
59
59
  email:
60
60
  - me@johnathangilday.com