header-inserter 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -1
- data/lib/header-inserter.rb +1 -1
- data/lib/header-inserter/project_file.rb +17 -3
- data/spec/project-file_spec.rb +12 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
== 1.0.
|
1
|
+
== 1.0.3 2009-03-27
|
2
|
+
|
3
|
+
* New version
|
4
|
+
* The replace of the old header should happen only once. If there are more comments around the code with a similar content, it is safer to let them there.
|
5
|
+
|
6
|
+
== 1.0.2 2009-03-26
|
2
7
|
|
3
8
|
* New version
|
4
9
|
* addHeader wasn't replacing the old header. Changed the behavior to do so. Also does not erase parts of the new header if they match the old header.
|
data/lib/header-inserter.rb
CHANGED
@@ -69,15 +69,29 @@ class ProjectFile
|
|
69
69
|
end
|
70
70
|
file.close
|
71
71
|
|
72
|
-
content
|
73
|
-
content = header + content
|
72
|
+
content = remove old_header, content
|
74
73
|
|
75
74
|
file = File.new absolute_path, "w"
|
76
|
-
file.puts content
|
75
|
+
file.puts(header + content)
|
77
76
|
file.close
|
78
77
|
end
|
79
78
|
|
80
79
|
protected
|
80
|
+
|
81
|
+
def remove old_header, content
|
82
|
+
replaced = false
|
83
|
+
unless old_header.nil?
|
84
|
+
content.gsub!(old_header) { |match|
|
85
|
+
if not replaced
|
86
|
+
replaced = true
|
87
|
+
""
|
88
|
+
else
|
89
|
+
match
|
90
|
+
end
|
91
|
+
}
|
92
|
+
end
|
93
|
+
content
|
94
|
+
end
|
81
95
|
|
82
96
|
def modifications
|
83
97
|
@mods = version_control.history path if @mods.nil?
|
data/spec/project-file_spec.rb
CHANGED
@@ -191,6 +191,18 @@ describe ProjectFile do
|
|
191
191
|
read_content(file.absolute_path).should == new_header + content
|
192
192
|
end
|
193
193
|
|
194
|
+
it "should add a header at the beginning of the file and remove the one specified even if a part matches only once" do
|
195
|
+
new_header = "/**\n * My fine header.\n * It has the date (2009-03-24, 21:43:58) and the first contributor (hugo).\n * And ends like nothing\n */\n/** A stupid header */\n\n"
|
196
|
+
stupid_header = "/** A stupid header */\n\n"
|
197
|
+
content = "class A {}\n"
|
198
|
+
|
199
|
+
file = ProjectFile.new @project, "A.java"
|
200
|
+
create_file file.absolute_path, stupid_header + content + stupid_header
|
201
|
+
file.add_header(new_header, stupid_header)
|
202
|
+
|
203
|
+
read_content(file.absolute_path).should == new_header + content + stupid_header
|
204
|
+
end
|
205
|
+
|
194
206
|
after(:each) do
|
195
207
|
FileUtils.rm_rf @project.path
|
196
208
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: header-inserter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FIXME full name
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-27 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|