clr 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clr.gemspec
4
+ gemspec
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', version: 2, cli: '--color --format Fuubar' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 lefty313
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.
@@ -0,0 +1,38 @@
1
+ # Clr
2
+
3
+ This gem manages the markers for debugging e.g. binding.pry
4
+
5
+ In this video you can see how it works http://www.youtube.com/watch?v=yd9kQEYALTc&hd=1
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'clr'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install clr
20
+
21
+ ## Usage
22
+ ```shell
23
+ clr clean [PATH || Dir.pwd]
24
+
25
+ Options:
26
+ -c, [--comment] # comment all markers
27
+ -u, [--uncomment] # uncomment all markers
28
+ -r, [--remove] # remove all markers
29
+ -s, [--search] # search markers
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/clr ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler'
3
+ require 'clr/cli'
4
+
5
+ Clr::Cli.start
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/clr/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["lefty313"]
6
+ gem.email = ["lewy313@gmail.com"]
7
+ gem.description = %q{This gem manages the markers for debugging}
8
+ gem.summary = %q{This gem manages the markers for debugging}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "clr"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Clr::VERSION
17
+
18
+ gem.add_dependency "thor"
19
+
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "pry"
22
+ gem.add_development_dependency "guard-rspec"
23
+ gem.add_development_dependency "simplecov"
24
+ gem.add_development_dependency "fuubar"
25
+ gem.add_development_dependency 'rb-inotify', '~> 0.8.8'
26
+ end
@@ -0,0 +1,5 @@
1
+ require "clr/version"
2
+
3
+ module Clr
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,101 @@
1
+ require 'thor'
2
+ require 'clr/search'
3
+
4
+ module Clr
5
+ class Cli < Thor
6
+ include Thor::Actions
7
+
8
+ default_task :clean
9
+
10
+ FORCE_PATTERNS = [
11
+ /\s*binding\.pry/,
12
+ /\s*require .pry./,
13
+ ]
14
+ PATTERNS = [
15
+ /binding\.pry/,
16
+ /require .pry./,
17
+ ]
18
+
19
+ desc "clean [PATH || Dir.pwd]", "Manage your debugging markers"
20
+ method_option :comment, :type => :boolean, :aliases => "-c", :desc => 'comment all markers'
21
+ method_option :uncomment, :type => :boolean, :aliases => "-u", :desc => 'uncomment all markers'
22
+ method_option :remove, :type => :boolean, :aliases => "-r", :desc => 'remove all markers'
23
+ method_option :search, :type => :boolean, :aliases => "-s", :desc => 'search markers'
24
+ def clean(path = Dir.pwd)
25
+ @path = Pathname.new(path)
26
+
27
+ search_markers if options[:search]
28
+ comment_markers if options[:comment]
29
+ uncomment_markers if options[:uncomment]
30
+ remove_markers if options[:remove]
31
+ end
32
+
33
+ private
34
+
35
+ def search_markers
36
+ each_entry.summary do |filepath, markers|
37
+ say_status :found, "#{markers} markers in #{filepath}"
38
+ end
39
+ end
40
+
41
+ def comment_markers
42
+ report = each_entry do |file, regexp|
43
+ comment_lines file, regexp, :verbose => false
44
+ end
45
+
46
+ report.summary do |filepath, markers|
47
+ say_status :commented, "#{markers} markers in file #{filepath}"
48
+ end
49
+ end
50
+
51
+ def uncomment_markers(verbose = true)
52
+ report = each_entry do |file, regexp|
53
+ uncomment_lines file, regexp, :verbose => false
54
+ end
55
+
56
+ return nil unless verbose
57
+ report.summary do |filepath, markers|
58
+ say_status :uncommented, "#{markers} markers in file #{filepath}"
59
+ end
60
+ end
61
+
62
+ def remove_markers
63
+ uncomment_markers(false)
64
+
65
+ report = each_entry(FORCE_PATTERNS) do |file, regexp|
66
+ gsub_file file, regexp, '', :verbose => false
67
+ end
68
+
69
+ report.summary do |filepath, markers|
70
+ say_status :removed, "#{markers} markers from file #{filepath}"
71
+ end
72
+ end
73
+
74
+ def files_to_visit
75
+ unless @path.exist?
76
+ say_status(:error, "This path not exist: #{@path}", :red)
77
+ exit
78
+ end
79
+
80
+ @files_to_visit ||= if @path.file?
81
+ Array(@path)
82
+ else
83
+ files = Pathname.glob(@path.join('**/*'))
84
+ files.reject { |path| path.directory? }
85
+ end
86
+ end
87
+
88
+ def each_entry(patterns = PATTERNS)
89
+ engine = Search.new
90
+
91
+ files_to_visit.each do |file|
92
+ patterns.each do |pattern|
93
+ item = engine.perform file, pattern
94
+ yield file, pattern if block_given? && item.matches_count > 0
95
+ end
96
+ end
97
+ engine
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,31 @@
1
+ module Clr
2
+ class Search
3
+ attr_reader :results
4
+
5
+ class Item < Struct.new(:filepath, :pattern, :matches)
6
+ def matches_count
7
+ matches.count
8
+ end
9
+ end
10
+
11
+ def initialize
12
+ @results = Array.new
13
+ end
14
+
15
+ def perform(file, pattern)
16
+ text = file.binread
17
+ matches = text.scan(pattern)
18
+ item = Item.new(file, pattern, matches)
19
+ results.push(item).last
20
+ end
21
+
22
+ def summary
23
+ results.group_by(&:filepath).each do |filepath, collection|
24
+ # number of markers in file
25
+ occurrences = collection.map(&:matches_count).inject(0,:+)
26
+
27
+ yield filepath, occurrences, collection if occurrences > 0
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Clr
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+ require 'clr/cli'
3
+
4
+ describe Clr::Cli do
5
+ context "-s" do
6
+ it 'should exit unless path exist' do
7
+ expect { command 'clean', 'file.not_exist', '-s' }.to raise_error SystemExit
8
+ end
9
+
10
+ it 'should find all markers in file' do
11
+ in_temp_dir do
12
+ copy_fixture
13
+ result = command 'clean', 'app.rb', '-s'
14
+ result.should =~ /found.* 5 markers in app.rb/
15
+ end
16
+ end
17
+
18
+ it 'should find all markers in dir' do
19
+ in_temp_dir do
20
+ copy_fixture
21
+ result = command 'clean','nested', '-s'
22
+ result.should =~ /found.* 1 markers in nested\/deep\/foo\.rb/
23
+ end
24
+ end
25
+
26
+ it 'should find all markers in current directory' do
27
+ in_temp_dir do
28
+ copy_fixture
29
+ result = command 'clean','-s'
30
+ result.should =~ /found.* 1 markers in .*nested\/deep\/foo\.rb/
31
+ result.should =~ /found.* 5 markers in .*app.rb/
32
+ result.lines.should have(2).items
33
+ end
34
+ end
35
+ end
36
+
37
+ context "-c" do
38
+ it 'should comment markers in file' do
39
+ in_temp_dir do
40
+ copy_fixture
41
+ result = command 'clean', 'app.rb','-c'
42
+
43
+ File.read('app.rb').should == pattern_file('commented/app.rb')
44
+ result.should =~ /commented.* 5 markers in file app.rb/
45
+ end
46
+ end
47
+ end
48
+
49
+ context "-u" do
50
+ it 'should uncomment markers in file' do
51
+ in_temp_dir do
52
+ copy_fixture
53
+ command 'clean', 'app.rb','-c'
54
+ result = command 'clean', 'app.rb','-u'
55
+
56
+ File.read('app.rb').should == pattern_file('uncommented/app.rb')
57
+ result.should =~ /uncommented.* 5 markers in file app.rb/
58
+ end
59
+ end
60
+ end
61
+
62
+ context "-r" do
63
+ it 'should remove markers from file' do
64
+ in_temp_dir do
65
+ copy_fixture
66
+ result = command 'clean', 'app.rb', '-r'
67
+
68
+ File.read('app.rb').should == pattern_file('removed/app.rb')
69
+ result.should =~ /removed.* 5 markers from file app.rb/
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ def command(*args)
77
+ capture(:stdout) { subject.class.start(args) }
78
+ end
79
+
80
+ def fixture
81
+ root = Pathname.new(__FILE__)
82
+ root.dirname.join('fixtures/app/.')
83
+ end
84
+
85
+ def pattern_file(path)
86
+ root = Pathname.new(__FILE__)
87
+ file = root.dirname.join("fixtures/pattern/#{path}")
88
+ file.read
89
+ end
90
+
91
+ def copy_fixture
92
+ FileUtils.cp_r fixture, Dir.pwd
93
+ end
@@ -0,0 +1,14 @@
1
+ require 'pry'
2
+ binding.pry
3
+ class Foo
4
+ def foo
5
+ [1,2,3].each { binding.pry }
6
+ end
7
+
8
+ def bar
9
+ [1,2,3].each do |n|
10
+ binding.pry
11
+ end
12
+ end
13
+ end
14
+ binding.pry
@@ -0,0 +1,3 @@
1
+ require 'pry'
2
+
3
+ 2 + 2
@@ -0,0 +1,14 @@
1
+ # require 'pry'
2
+ # binding.pry
3
+ class Foo
4
+ def foo
5
+ # [1,2,3].each { binding.pry }
6
+ end
7
+
8
+ def bar
9
+ [1,2,3].each do |n|
10
+ # binding.pry
11
+ end
12
+ end
13
+ end
14
+ # binding.pry
@@ -0,0 +1,11 @@
1
+
2
+ class Foo
3
+ def foo
4
+ [1,2,3].each { }
5
+ end
6
+
7
+ def bar
8
+ [1,2,3].each do |n|
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require 'pry'
2
+ binding.pry
3
+ class Foo
4
+ def foo
5
+ [1,2,3].each { binding.pry }
6
+ end
7
+
8
+ def bar
9
+ [1,2,3].each do |n|
10
+ binding.pry
11
+ end
12
+ end
13
+ end
14
+ binding.pry
@@ -0,0 +1,37 @@
1
+ require 'pry'
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # Require this file using `require "spec_helper"` to ensure that it is only
5
+ # loaded once.
6
+ #
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
19
+
20
+ def capture(stream)
21
+ begin
22
+ stream = stream.to_s
23
+ eval "$#{stream} = StringIO.new"
24
+ yield
25
+ result = eval("$#{stream}").string
26
+ ensure
27
+ eval("$#{stream} = #{stream.upcase}")
28
+ end
29
+ result
30
+ end
31
+
32
+ def in_temp_dir(&block)
33
+ dir = Dir.mktmpdir
34
+ Dir.chdir(dir, &block)
35
+ ensure
36
+ FileUtils.rm_rf(dir)
37
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - lefty313
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fuubar
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rb-inotify
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.8.8
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.8.8
126
+ description: This gem manages the markers for debugging
127
+ email:
128
+ - lewy313@gmail.com
129
+ executables:
130
+ - clr
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .rspec
136
+ - Gemfile
137
+ - Guardfile
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - bin/clr
142
+ - clr.gemspec
143
+ - lib/clr.rb
144
+ - lib/clr/cli.rb
145
+ - lib/clr/search.rb
146
+ - lib/clr/version.rb
147
+ - spec/cli_spec.rb
148
+ - spec/fixtures/app/app.rb
149
+ - spec/fixtures/app/nested/deep/foo.rb
150
+ - spec/fixtures/pattern/commented/app.rb
151
+ - spec/fixtures/pattern/removed/app.rb
152
+ - spec/fixtures/pattern/uncommented/app.rb
153
+ - spec/spec_helper.rb
154
+ homepage: ''
155
+ licenses: []
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 1.8.24
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: This gem manages the markers for debugging
178
+ test_files:
179
+ - spec/cli_spec.rb
180
+ - spec/fixtures/app/app.rb
181
+ - spec/fixtures/app/nested/deep/foo.rb
182
+ - spec/fixtures/pattern/commented/app.rb
183
+ - spec/fixtures/pattern/removed/app.rb
184
+ - spec/fixtures/pattern/uncommented/app.rb
185
+ - spec/spec_helper.rb
186
+ has_rdoc: