tree_trimmer 0.1.0 → 0.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: 301a095221002fd01b2e19a9d42ca6033cee9898
4
- data.tar.gz: f6d1dc6b7f11cf426281ef7f2dc68d8aad9846a7
3
+ metadata.gz: 998c481662ceae8e15f91f1a8452f5df5e206b41
4
+ data.tar.gz: 07bc104b5f8852eaeb6bc6b4904775354d2a56bf
5
5
  SHA512:
6
- metadata.gz: 3a8740755e2bcd685f87a670e00343b57f6f59b60c9fcb09f91fc06e27e923062228c75c73a69929157871f8afef136dfb2c0507fe607ce048126cf398518171
7
- data.tar.gz: e509cc5bd521b6576417919bb913c386ec1d4f55c346e041aa70fc221df8c716daedbad13c15479981a42203e7ce2bbd108cfc9a2f7a9f537bd508d07adb8b4b
6
+ metadata.gz: 3aec51c049593dd0e664372607774c44aca3a05dd7aa96fa8aaf68c933d5026d4e819a5a34612d7299b04e514b5cfc72a6684cff103504f91cef19e13d6581b0
7
+ data.tar.gz: 1887d58aa8e9348b6375c01dc984cccf256bd3bb3d3e7beca18b990b956d000b64125612fb8db36c7794c1ace6fda36f6c92e599d76f83677cc60fba4f471ca6
@@ -0,0 +1,37 @@
1
+ # This is a sample .codeclimate.yml configured for Engine analysis on Code
2
+ # Climate Platform. For an overview of the Code Climate Platform, see here:
3
+ # http://docs.codeclimate.com/article/300-the-codeclimate-platform
4
+
5
+ # Under the engines key, you can configure which engines will analyze your repo.
6
+ # Each key is an engine name. For each value, you need to specify enabled: true
7
+ # to enable the engine as well as any other engines-specific configuration.
8
+
9
+ # For more details, see here:
10
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
11
+
12
+ # For a list of all available engines, see here:
13
+ # http://docs.codeclimate.com/article/296-engines-available-engines
14
+
15
+ engines:
16
+ # to turn on an engine, add it here and set enabled to `true`
17
+ # to turn off an engine, set enabled to `false` or remove it
18
+ rubocop:
19
+ enabled: true
20
+
21
+ # Engines can analyze files and report issues on them, but you can separately
22
+ # decide which files will receive ratings based on those issues. This is
23
+ # specified by path patterns under the ratings key.
24
+
25
+ # For more details see here:
26
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
27
+
28
+ ratings:
29
+ paths:
30
+ - lib/**
31
+
32
+ # You can globally exclude files from being analyzed by any engine using the
33
+ # exclude_paths key.
34
+
35
+ #exclude_paths:
36
+ #- spec/**/*
37
+ #- vendor/**/*
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.3
4
+ addons:
5
+ code_climate:
6
+ repo_token: f3f262681f3d63918bf161a3951444a6fd8bd920d656c31a6ee26b10db702780
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in tree_trimmer.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "faker"
8
+ gem "minitest"
9
+ end
10
+
11
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # TreeTrimmer
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/tree_trimmer.svg)](http://badge.fury.io/rb/tree_trimmer) [![Build Status](https://travis-ci.org/davidbegin/tree_trimmer.svg?branch=master)](https://travis-ci.org/davidbegin/tree_trimmer) [![Test Coverage](https://codeclimate.com/github/davidbegin/tree_trimmer/badges/coverage.svg)](https://codeclimate.com/github/davidbegin/tree_trimmer/coverage) [![Code Climate](https://codeclimate.com/github/davidbegin/tree_trimmer/badges/gpa.svg)](https://codeclimate.com/github/davidbegin/tree_trimmer) [![Dependency Status](https://gemnasium.com/presidentJFK/tree_trimmer.svg)](https://gemnasium.com/presidentJFK/tree_trimmer) [![Inline docs](http://inch-ci.org/github/presidentJFK/tree_trimmer.svg?branch=master)](http://inch-ci.org/github/presidentJFK/tree_trimmer)
4
+
5
+ ### \*\*WARNING THIS GEM IS PRE 1.0 AND STILL UNSTABLE\*\*
6
+
3
7
  A soon-to-be command line tool for cleaning up Git Branches
4
8
 
5
9
  ## Installation
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ task :default => "test"
4
+
5
+ desc "run all tests"
6
+ task :test do
7
+ Dir.glob("test/test*.rb").each do |file|
8
+ require_relative file
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ require_relative "../lib/tree_trimmer"
2
+
3
+ TreeTrimmer.lets_clean_up_some_branches
@@ -1,73 +1,19 @@
1
+ # require_relative "tree_trimmer/version"
2
+ # require_relative "tree_trimmer/base"
1
3
  require "tree_trimmer/version"
2
- require "downup"
3
- require "colorize"
4
+ require "tree_trimmer/base"
4
5
 
5
6
  module TreeTrimmer
6
- def self.lets_clean_up_some_branches
7
- puts "\nBranches to Clean:\n\n"
8
- Base.new.trim_branches
9
- end
10
-
11
- private
12
-
13
- class Base
14
- def initialize
15
- sanitize_branches!
16
- end
17
-
18
- def trim_branches
19
- @selection = Downup::Base.new(
20
- options: downup_options,
21
- type: :multi_select
22
- ).prompt
23
-
24
- delete_branches
7
+ class << self
8
+ def lets_clean_up_some_branches
9
+ puts "\nBranches to Clean:\n\n"
10
+ tree_trimmer.trim_branches
25
11
  end
26
12
 
27
13
  private
28
14
 
29
- def downup_options
30
- branch_options.zip(branches).each_with_object({}) do |option, hash|
31
- hash[option.first] = option.last
32
- end
33
- end
34
-
35
- def branch_options
36
- @branch_options ||= ("a".."z").take(branches.count)
37
- end
38
-
39
- def branches
40
- @branches ||= IO.popen("git branch").each_line.map(&:chomp).map(&:lstrip)
41
- end
42
-
43
- def delete_branches
44
- puts "\n\nDelete Branches?\n".red
45
- puts @selection
46
- print "\n(y/n) > ".light_black
47
- process_input(gets.chomp)
48
- end
49
-
50
- def process_input(input)
51
- case input
52
- when "y"
53
- @selection.each do |branch|
54
- cmd = "git branch -D #{branch}"
55
- puts "\n...running " + cmd.red + "\n\n"
56
- system(cmd)
57
- end
58
- when "n"
59
- else
60
- puts "please choose y or n"
61
- delete_branches
62
- end
63
- end
64
-
65
- def sanitize_branches!
66
- branches.each do |branch|
67
- if branch.include?("master")
68
- branches.delete(branch)
69
- end
70
- end
15
+ def tree_trimmer
16
+ Base.new
71
17
  end
72
18
  end
73
19
  end
@@ -0,0 +1,121 @@
1
+ require "colorize"
2
+ require "downup"
3
+
4
+ module TreeTrimmer
5
+ class Base
6
+
7
+ # @param multi_select_selector [String] selector for Downup Menu of when
8
+ # chosing branches to delete
9
+ # @param selected_color [Symbol] color of selector when chosing a branch to delete
10
+ def initialize(multi_select_selector: "x",
11
+ selected_color: :red,
12
+ stdin: $stdin,
13
+ stdout: $stdout)
14
+
15
+ @stdin = stdin
16
+ @stdout = stdout
17
+ @multi_select_selector = multi_select_selector
18
+ @selected_color = selected_color
19
+ sanitize_branches!
20
+ end
21
+
22
+ # Uses the git branches of the current folder
23
+ # to create a Menu with Downup
24
+ #
25
+ # Once branches are choosen,
26
+ # users are prompted to confirm delete the choosen branches.
27
+ #
28
+ # The appropiate action is taken based on the user's input
29
+ # and the deleted or undeleted branches are returned.
30
+ def trim_branches
31
+ @selection = Downup::Base.new(
32
+ options: branch_options,
33
+ type: :multi_select,
34
+ multi_select_selector: multi_select_selector,
35
+ selected_color: selected_color,
36
+ header_proc: header_proc
37
+ ).prompt
38
+
39
+ delete_branches_confirmation
40
+ @selection
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :stdout, :stdin, :multi_select_selector, :selected_color
46
+
47
+ def branch_options
48
+ branch_keys.zip(branches).each_with_object({}) do |option, hash|
49
+ hash[option.first] = option.last
50
+ end
51
+ end
52
+
53
+ def branch_keys
54
+ ("a".."z").take(branches.count)
55
+ end
56
+
57
+ def branches
58
+ IO.popen("git branch").each_line.map(&:chomp).map(&:lstrip)
59
+ end
60
+
61
+ def delete_branches_confirmation
62
+ stdout.puts "\n\nDelete Branches?\n".red
63
+ stdout.puts @selection
64
+ stdout.print "\n(y/n) > ".light_black
65
+ process_input(stdin.gets.chomp)
66
+ end
67
+
68
+ def process_input(input)
69
+ case input
70
+ when "y" then delete_branches!
71
+ when "n" then quit_or_continue
72
+ else
73
+ stdout.puts "please choose y or n"
74
+ delete_branches_confirmation
75
+ end
76
+ end
77
+
78
+ def delete_branches!
79
+ @selection.each do |branch|
80
+ cmd = "git branch -D #{branch}"
81
+ stdout.puts "\n...running " + cmd.red + "\n\n"
82
+ system(cmd)
83
+ end
84
+ quit_or_continue
85
+ end
86
+
87
+ def quit_or_continue
88
+ quit_or_continue_prompt
89
+ case stdin.gets.chomp
90
+ when "q", "quit"
91
+ stdout.puts "\n...thanks for using tree trimmer!".light_cyan
92
+ when "c", "continue"
93
+ trim_branches
94
+ else
95
+ stdout.puts "please choose a relevant option"
96
+ quit_or_continue
97
+ end
98
+ end
99
+
100
+ def sanitize_branches!
101
+ branches.each do |branch|
102
+ branches.delete(branch) if branch.include?("master")
103
+ end
104
+ end
105
+
106
+ def quit_or_continue_prompt
107
+ stdout.puts ("-" * 80).light_black
108
+ stdout.puts "\nq or quit to abort".light_red
109
+ stdout.puts "c or continue to continue\n".light_yellow
110
+ stdout.print "> "
111
+ end
112
+
113
+ def header_proc
114
+ proc {
115
+ stdout.puts "\n------------------"
116
+ stdout.puts "-- Tree Trimmer --"
117
+ stdout.puts "------------------\n\n"
118
+ }
119
+ end
120
+ end
121
+ end
@@ -1,3 +1,3 @@
1
1
  module TreeTrimmer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = ["tree_trimmer"]
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "bundler"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_runtime_dependency "downup", "~> 0.10.6"
24
+ spec.add_runtime_dependency "downup", "0.11.6"
25
25
  spec.add_runtime_dependency "colorize"
26
26
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_trimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Begin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-29 00:00:00.000000000 Z
11
+ date: 2015-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: downup
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.10.6
47
+ version: 0.11.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.10.6
54
+ version: 0.11.6
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: colorize
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".codeclimate.yml"
77
78
  - ".gitignore"
78
79
  - ".travis.yml"
79
80
  - CODE_OF_CONDUCT.md
@@ -84,7 +85,9 @@ files:
84
85
  - bin/console
85
86
  - bin/setup
86
87
  - bin/tree_trimmer
88
+ - examples/basic.rb
87
89
  - lib/tree_trimmer.rb
90
+ - lib/tree_trimmer/base.rb
88
91
  - lib/tree_trimmer/version.rb
89
92
  - tree_trimmer.gemspec
90
93
  homepage: https://github.com/presidentJFK/tree_trimmer