mcc 0.1.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bin/mcc +6 -0
- data/lib/mcc.rb +50 -0
- data/spec/fixtures/with_magick_comment.rb +5 -0
- data/spec/fixtures/with_shebang_and_magick_comment.rb +6 -0
- data/spec/fixtures/without_magick_comment.rb +4 -0
- data/spec/fixtures/without_shebung_and_magick_comment.rb +3 -0
- data/spec/mcc_spec.rb +50 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +102 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kuniaki IGARASHI
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= mcc
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Kuniaki IGARASHI. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "mcc"
|
8
|
+
gem.summary = %Q{Magic Comment Checker}
|
9
|
+
gem.description = %Q{It provides command "mcc" for check a magic comment. }
|
10
|
+
gem.email = "igaiga@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/igaiga/mcc"
|
12
|
+
gem.authors = ["Kuniaki IGARASHI"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "mcc #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/mcc
ADDED
data/lib/mcc.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module MCC
|
7
|
+
RE = /^#.*coding.*:.*$/
|
8
|
+
|
9
|
+
def self.run(files, format = '# coding: utf-8')
|
10
|
+
files.each do |file|
|
11
|
+
unless include_magick_comment?(file)
|
12
|
+
insert_magick_comment(file, format)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.include_magick_comment?(file)
|
18
|
+
File.open(file) do |f|
|
19
|
+
2.times do
|
20
|
+
f.readline =~ RE and return true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.insert_magick_comment(file, magick_comment)
|
27
|
+
include_shebang = include_shebang?(file)
|
28
|
+
|
29
|
+
tmp = Tempfile.open(File.basename(file))
|
30
|
+
File.open(file) do |f|
|
31
|
+
tmp.puts f.readline if include_shebang
|
32
|
+
tmp.puts magick_comment
|
33
|
+
|
34
|
+
f.each do |line|
|
35
|
+
tmp.puts line
|
36
|
+
end
|
37
|
+
end
|
38
|
+
tmp.flush
|
39
|
+
|
40
|
+
FileUtils.cp(tmp, file)
|
41
|
+
ensure
|
42
|
+
tmp.close
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.include_shebang?(file)
|
46
|
+
File.open(file) do |f|
|
47
|
+
return !!(f.readline =~ /^#!/)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/mcc_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "Mcc" do
|
5
|
+
it "should run" do
|
6
|
+
MCC.should_receive(:include_magick_comment?).with('foo.rb')
|
7
|
+
MCC.should_receive(:include_magick_comment?).with('bar.rb')
|
8
|
+
MCC.should_receive(:insert_magick_comment).with('foo.rb', '# encoding: utf-8')
|
9
|
+
MCC.should_receive(:insert_magick_comment).with('bar.rb', '# encoding: utf-8')
|
10
|
+
|
11
|
+
MCC.run(['foo.rb', 'bar.rb'], '# encoding: utf-8')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should check to include a magick comment' do
|
15
|
+
{
|
16
|
+
'with_magick_comment.rb' => true,
|
17
|
+
'without_magick_comment.rb' => false,
|
18
|
+
'with_shebang_and_magick_comment.rb' => true
|
19
|
+
}.each do |k, v|
|
20
|
+
MCC.include_magick_comment?(fixture_file(k)).should be v
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should insert a magick comment' do
|
25
|
+
{
|
26
|
+
'without_magick_comment.rb' => true,
|
27
|
+
'without_shebung_and_magick_comment.rb' => false
|
28
|
+
}.each do |file, include_shebang|
|
29
|
+
begin
|
30
|
+
tmp = Tempfile.open(file)
|
31
|
+
FileUtils.cp(fixture_file(file), tmp.path)
|
32
|
+
MCC.insert_magick_comment(tmp.path, '# encoding: utf-8')
|
33
|
+
|
34
|
+
MCC.include_magick_comment?(tmp.path).should be true
|
35
|
+
MCC.include_shebang?(tmp.path).should be include_shebang
|
36
|
+
ensure
|
37
|
+
tmp.close
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should check include a shebang' do
|
43
|
+
MCC.include_shebang?(fixture_file('with_shebang_and_magick_comment.rb')).should be true
|
44
|
+
MCC.include_shebang?(fixture_file('with_magick_comment.rb')).should be false
|
45
|
+
end
|
46
|
+
|
47
|
+
def fixture_file(filename)
|
48
|
+
File.join(File.dirname(__FILE__), 'fixtures', filename)
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mcc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kuniaki IGARASHI
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-10 00:00:00 +09:00
|
19
|
+
default_executable: mcc
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: "It provides command \"mcc\" for check a magic comment. "
|
38
|
+
email: igaiga@gmail.com
|
39
|
+
executables:
|
40
|
+
- mcc
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- bin/mcc
|
54
|
+
- lib/mcc.rb
|
55
|
+
- spec/fixtures/with_magick_comment.rb
|
56
|
+
- spec/fixtures/with_shebang_and_magick_comment.rb
|
57
|
+
- spec/fixtures/without_magick_comment.rb
|
58
|
+
- spec/fixtures/without_shebung_and_magick_comment.rb
|
59
|
+
- spec/mcc_spec.rb
|
60
|
+
- spec/spec.opts
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://github.com/igaiga/mcc
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --charset=UTF-8
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.7
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Magic Comment Checker
|
96
|
+
test_files:
|
97
|
+
- spec/fixtures/with_magick_comment.rb
|
98
|
+
- spec/fixtures/with_shebang_and_magick_comment.rb
|
99
|
+
- spec/fixtures/without_magick_comment.rb
|
100
|
+
- spec/fixtures/without_shebung_and_magick_comment.rb
|
101
|
+
- spec/mcc_spec.rb
|
102
|
+
- spec/spec_helper.rb
|