sugar-high 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -2,6 +2,7 @@ require 'sugar-high/blank'
2
2
  require 'sugar-high/arguments'
3
3
  require 'sugar-high/path'
4
4
  require 'sugar-high/regexp'
5
+ require 'sugar-high/string'
5
6
 
6
7
  class File
7
8
  def self.delete! name
@@ -126,10 +127,13 @@ class File
126
127
  return nil if content.blank? || (file.read =~ /#{content}/)
127
128
 
128
129
  place, marker = if options[:before]
129
- [ :before, options[:before] ]
130
+ [ :before, options[:before] ]
131
+ elsif options[:before_last]
132
+ [ :before_last, options[:before_last] ]
130
133
  else
131
- [ :after, options[:after] ]
134
+ [ :after, options[:after] ]
132
135
  end
136
+
133
137
 
134
138
  marker = Insert.get_marker marker
135
139
 
@@ -165,8 +169,15 @@ class File
165
169
 
166
170
  module Mutate
167
171
  def self.mutate_file file, marker, place, &block
168
- raise ArgumentError, "You must define a replacement marker for a :before or :after key" if !marker
169
-
172
+ raise ArgumentError, "You must define a replacement marker for a :before, :before_last or :after key" if !marker
173
+
174
+ if place == :before_last
175
+ content = File.read(file)
176
+ content = content.insert_before_last yield, marker
177
+ File.open(file, 'wb') { |file| file.write(content) }
178
+ return
179
+ end
180
+
170
181
  replace_in_file file, /(#{marker})/mi do |match|
171
182
  place == :after ? "#{match}\n #{yield}" : "#{yield}\n #{match}"
172
183
  end
@@ -0,0 +1,6 @@
1
+ class Abc
2
+ def begin
3
+ end
4
+
5
+ end
6
+
@@ -4,6 +4,7 @@ require 'sugar-high/file'
4
4
  describe "SugarHigh::File" do
5
5
  let(:empty_file) { fixture_file 'empty.txt' }
6
6
  let(:non_empty_file) { fixture_file 'non-empty.txt'}
7
+ let(:class_file) { fixture_file 'class_file.rb'}
7
8
  let(:replace_file) { fixture_file 'file.txt' }
8
9
 
9
10
  before :each do
@@ -145,5 +146,12 @@ describe "SugarHigh::File" do
145
146
  File.insert_into insertion_file, :content => ' Hello', :after => /Goodbye/
146
147
  File.read(insertion_file).should match /Goodbye\s+Hello/
147
148
  end
149
+
150
+ it "should insert Hello before last end statement" do
151
+ File.insert_into class_file, :content => ' # Hello', :before_last => 'end'
152
+ puts File.read(class_file)
153
+ File.read(class_file).should match /end\s+# Hello\s+end/
154
+ File.remove_content_from class_file, :content => ' # Hello'
155
+ end
148
156
  end
149
157
  end
data/sugar-high.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  "lib/sugar-high/rspec/configure.rb",
42
42
  "lib/sugar-high/rspec/matchers/have_aliases.rb",
43
43
  "lib/sugar-high/string.rb",
44
+ "spec/fixtures/class_file.rb",
44
45
  "spec/fixtures/empty.txt",
45
46
  "spec/fixtures/non-empty.txt",
46
47
  "spec/spec_helper.rb",
@@ -65,6 +66,7 @@ Gem::Specification.new do |s|
65
66
  s.rubygems_version = %q{1.3.7}
66
67
  s.summary = %q{Ruby convenience sugar packs!}
67
68
  s.test_files = [
69
+ "spec/fixtures/class_file.rb",
68
70
  "spec/spec_helper.rb",
69
71
  "spec/sugar-high/alias_spec.rb",
70
72
  "spec/sugar-high/arguments_spec.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -96,6 +96,7 @@ files:
96
96
  - lib/sugar-high/rspec/configure.rb
97
97
  - lib/sugar-high/rspec/matchers/have_aliases.rb
98
98
  - lib/sugar-high/string.rb
99
+ - spec/fixtures/class_file.rb
99
100
  - spec/fixtures/empty.txt
100
101
  - spec/fixtures/non-empty.txt
101
102
  - spec/spec_helper.rb
@@ -147,6 +148,7 @@ signing_key:
147
148
  specification_version: 3
148
149
  summary: Ruby convenience sugar packs!
149
150
  test_files:
151
+ - spec/fixtures/class_file.rb
150
152
  - spec/spec_helper.rb
151
153
  - spec/sugar-high/alias_spec.rb
152
154
  - spec/sugar-high/arguments_spec.rb