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.
@@ -1,3 +1,8 @@
1
+ == 1.0.1 2009-03-26
2
+
3
+ * New version
4
+ * 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.
5
+
1
6
  == 1.0.1 2009-03-25
2
7
 
3
8
  * New version
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module HeaderInserter
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  end
@@ -62,14 +62,15 @@ class ProjectFile
62
62
  end
63
63
 
64
64
  def add_header header, old_header = nil
65
- content = header
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
@@ -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 = "#{stupid_header}class A {}\n"
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.1
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-25 00:00:00 -03:00
12
+ date: 2009-03-26 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency