header-inserter 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/header-inserter.rb +1 -1
- data/lib/header-inserter/project_file.rb +3 -2
- data/spec/project-file_spec.rb +14 -3
- metadata +2 -2
data/History.txt
CHANGED
data/lib/header-inserter.rb
CHANGED
@@ -62,14 +62,15 @@ class ProjectFile
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def add_header header, old_header = nil
|
65
|
-
content =
|
65
|
+
content = ""
|
66
66
|
file = File.new absolute_path, "r"
|
67
67
|
file.each do |line|
|
68
68
|
content += line
|
69
69
|
end
|
70
70
|
file.close
|
71
71
|
|
72
|
-
content.gsub(old_header, "") unless old_header.nil?
|
72
|
+
content.gsub!(old_header, "") unless old_header.nil?
|
73
|
+
content = header + content
|
73
74
|
|
74
75
|
file = File.new absolute_path, "w"
|
75
76
|
file.puts content
|
data/spec/project-file_spec.rb
CHANGED
@@ -170,10 +170,22 @@ describe ProjectFile do
|
|
170
170
|
it "should add a header at the beginning of the file and remove the one specified" do
|
171
171
|
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\n"
|
172
172
|
stupid_header = "/** A stupid header */\n\n"
|
173
|
-
content = "
|
173
|
+
content = "class A {}\n"
|
174
174
|
|
175
175
|
file = ProjectFile.new @project, "A.java"
|
176
|
-
create_file file.absolute_path, content
|
176
|
+
create_file file.absolute_path, stupid_header + content
|
177
|
+
file.add_header(new_header, stupid_header)
|
178
|
+
|
179
|
+
read_content(file.absolute_path).should == new_header + content
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should add a header at the beginning of the file and remove the one specified even if a part matches" do
|
183
|
+
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"
|
184
|
+
stupid_header = "/** A stupid header */\n\n"
|
185
|
+
content = "class A {}\n"
|
186
|
+
|
187
|
+
file = ProjectFile.new @project, "A.java"
|
188
|
+
create_file file.absolute_path, stupid_header + content
|
177
189
|
file.add_header(new_header, stupid_header)
|
178
190
|
|
179
191
|
read_content(file.absolute_path).should == new_header + content
|
@@ -185,7 +197,6 @@ describe ProjectFile do
|
|
185
197
|
|
186
198
|
protected
|
187
199
|
|
188
|
-
|
189
200
|
def create_file absolute_path, content
|
190
201
|
File.makedirs File.dirname(absolute_path)
|
191
202
|
file = File.new absolute_path, "w"
|
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.2
|
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-26 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|