katana_stamp 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/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Guardfile +7 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/bin/katana_stamp +38 -0
- data/katana_stamp.gemspec +26 -0
- data/lib/katana_stamp.rb +43 -0
- data/lib/katana_stamp/stamp_file.rb +43 -0
- data/lib/katana_stamp/version.rb +3 -0
- data/spec/katana_stamp_spec.rb +104 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/templates/README.md +2 -0
- data/spec/templates/spec/support/test_dummy_file.rb +3 -0
- metadata +123 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Katana Code's Copyright Stamper
|
|
2
|
+
|
|
3
|
+
This gem is used internally by Katana Code. Feel free to fork it and modify for your
|
|
4
|
+
own organisation.
|
|
5
|
+
|
|
6
|
+
## Usage:
|
|
7
|
+
|
|
8
|
+
$ katana_stamp
|
|
9
|
+
|
|
10
|
+
adds **(c) Copyright 2012 Katana Code Ltd. All Rights Reserved.** to the end of every Ruby file under app/ and lib/.
|
|
11
|
+
|
|
12
|
+
See options below for configuration
|
|
13
|
+
|
|
14
|
+
## Options
|
|
15
|
+
|
|
16
|
+
### --include-dirs (-i)
|
|
17
|
+
|
|
18
|
+
Include these dir patterns in stamp list
|
|
19
|
+
e.g.
|
|
20
|
+
$ katana_stamp -i vendor/**/*.rb # will also stamp files matching vendor/**/*.rb
|
|
21
|
+
|
|
22
|
+
### --exclude-dirs (-x)
|
|
23
|
+
|
|
24
|
+
Don't include these dir patterns in stamp list
|
|
25
|
+
e.g.
|
|
26
|
+
|
|
27
|
+
$ katana_stamp -x app/controllers/application_controller.rb # will not stamp files matching app/controllers/application_controller.rb
|
|
28
|
+
|
|
29
|
+
### --year (-y)
|
|
30
|
+
|
|
31
|
+
Change the year of the Copyright
|
|
32
|
+
e.g.
|
|
33
|
+
|
|
34
|
+
$ katana_stamp -y 1999
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### --owner (-o)
|
|
38
|
+
|
|
39
|
+
Change the owner of the Copyright
|
|
40
|
+
e.g.
|
|
41
|
+
|
|
42
|
+
$ katana_stamp -o "Ace Rimmer!"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### --message (-m)
|
|
46
|
+
|
|
47
|
+
Overwrite the entire message for the stamp.
|
|
48
|
+
e.g.
|
|
49
|
+
|
|
50
|
+
$ katana_stamp -m "Released under the MIT license"
|
|
51
|
+
|
|
52
|
+
## Known Issues
|
|
53
|
+
|
|
54
|
+
At the moment there's no way to reverse this... make sure you commit any changes before you
|
|
55
|
+
run this!
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/katana_stamp
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
5
|
+
|
|
6
|
+
require 'katana_stamp'
|
|
7
|
+
require 'optparse'
|
|
8
|
+
|
|
9
|
+
options = {}
|
|
10
|
+
|
|
11
|
+
OptionParser.new do |opts|
|
|
12
|
+
opts.banner = "Katana Stamp Usage:"
|
|
13
|
+
|
|
14
|
+
opts.on("-i", "--include-dirs x,y,x", Array,
|
|
15
|
+
"Include these dir patterns in stamp list") do |v|
|
|
16
|
+
options[:include_paths] = v
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
opts.on("-x", "--exclude-dirs x,y,x", Array,
|
|
20
|
+
"Don't include these dir patterns in stamp list") do |v|
|
|
21
|
+
options[:exclude_paths] = v
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
opts.on("-y", "--year YEAR", "Year of Copyright") do |v|
|
|
25
|
+
options[:year] = v
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
opts.on("-o", "--owner OWNER", "Copyright owner") do |v|
|
|
29
|
+
options[:owner] = v
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
opts.on("-m", "--message MESSAGE", "Overwrite the entire message.") do |v|
|
|
33
|
+
options[:message] = v
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end.parse!
|
|
37
|
+
|
|
38
|
+
exit(KatanaStamp.run!(options))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "katana_stamp/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "katana_stamp"
|
|
7
|
+
s.version = KatanaStamp::VERSION
|
|
8
|
+
s.authors = ["Bodacious"]
|
|
9
|
+
s.email = ["bodacious@katanacode.com"]
|
|
10
|
+
s.homepage = ""
|
|
11
|
+
s.summary = %q{A copyright stamping gem}
|
|
12
|
+
s.description = %q{Adds copyright comments to .rb files within a Ruby application}
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = "katana_stamp"
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
|
+
s.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
# specify any dependencies here; for example:
|
|
22
|
+
s.add_development_dependency "rspec"
|
|
23
|
+
s.add_development_dependency "activesupport"
|
|
24
|
+
s.add_development_dependency 'guard-rspec'
|
|
25
|
+
s.add_development_dependency 'rake'
|
|
26
|
+
end
|
data/lib/katana_stamp.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module KatanaStamp
|
|
2
|
+
|
|
3
|
+
require 'katana_stamp/stamp_file'
|
|
4
|
+
|
|
5
|
+
DIR_PATTERS = [ "app/**/*.rb", "lib/**/*.rb" ]
|
|
6
|
+
|
|
7
|
+
# Stamps all files matching DIR_PATTERNS and the +--include-paths+ option unless they have
|
|
8
|
+
# already been stamped
|
|
9
|
+
def run!(options={})
|
|
10
|
+
options[:exclude_paths] ||= []
|
|
11
|
+
options[:include_paths].each do |path|
|
|
12
|
+
DIR_PATTERS << path
|
|
13
|
+
end if options[:include_paths]
|
|
14
|
+
|
|
15
|
+
DIR_PATTERS.each do |main_dir|
|
|
16
|
+
Dir.glob(main_dir).each do |path|
|
|
17
|
+
next if options[:exclude_paths].detect { |pattern| File.fnmatch(pattern, path) }
|
|
18
|
+
custom_file = StampFile.new(path, options)
|
|
19
|
+
if custom_file.has_stamp?
|
|
20
|
+
print_colour("#{path} already stamped!", :yellow)
|
|
21
|
+
else
|
|
22
|
+
print_colour("#{path} stamped!", :green)
|
|
23
|
+
custom_file.stamp
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
true # return true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.print_colour(message, colour)
|
|
31
|
+
colour_id =
|
|
32
|
+
case colour
|
|
33
|
+
when :yellow then 33
|
|
34
|
+
when :green then 32
|
|
35
|
+
else
|
|
36
|
+
37 # white
|
|
37
|
+
end
|
|
38
|
+
puts "\033[0;#{colour_id}m#{message}\033[0m"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
module_function :run!
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module KatanaStamp
|
|
2
|
+
class StampFile < Struct.new(:path, :options)
|
|
3
|
+
|
|
4
|
+
# The default message stamped to each file.
|
|
5
|
+
# The %s are placeholders for _year_ and _owner_ respectively
|
|
6
|
+
COPYRIGHT_NOTICE = "(c) Copyright %s %s. All Rights Reserved."
|
|
7
|
+
|
|
8
|
+
# When called, will add a copyright notice comment to the end of the file
|
|
9
|
+
# with path
|
|
10
|
+
def stamp
|
|
11
|
+
`echo "#{"\n" unless has_closing_break?}# #{message}" >> #{path}`
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Does the file already have a copyright stamp?
|
|
15
|
+
def has_stamp?
|
|
16
|
+
File.open(path, "r") { |file| file.read.scan(message).any? }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# The message to be stamped to each file
|
|
20
|
+
# defaults to: COPYRIGHT_NOTICE
|
|
21
|
+
def message
|
|
22
|
+
options[:year] ||= Time.now.year
|
|
23
|
+
options[:owner] ||= 'Katana Code Ltd'
|
|
24
|
+
message = options[:message] || COPYRIGHT_NOTICE % [options[:year], options[:owner]]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def has_closing_break?
|
|
31
|
+
last_char == "\n"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def last_char
|
|
35
|
+
last_line[-1] if last_line
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def last_line
|
|
39
|
+
IO.readlines(path)[-1]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
include ActiveSupport::Inflector
|
|
3
|
+
|
|
4
|
+
describe KatanaStamp do
|
|
5
|
+
|
|
6
|
+
DEFAULT_STAMP = '# (c) Copyright 2012 Katana Code Ltd. All Rights Reserved'
|
|
7
|
+
|
|
8
|
+
before(:each) do
|
|
9
|
+
copy_template_files
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after(:all) do
|
|
13
|
+
copy_template_files
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:file_content) { File.read("app/models/test_model_one.rb") }
|
|
17
|
+
|
|
18
|
+
context "by default" do
|
|
19
|
+
|
|
20
|
+
before do
|
|
21
|
+
run_with_options
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'adds the copyright notice to the bottom of the file if not present' do
|
|
25
|
+
file_content.should include(DEFAULT_STAMP)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "doesn't add the copyright notice again if it's already there" do
|
|
29
|
+
run_with_options # again
|
|
30
|
+
file_content.scan(DEFAULT_STAMP).count.should eql(1)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "doesn't modify non-ruby files" do
|
|
34
|
+
File.read('app/models/README').should_not include("# (c) Copyright")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context 'with owner option' do
|
|
40
|
+
|
|
41
|
+
it 'uses the owner passed' do
|
|
42
|
+
run_with_options(owner: 'Bodacious')
|
|
43
|
+
file_content.should include('Bodacious')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context 'with year option' do
|
|
49
|
+
|
|
50
|
+
it 'uses the year passed' do
|
|
51
|
+
run_with_options(year: '1999')
|
|
52
|
+
file_content.should include('1999')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context 'with include-dirs option' do
|
|
58
|
+
|
|
59
|
+
let(:path) { 'spec/support/test_dummy_file.rb' }
|
|
60
|
+
|
|
61
|
+
before do
|
|
62
|
+
run_with_options(include_paths: [path])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "also stamps paths listed in include_paths" do
|
|
66
|
+
File.read(path).should include(DEFAULT_STAMP)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'with exclude-dirs option' do
|
|
72
|
+
|
|
73
|
+
let(:path) { 'app/models/test_model_two.rb' }
|
|
74
|
+
|
|
75
|
+
before do
|
|
76
|
+
run_with_options(exclude_paths: [path])
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "doesn't stamp paths listed in exclude_paths" do
|
|
80
|
+
File.read(path).should_not include(DEFAULT_STAMP)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "it still stamps files that don't match the pattern" do
|
|
84
|
+
file_content.should include(DEFAULT_STAMP)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'with message option' do
|
|
90
|
+
|
|
91
|
+
let(:message) { "Released under the Bodacious license" }
|
|
92
|
+
|
|
93
|
+
before do
|
|
94
|
+
run_with_options(message: message)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "overwrites the entire message" do
|
|
98
|
+
file_content.should include(message)
|
|
99
|
+
file_content.should_not include(DEFAULT_STAMP)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "katana_stamp"
|
|
2
|
+
require "active_support"
|
|
3
|
+
|
|
4
|
+
def copy_template_files
|
|
5
|
+
FileUtils.cp_r(Dir.glob("#{File.dirname(__FILE__)}/templates/*"), ".")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def run_with_options(options = {})
|
|
9
|
+
options[:exclude_paths] ||= []
|
|
10
|
+
# we don't want to stamp files from this Gem's libraries
|
|
11
|
+
# each time we test
|
|
12
|
+
options[:exclude_paths] << "lib/katana_stamp.rb"
|
|
13
|
+
options[:exclude_paths] << "lib/katana_stamp/*.rb"
|
|
14
|
+
KatanaStamp.run!(options)
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: katana_stamp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Bodacious
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-01-28 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: &70113106504500 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70113106504500
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: activesupport
|
|
27
|
+
requirement: &70113106504080 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70113106504080
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: guard-rspec
|
|
38
|
+
requirement: &70113106503660 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
type: :development
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *70113106503660
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: rake
|
|
49
|
+
requirement: &70113106503240 !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: *70113106503240
|
|
58
|
+
description: Adds copyright comments to .rb files within a Ruby application
|
|
59
|
+
email:
|
|
60
|
+
- bodacious@katanacode.com
|
|
61
|
+
executables:
|
|
62
|
+
- katana_stamp
|
|
63
|
+
extensions: []
|
|
64
|
+
extra_rdoc_files: []
|
|
65
|
+
files:
|
|
66
|
+
- .gitignore
|
|
67
|
+
- Gemfile
|
|
68
|
+
- Guardfile
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- app/models/README
|
|
72
|
+
- app/models/test_model_one.rb
|
|
73
|
+
- app/models/test_model_two.rb
|
|
74
|
+
- bin/katana_stamp
|
|
75
|
+
- katana_stamp.gemspec
|
|
76
|
+
- lib/katana_stamp.rb
|
|
77
|
+
- lib/katana_stamp/stamp_file.rb
|
|
78
|
+
- lib/katana_stamp/version.rb
|
|
79
|
+
- spec/katana_stamp_spec.rb
|
|
80
|
+
- spec/spec_helper.rb
|
|
81
|
+
- spec/support/test_dummy_file.rb
|
|
82
|
+
- spec/templates/README.md
|
|
83
|
+
- spec/templates/app/models/test_model_one.rb
|
|
84
|
+
- spec/templates/app/models/test_model_two.rb
|
|
85
|
+
- spec/templates/spec/support/test_dummy_file.rb
|
|
86
|
+
homepage: ''
|
|
87
|
+
licenses: []
|
|
88
|
+
post_install_message:
|
|
89
|
+
rdoc_options: []
|
|
90
|
+
require_paths:
|
|
91
|
+
- lib
|
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
|
+
none: false
|
|
94
|
+
requirements:
|
|
95
|
+
- - ! '>='
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
segments:
|
|
99
|
+
- 0
|
|
100
|
+
hash: -2004445586818876172
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
none: false
|
|
103
|
+
requirements:
|
|
104
|
+
- - ! '>='
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
segments:
|
|
108
|
+
- 0
|
|
109
|
+
hash: -2004445586818876172
|
|
110
|
+
requirements: []
|
|
111
|
+
rubyforge_project: katana_stamp
|
|
112
|
+
rubygems_version: 1.8.15
|
|
113
|
+
signing_key:
|
|
114
|
+
specification_version: 3
|
|
115
|
+
summary: A copyright stamping gem
|
|
116
|
+
test_files:
|
|
117
|
+
- spec/katana_stamp_spec.rb
|
|
118
|
+
- spec/spec_helper.rb
|
|
119
|
+
- spec/support/test_dummy_file.rb
|
|
120
|
+
- spec/templates/README.md
|
|
121
|
+
- spec/templates/app/models/test_model_one.rb
|
|
122
|
+
- spec/templates/app/models/test_model_two.rb
|
|
123
|
+
- spec/templates/spec/support/test_dummy_file.rb
|