discover_tabs 0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f2c20999e5198d37a1ebb13f5081eb2fd86f203
4
+ data.tar.gz: 0334b4fb74dce96269f5ce0b1c3c99a9278379bd
5
+ SHA512:
6
+ metadata.gz: ea0b7aeb673d91868f75f2475f1afc5a2c9797bf50c4447ecc3f6eec2ff5d63a54e88700351823288b5785f3112a2923180bcf5ef14e12733432f9f6f80a7eca
7
+ data.tar.gz: da59df03c9963dc13a94b99fbbbf4a7b8d8cc92f105d7692909d077862c7a777bb8462eda68e3a8830b610112d157b124c75094b4f2e48d598420dbf1a461c62
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rspec"
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Bas Vodde
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ discover_tabs
2
+ =============
3
+
4
+ Discover which files use tabs
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+
6
+ desc "Run the spec tasks"
7
+ RSpec::Core::RakeTask.new(:spec)
data/bin/discover_tabs ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'discover_tabs.rb'
5
+
6
+ DiscoverTabs.cmdline_run(ARGV)
@@ -0,0 +1,45 @@
1
+ require 'pathname'
2
+ require 'ptools'
3
+
4
+ module DiscoverTabs
5
+
6
+ def self.in_dir(dir, pattern = "*")
7
+ files_with_tabs = false
8
+ Dir["#{dir}/**/#{pattern}"].each do |file|
9
+ begin
10
+ has_tabs = false
11
+ unless File.directory?(file) || File.binary?(file)
12
+ has_tabs = in_file(file)
13
+ end
14
+ rescue ArgumentError
15
+ end
16
+ files_with_tabs ||= has_tabs
17
+ end
18
+ files_with_tabs
19
+ end
20
+
21
+ def self.in_file(filename)
22
+ File.readlines(filename).each do |line|
23
+ if line =~ /^\t+/
24
+ puts Pathname.new(filename).cleanpath.to_s
25
+ return true
26
+ end
27
+ end
28
+ false
29
+ end
30
+
31
+ def self.cmdline_run(argv)
32
+ full_path = argv[0] || "."
33
+ filename = File.basename(full_path)
34
+ dirname = File.dirname(full_path)
35
+
36
+ found_tabs = if File.directory?(full_path)
37
+ in_dir(full_path)
38
+ elsif filename.include?("*")
39
+ in_dir(dirname, filename)
40
+ else
41
+ in_file(full_path)
42
+ end
43
+ found_tabs ? 0 : 1
44
+ end
45
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ module DiscoverTabs
3
+ VERSION = "0.5"
4
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "It can discover tabs" do
4
+
5
+ it "Can discover tabs in one file" do
6
+ DiscoverTabs.should_receive(:puts).with(/file_with_tabs.rb/)
7
+ DiscoverTabs.in_file(test_data("file_with_tabs.rb")).should== true
8
+ end
9
+
10
+ it "Won't discover tabs in one file without tabs" do
11
+ DiscoverTabs.should_not_receive(:puts)
12
+ DiscoverTabs.in_file(test_data("file_without_tabs.rb")).should== false
13
+ end
14
+
15
+ it "Won't discover any files with tabs in a directory when there are none" do
16
+ DiscoverTabs.should_not_receive(:puts)
17
+ DiscoverTabs.in_dir(test_data("dir_without_tabbled_files")).should== false
18
+ end
19
+
20
+ it "Won't discover any files with tabs in a directory when there are none" do
21
+ DiscoverTabs.should_receive(:puts).with(/dir_with_some_tabbed_files\/1.rb/)
22
+ DiscoverTabs.should_receive(:puts).with(/dir_with_some_tabbed_files\/8\/1.rb/)
23
+ DiscoverTabs.should_receive(:puts).with(/dir_with_some_tabbed_files\/dir\/4.rb/)
24
+ DiscoverTabs.in_dir(test_data("dir_with_some_tabbed_files")).should== true
25
+ end
26
+
27
+ it "Can deal with the current dir" do
28
+ DiscoverTabs.should_receive(:puts).at_least(1).times
29
+ DiscoverTabs.in_dir(".").should== true
30
+ end
31
+
32
+ it "Should swallow ArgumentError expections" do
33
+ DiscoverTabs.stub(:in_file).and_raise(ArgumentError)
34
+ DiscoverTabs.in_dir(".").should== false
35
+ end
36
+
37
+ it "Makes sure the pathname is clean" do
38
+ DiscoverTabs.should_receive(:puts).with(/dir_with_some_tabbed_files_and_different_extensions\/tabs.rb/)
39
+ DiscoverTabs.should_receive(:puts)
40
+ DiscoverTabs.in_dir(test_data("dir_with_some_tabbed_files_and_different_extensions/")).should== true
41
+ end
42
+
43
+ it "will only find the files with a certain extension" do
44
+ DiscoverTabs.should_receive(:puts).with(/dir_with_some_tabbed_files_and_different_extensions\/tabs.rb/)
45
+ DiscoverTabs.should_not_receive(:puts).with(/dir_with_some_tabbed_files_and_different_extensions\tabs.cpp/)
46
+ DiscoverTabs.in_dir(test_data("dir_with_some_tabbed_files_and_different_extensions"), "*.rb").should== true
47
+ end
48
+
49
+ it "will discover tabs in a file when a filename it passed (success)" do
50
+ DiscoverTabs.should_receive(:in_file).with(test_data("file_with_tabs.rb")).and_return(true)
51
+ DiscoverTabs.cmdline_run([ test_data("file_with_tabs.rb") ]).should== 0
52
+ end
53
+
54
+ it "will discover tabs in a dir when a directory it passed (failed)" do
55
+ DiscoverTabs.should_receive(:in_dir).with(test_data("dir_with_some_tabbed_files")).and_return(false)
56
+ DiscoverTabs.cmdline_run([ test_data("dir_with_some_tabbed_files") ]).should== 1
57
+ end
58
+
59
+ it "will discover a pattern (based on having an * in the filename) and it passes the pattern (success)" do
60
+ DiscoverTabs.should_receive(:in_dir).with(test_data("dir_with_some_tabbed_files"), "*").and_return(true)
61
+ DiscoverTabs.cmdline_run([ test_data("dir_with_some_tabbed_files/*") ]).should== 0
62
+ end
63
+
64
+ it "Defaults to the current dir" do
65
+ DiscoverTabs.should_receive(:in_dir).with(".").and_return(true)
66
+ DiscoverTabs.cmdline_run([])
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ require 'discover_tabs'
2
+
3
+ def test_data(filename)
4
+ File.join(File.dirname(__FILE__), "test_data", filename)
5
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class SomeClass
3
+ def tabbed method
4
+
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ class SomeClass
4
+ def tabbed method
5
+
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class SomeClass
3
+ def tabbed method
4
+
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ class SomeClass
4
+ def tabbed method
5
+
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class SomeClass
3
+ def tabbed method
4
+
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ class SomeClass
4
+ def tabbed method
5
+
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class SomeClass
3
+ def tabbed method
4
+
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class SomeClass
3
+ def tabbed method
4
+
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ class SomeClass
4
+ def tabbed method
5
+
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ class SomeClass
4
+ def tabbed method
5
+
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ class SomeClass
4
+ def tabbed method
5
+
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class SomeClass
3
+ def tabbed method
4
+
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+
2
+
3
+ class SomeClass
4
+ def tabbed method
5
+
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discover_tabs
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ platform: ruby
6
+ authors:
7
+ - Bas Vodde
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ptools
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.0.0
61
+ description: Library and Command line for discovering files that contain tab indentation
62
+ email: basv@odd-e.com
63
+ executables:
64
+ - discover_tabs
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - Gemfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - bin/discover_tabs
73
+ - lib/discover_tabs.rb
74
+ - lib/version.rb
75
+ - spec/discover_tabs_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/test_data/dir_with_some_tabbed_files/1.rb
78
+ - spec/test_data/dir_with_some_tabbed_files/5.rb
79
+ - spec/test_data/dir_with_some_tabbed_files/8/1.rb
80
+ - spec/test_data/dir_with_some_tabbed_files/8/9.rb
81
+ - spec/test_data/dir_with_some_tabbed_files/dir/4.rb
82
+ - spec/test_data/dir_with_some_tabbed_files/file_without_tabs.rb
83
+ - spec/test_data/dir_with_some_tabbed_files_and_different_extensions/tabs.cpp
84
+ - spec/test_data/dir_with_some_tabbed_files_and_different_extensions/tabs.rb
85
+ - spec/test_data/dir_without_tabbed_files/3.rb
86
+ - spec/test_data/dir_without_tabbed_files/9.rb
87
+ - spec/test_data/dir_without_tabbed_files/file_without_tabs.rb
88
+ - spec/test_data/file_with_tabs.rb
89
+ - spec/test_data/file_without_tabs.rb
90
+ homepage: https://github.com/basvodde/discover_tabs
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Discover which files are tab indented
114
+ test_files: []