peacock 0.1.1 → 0.1.2

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: 9e670fe6062303fb5c99994b30d0d09e2b5f8d66
4
- data.tar.gz: 2dc6f75e2989d0cf07eb248bab647980d58faf0d
3
+ metadata.gz: fac84611573a5fd44f62cde9faa8a1629218d3f8
4
+ data.tar.gz: 90c4812009455f94839f36e632eb2c7166395571
5
5
  SHA512:
6
- metadata.gz: 2fab13f5646f16d876859fda2464dca4fcbedfac49e66716e6a483ad427533d67402125209daba5a55dd81f277f0fa340846cc2fb71eeb014e0e6392ef1fd410
7
- data.tar.gz: 6cf66d6978b987086aa89cd57f89eb77e5cda13d6d75ec9dce533cba09899c7a876b64e1f74bec4adee3283568bc4eba11ca3ecfc4762f0c9659b32a9f41fac7
6
+ metadata.gz: c08ef5075610bae74a67ac04cfb9457f6bfbc2908e10ea56a50866b277fbc9017d325e7ae58eabcf60157755f0ba77f7ef721c16bc8180f386710a2db426df16
7
+ data.tar.gz: 45b12fe8af6c20d2636e30acf764b5276b296e241dbff7867b670234d834577613f44f5f3b12fdf39d65c46146faebbd951e4cded887357046bd531396a3a206
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
+ sdfsd
data/README.md CHANGED
@@ -1,35 +1,39 @@
1
1
  # Peacock
2
2
 
3
- Peacock is still in development. I hope soon to publish the first version.
4
- This gem will make it easy to add files to .gitignore
3
+ Peacock is a small tool to easily manage your .gitignore written in ruby.
5
4
 
6
- TODO: Delete this and the text above, and describe your gem
5
+ At the moment, Peacock can only be executed from the root directory of your repository.
6
+
7
+ In order to perform your changes on .gitignore, peacock will automatically add all current files to the index
8
+ and perform a commit before and after you execute peacock.
7
9
 
8
10
  ## Installation
9
11
 
10
12
  Add this line to your application's Gemfile:
11
13
 
12
- ```ruby
13
- gem 'peacock'
14
- ```
15
-
16
- And then execute:
17
-
18
- $ bundle
19
-
20
- Or install it yourself as:
14
+ Install by executing:
21
15
 
22
16
  $ gem install peacock
23
17
 
24
18
  ## Usage
25
19
 
26
- TODO: Write usage instructions here
27
-
28
- ## Development
29
-
30
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec peacock` to use the code located in this directory, ignoring other installed copies of this gem.
31
-
32
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
20
+ Usage:
21
+ peacock [options] [files/directories]
22
+
23
+ Options:
24
+ -h, [--help] # show this text
25
+ -r, [--root] # use root .gitignore (not functional yet)
26
+ -e, [--extract] # extract file from .gitignore (not functional yet)
27
+ -l, [--list] # list all ignored directories and files (not functional yet)
28
+
29
+ ## TODO
30
+
31
+ - ruby-git does not recognize a repo unless you are in the root directory. a different mechanism is needed
32
+ - implement own small git library for peacock
33
+ - create a test environment and better tests
34
+ - add functionalities
35
+ - custom commit messages
36
+ - comments in .gitignore
33
37
 
34
38
  ## Contributing
35
39
 
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |task|
6
+ task.libs << %w(test)
7
+ task.pattern = 'test/test_*.rb'
8
+ end
data/exe/peacock CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+
3
5
  require "peacock"
4
6
 
5
- puts 'just a test. still under construction. look back later'
7
+ Peacock.execute
8
+
@@ -0,0 +1,67 @@
1
+ module Peacock
2
+
3
+ class Ignorer
4
+
5
+ def self.ignore(opt_hash)
6
+ ignorer = Ignorer.new(opt_hash)
7
+ ignorer.commit_all('peacock: before .gitignore commit')
8
+ ignorer.ignore_files_and_directories
9
+ ignorer.clear_cache
10
+ ignorer.commit_all('peacock: after .gitignore commit')
11
+ end
12
+
13
+ def initialize(opt_hash)
14
+ @hash = opt_hash
15
+ @git_ignore = File.open('.gitignore', 'a+')
16
+ @repo = Git.open Dir.pwd
17
+ end
18
+
19
+ def clear_cache
20
+ # totally ugly, but ruby-git does not support git rm -r --cached
21
+ Open3.popen3('git rm -r --cached .') do |stdin, stdout, stderr, thread|
22
+ # ignore output
23
+ end
24
+ end
25
+
26
+ def commit_all(message)
27
+ begin
28
+ @repo.add(all: true)
29
+ @repo.commit_all(message)
30
+ rescue
31
+ # do nothing
32
+ end
33
+ end
34
+
35
+ def ignore_files_and_directories
36
+ ignore_files
37
+ ignore_directories
38
+ end
39
+
40
+ def ignore_directories
41
+ @hash[:dirs].each do |dir|
42
+ dir = dir + '/' unless dir =~ /\/$/ # add backlash to dir name if it does not exist yet
43
+ check_and_write(dir)
44
+ end
45
+ end
46
+
47
+ def ignore_files
48
+ @hash[:files].each do |file|
49
+ check_and_write(file)
50
+ end
51
+ end
52
+
53
+ def check_and_write(str)
54
+ @git_ignore.write(str + "\n") unless entry_exists?(str)
55
+ @git_ignore.rewind
56
+ end
57
+
58
+ def entry_exists?(entry)
59
+ @git_ignore.each do |line|
60
+ return true if line.chomp == entry
61
+ end
62
+ false
63
+ end
64
+
65
+ end
66
+ end
67
+
@@ -0,0 +1,24 @@
1
+ module Peacock
2
+
3
+ class ParseHash
4
+
5
+ attr_reader :hash
6
+
7
+ def initialize
8
+ @hash = Hash.new
9
+ @hash[:opts] = Array.new
10
+ @hash[:files] = Array.new
11
+ @hash[:dirs] = Array.new
12
+ end
13
+
14
+ def push(type, str)
15
+ @hash[type].push(str)
16
+ end
17
+
18
+ def to_s
19
+ hash.to_s
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,65 @@
1
+ module Peacock
2
+
3
+ class Parser
4
+
5
+ def self.parse
6
+ parser = Parser.new
7
+ parser.check_if_help_text
8
+ parser.parse_args.hash
9
+ end
10
+
11
+ def parse_args
12
+ return_hash = Peacock::ParseHash.new
13
+
14
+ ARGV.each do |arg|
15
+ type = determine_type arg
16
+ return_hash.push(type, arg) unless type.nil?
17
+ end
18
+
19
+ return_hash
20
+ end
21
+
22
+ def determine_type(opt)
23
+ if File.directory?(opt)
24
+ :dirs
25
+ elsif File.file?(opt)
26
+ :files
27
+ elsif options.include?(opt)
28
+ :opts
29
+ else
30
+ nil
31
+ end
32
+ end
33
+
34
+ def check_if_help_text
35
+ if should_print_help?
36
+ puts help_text
37
+ exit 0
38
+ end
39
+ end
40
+
41
+ def should_print_help?
42
+ ARGV.size == 0 || ARGV[0] == '-h' || ARGV[0] == '--help'
43
+ end
44
+
45
+ def help_text
46
+ <<-EOF.gsub /^ */, ''
47
+ Usage:
48
+ \tpeacock [options] [files/directories]
49
+
50
+ Options:
51
+ \t-h, [--help] # show this text
52
+ \t-r, [--root] # use root .gitignore (not functional yet)
53
+ \t-e, [--extract] # extract file from .gitignore (not functional yet)
54
+ \t-l, [--list] # list all ignored directories and files (not functional yet)
55
+ EOF
56
+ end
57
+
58
+ def options
59
+ ['-r', '--root', '-e', '--extract', '-l', '--list']
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
@@ -0,0 +1,7 @@
1
+ module Peacock
2
+
3
+ class PeacockError < StandardError
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,32 @@
1
+ module Peacock
2
+
3
+ class StartupManager
4
+
5
+ def self.check_peacock_requirements
6
+ startup = StartupManager.new
7
+
8
+ begin
9
+ startup.check_git_repository
10
+ rescue PeacockError
11
+ puts 'An error occured. Make sure you are in a git repository and git is installed.'
12
+ exit 1
13
+ end
14
+ end
15
+
16
+ def check_git_repository
17
+ raise PeacockError unless git_repository?
18
+ end
19
+
20
+ # checks if current directory is a git repository
21
+ def git_repository?
22
+ begin
23
+ Git.open Dir.pwd
24
+ true
25
+ rescue
26
+ false
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Peacock
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/peacock.rb CHANGED
@@ -1,5 +1,20 @@
1
- require "peacock/version"
1
+ require 'git'
2
+ require 'open3'
3
+
4
+ require 'peacock/version'
5
+ require 'peacock/peacock_exception'
6
+ require 'peacock/startup_manager'
7
+ require 'peacock/parse_hash'
8
+ require 'peacock/parser'
9
+ require 'peacock/ignorer'
10
+
2
11
 
3
12
  module Peacock
4
- # Your code goes here...
13
+
14
+ def self.execute
15
+ Peacock::StartupManager.check_peacock_requirements
16
+ parse_hash = Peacock::Parser.parse
17
+ Peacock::Ignorer.ignore(parse_hash)
18
+ end
19
+
5
20
  end
data/peacock.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.9"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "git"
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peacock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Paling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-11 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: git
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Longer Description
42
56
  email:
43
57
  - christian.paling@googlemail.com
@@ -52,10 +66,13 @@ files:
52
66
  - LICENSE.txt
53
67
  - README.md
54
68
  - Rakefile
55
- - bin/console
56
- - bin/setup
57
69
  - exe/peacock
58
70
  - lib/peacock.rb
71
+ - lib/peacock/ignorer.rb
72
+ - lib/peacock/parse_hash.rb
73
+ - lib/peacock/parser.rb
74
+ - lib/peacock/peacock_exception.rb
75
+ - lib/peacock/startup_manager.rb
59
76
  - lib/peacock/version.rb
60
77
  - peacock.gemspec
61
78
  homepage: https://github.com/bakku/peacock
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "peacock"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here