sugar-high 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -29
- data/VERSION +1 -1
- data/lib/sugar-high/class_ext.rb +2 -133
- data/lib/sugar-high/file.rb +10 -11
- data/lib/sugar-high/file_ext.rb +13 -11
- data/lib/sugar-high/rails/concerns.rb +10 -4
- data/spec/sugar-high/file_spec.rb +26 -28
- data/spec/sugar-high/rails/concerns_spec.rb +31 -1
- data/spec/sugar-high/rails/fixture_user/scopes.rb +4 -0
- data/spec/sugar-high/rails/fixture_user/validations.rb +4 -0
- data/spec/sugar-high/rails/shared/associations.rb +1 -0
- data/spec/sugar-high/rails/shared/caching.rb +4 -0
- data/sugar-high.gemspec +6 -42
- metadata +19 -55
- data/lib/sugar-high/file_mutate.rb +0 -2
- data/lib/sugar-high/file_mutate/append_content.rb +0 -17
- data/lib/sugar-high/file_mutate/delete.rb +0 -29
- data/lib/sugar-high/file_mutate/insert_content.rb +0 -62
- data/lib/sugar-high/file_mutate/mutate.rb +0 -57
- data/lib/sugar-high/file_mutate/overwrite_content.rb +0 -17
- data/lib/sugar-high/file_mutate/remove_content.rb +0 -33
- data/lib/sugar-high/file_mutate/replace_content.rb +0 -45
- data/lib/sugar-high/file_mutation.rb +0 -58
- data/sandbox/test_routes_mutate.rb +0 -8
- data/spec/auto_load_blank_root.rb +0 -3
- data/spec/autoload_blank_root.rb +0 -3
- data/spec/autoload_blank_root/hello.rb +0 -6
- data/spec/autoload_blank_root/sailor.rb +0 -7
- data/spec/fixtures/application_file.rb +0 -6
- data/spec/fixtures/autoload_modules.rb +0 -3
- data/spec/fixtures/autoload_modules/subdir/first.rb +0 -7
- data/spec/fixtures/autoload_modules/subdir/second.rb +0 -5
- data/spec/fixtures/autoload_modules/subdir/third.rb +0 -4
- data/spec/fixtures/autoload_modules_root.rb +0 -3
- data/spec/fixtures/autoload_modules_root/first.rb +0 -7
- data/spec/fixtures/autoload_modules_root/second.rb +0 -4
- data/spec/fixtures/autoload_modules_root/third.rb +0 -7
- data/spec/fixtures/autoload_modulez.rb +0 -4
- data/spec/fixtures/autoload_modulez/first.rb +0 -7
- data/spec/fixtures/autoload_modulez/second.rb +0 -5
- data/spec/fixtures/autoload_modulez/third_one_here.rb +0 -4
- data/spec/fixtures/class_file.rb +0 -22
- data/spec/fixtures/class_file.txt +0 -0
- data/spec/fixtures/content_file.txt +0 -1
- data/spec/fixtures/routes_file.rb +0 -85
- data/spec/sugar-high/class_ext_spec.rb +0 -189
- data/spec/sugar-high/file/file_dsl_spec.rb +0 -4
- data/spec/sugar-high/file_mutate/append_content_spec.rb +0 -61
- data/spec/sugar-high/file_mutate/delete_spec.rb +0 -47
- data/spec/sugar-high/file_mutate/insert_before_last_spec.rb +0 -56
- data/spec/sugar-high/file_mutate/insert_content_spec.rb +0 -111
- data/spec/sugar-high/file_mutate/overwrite_content_spec.rb +0 -80
- data/spec/sugar-high/file_mutate/remove_content_spec.rb +0 -109
- data/spec/sugar-high/file_mutate/replace_content_spec.rb +0 -33
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sugar-high/file'
|
3
|
-
require 'sugar-high/file_mutate'
|
4
|
-
File.mutate_ext :all
|
5
|
-
|
6
|
-
describe "SugarHigh::File" do
|
7
|
-
let(:empty_file) { fixture_file 'empty.txt' }
|
8
|
-
let(:replace_file) { fixture_file 'file.txt' }
|
9
|
-
|
10
|
-
describe '#append with :content option' do
|
11
|
-
let(:append_file) { fixture_file 'file.txt' }
|
12
|
-
|
13
|
-
it 'should append content to existing file - class method' do
|
14
|
-
File.overwrite(append_file) do
|
15
|
-
'Hello You'
|
16
|
-
end
|
17
|
-
File.append append_file, :content => 'Appended'
|
18
|
-
content = File.read(append_file)
|
19
|
-
content.should match /Hello You/
|
20
|
-
content.should match /Appended/
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should append content to existing file - instance method' do
|
24
|
-
File.overwrite(append_file) do
|
25
|
-
'Hello You'
|
26
|
-
end
|
27
|
-
File.new(append_file).append :content => 'Appended'
|
28
|
-
content = File.read(append_file)
|
29
|
-
content.should match /Hello You/
|
30
|
-
content.should match /Appended/
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#append with block' do
|
35
|
-
let(:append_file) { fixture_file 'file.txt' }
|
36
|
-
|
37
|
-
it "should append content to existing file using block arg - class method" do
|
38
|
-
File.overwrite(append_file) do
|
39
|
-
'Hello You'
|
40
|
-
end
|
41
|
-
File.append append_file do
|
42
|
-
'Appended'
|
43
|
-
end
|
44
|
-
content = File.read(replace_file)
|
45
|
-
content.should match /Hello You/
|
46
|
-
content.should match /Appended/
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should append content to existing file using block arg - instance method" do
|
50
|
-
File.overwrite(append_file) do
|
51
|
-
'Hello You'
|
52
|
-
end
|
53
|
-
File.new(append_file).append do
|
54
|
-
'Appended'
|
55
|
-
end
|
56
|
-
content = File.read(replace_file)
|
57
|
-
content.should match /Hello You/
|
58
|
-
content.should match /Appended/
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sugar-high/file_mutate'
|
3
|
-
File.mutate_ext :all
|
4
|
-
|
5
|
-
describe "SugarHigh::File" do
|
6
|
-
let(:file_to_delete) { fixture_file 'file_to_delete.txt' }
|
7
|
-
|
8
|
-
describe '#delete! (class)' do
|
9
|
-
it 'should delete file' do
|
10
|
-
File.overwrite(file_to_delete) do
|
11
|
-
'Delete this!'
|
12
|
-
end
|
13
|
-
File.delete! file_to_delete
|
14
|
-
File.exist?(file_to_delete).should be_false
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#delete_file! (class)' do
|
19
|
-
it 'should delete file' do
|
20
|
-
File.overwrite(file_to_delete) do
|
21
|
-
'Delete this!'
|
22
|
-
end
|
23
|
-
File.delete_file! file_to_delete
|
24
|
-
File.exist?(file_to_delete).should be_false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#delete! (instance)' do
|
29
|
-
it 'should delete file' do
|
30
|
-
File.overwrite(file_to_delete) do
|
31
|
-
'Delete this!'
|
32
|
-
end
|
33
|
-
File.new(file_to_delete).delete!
|
34
|
-
File.exist?(file_to_delete).should be_false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#delete_file! (instance)' do
|
39
|
-
it 'should delete file' do
|
40
|
-
File.overwrite(file_to_delete) do
|
41
|
-
'Delete this!'
|
42
|
-
end
|
43
|
-
File.new(file_to_delete).delete_file!
|
44
|
-
File.exist?(file_to_delete).should be_false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sugar-high/file_mutate'
|
3
|
-
File.mutate_ext :all
|
4
|
-
|
5
|
-
describe "Insert content" do
|
6
|
-
let(:empty_file) { fixture_file 'empty.txt' }
|
7
|
-
let(:class_file) { fixture_file 'class_file.rb'}
|
8
|
-
let(:routes_file) { fixture_file 'routes_file.rb' }
|
9
|
-
let(:app_file) { fixture_file 'application_file.rb' }
|
10
|
-
|
11
|
-
describe '#insert_into' do
|
12
|
-
let(:insertion_file) { fixture_file 'insertion.txt' }
|
13
|
-
|
14
|
-
before :each do
|
15
|
-
File.overwrite(insertion_file) do
|
16
|
-
'Goodbye'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
after :each do
|
21
|
-
File.delete insertion_file if File.file?(insertion_file)
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
describe '#insert before last' do
|
26
|
-
context ':content option and :before_last option' do
|
27
|
-
it "should insert Hello before last end statement" do
|
28
|
-
File.insert_into class_file, :content => ' # Hello', :before_last => 'end'
|
29
|
-
puts File.read(class_file)
|
30
|
-
File.read(class_file).should match /end\s+# Hello\s+end/
|
31
|
-
File.remove_content_from class_file, :content => ' # Hello'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context ':content option and :before_last option and repeat=true' do
|
36
|
-
it "should insert Hello before last end statement but don't repeat" do
|
37
|
-
File.insert_into class_file, :content => ' # Hello', :before_last => 'end', :no_repeat => true
|
38
|
-
puts File.read(class_file)
|
39
|
-
File.read(class_file).should match /end\s+# Hello\s+end/
|
40
|
-
File.remove_content_from class_file, :content => ' # Hello'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'block content and :before_last' do
|
45
|
-
it "should insert Hello before last end statement" do
|
46
|
-
File.insert_into class_file, :before_last => 'end' do
|
47
|
-
' # Hello'
|
48
|
-
end
|
49
|
-
puts File.read(class_file)
|
50
|
-
File.read(class_file).should match /end\s+# Hello\s+end/
|
51
|
-
File.remove_content_from class_file, :content => ' # Hello'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sugar-high/file_mutate'
|
3
|
-
File.mutate_ext :all
|
4
|
-
|
5
|
-
describe "Insert content" do
|
6
|
-
let(:empty_file) { fixture_file 'empty.txt' }
|
7
|
-
let(:class_file) { fixture_file 'class_file.rb'}
|
8
|
-
let(:routes_file) { fixture_file 'routes_file.rb' }
|
9
|
-
let(:app_file) { fixture_file 'application_file.rb' }
|
10
|
-
|
11
|
-
describe '#insert_into' do
|
12
|
-
let(:insertion_file) { fixture_file 'insertion.txt' }
|
13
|
-
|
14
|
-
before :each do
|
15
|
-
File.overwrite(insertion_file) do
|
16
|
-
'Goodbye'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
after :each do
|
21
|
-
File.delete insertion_file if File.file?(insertion_file)
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'File object as target' do
|
25
|
-
it "should insert Hello before Goodbye" do
|
26
|
-
ins_file = File.new(insertion_file)
|
27
|
-
ins_file.read_content.should match /Goodbye/
|
28
|
-
|
29
|
-
ins_file.has_content?('Goodbye').should be_true
|
30
|
-
|
31
|
-
File.insert_into ins_file, :before => 'Goodbye' do
|
32
|
-
'Hello'
|
33
|
-
end
|
34
|
-
ins_file.read_content.should match /Hello\s+Goodbye/
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'content as block argument' do
|
38
|
-
it "should insert Hello before Goodbye" do
|
39
|
-
File.insert_into insertion_file, :before => 'Goodbye' do
|
40
|
-
'Hello'
|
41
|
-
end
|
42
|
-
File.read(insertion_file).should match /Hello\s+Goodbye/
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#insert instance method' do
|
48
|
-
context 'content as block argument' do
|
49
|
-
it "should insert Hello before Goodbye" do
|
50
|
-
File.new(insertion_file).insert :before => 'Goodbye' do
|
51
|
-
'Hello'
|
52
|
-
end
|
53
|
-
File.read(insertion_file).should match /Hello\s+Goodbye/
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'content as String argument' do
|
58
|
-
it "should insert Hello before Goodbye using a content string arg" do
|
59
|
-
File.insert_into insertion_file, "Hello ", :before => 'Goodbye'
|
60
|
-
File.read(insertion_file).should match /Hello\s+Goodbye/
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'using a :content option' do
|
65
|
-
it "should insert Hello before Goodbye" do
|
66
|
-
File.insert_into insertion_file, :content => 'Hello', :before => 'Goodbye'
|
67
|
-
File.read(insertion_file).should match /Hello\s+Goodbye/
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'insert after' do
|
72
|
-
context 'Regexp for the :after expression' do
|
73
|
-
it "should insert Hello after Goodbye using a :content option" do
|
74
|
-
File.insert_into insertion_file, :content => ' Hello', :after => /Goodbye/
|
75
|
-
File.read(insertion_file).should match /Goodbye\s+Hello/
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should work with an escaped Regexp matching" do
|
79
|
-
pattern = Regexp.escape('::Application.initialize!')
|
80
|
-
File.insert_into app_file, :after => /\w+#{pattern}/ do
|
81
|
-
'hello'
|
82
|
-
end
|
83
|
-
File.read(app_file).should match /hello/
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'routes file - String path' do
|
90
|
-
it "should insert devise routes statement as first route statement" do
|
91
|
-
File.insert_into routes_file, :after => 'routes.draw do' do
|
92
|
-
'devise :users'
|
93
|
-
end
|
94
|
-
# puts File.read(routes_file)
|
95
|
-
File.read(routes_file).should match /routes.draw\s+do\s+devise :users/
|
96
|
-
File.remove_content_from routes_file, :content => 'devise :users'
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'routes file - File obj' do
|
101
|
-
it "should insert devise routes statement as first route statement" do
|
102
|
-
File.insert_into File.new(routes_file), :after => 'routes.draw do' do
|
103
|
-
'devise :users'
|
104
|
-
end
|
105
|
-
# puts File.read(routes_file)
|
106
|
-
File.read(routes_file).should match /routes.draw\s+do\s+devise :users/
|
107
|
-
File.remove_content_from routes_file, :content => 'devise :users'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sugar-high/file_mutate'
|
3
|
-
File.mutate_ext :all
|
4
|
-
|
5
|
-
describe "Overwrite file" do
|
6
|
-
let(:empty_file) { fixture_file 'empty.txt' }
|
7
|
-
let(:non_empty_file) { fixture_file 'non-empty.txt' }
|
8
|
-
let(:content_file) { fixture_file 'content_file.txt' }
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
File.overwrite(content_file) do
|
12
|
-
'Goodbye'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'File #overwrite class method' do
|
17
|
-
describe '#overwrite with block arg' do
|
18
|
-
context 'empty file' do
|
19
|
-
let (:content) { 'Overwritten!!!' }
|
20
|
-
|
21
|
-
it 'should overwrite empty file' do
|
22
|
-
File.overwrite content_file do
|
23
|
-
content
|
24
|
-
end
|
25
|
-
cf = File.new(content_file)
|
26
|
-
cf.has_content?(content).should be_true
|
27
|
-
cf.delete!
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'non-empty file' do
|
32
|
-
let (:content) { 'Overwritten!!!' }
|
33
|
-
|
34
|
-
it 'should overwrite file content with new content, erasing the old' do
|
35
|
-
File.overwrite content_file do
|
36
|
-
content
|
37
|
-
end
|
38
|
-
|
39
|
-
new_content = "New content"
|
40
|
-
File.overwrite content_file do
|
41
|
-
new_content
|
42
|
-
end
|
43
|
-
|
44
|
-
cf = File.new(content_file)
|
45
|
-
cf.has_content?(content).should be_false
|
46
|
-
cf.has_content?(new_content).should be_true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#overwrite! (instance)' do
|
52
|
-
let (:content) { 'Overwritten!!!' }
|
53
|
-
|
54
|
-
describe '#overwrite with block argument' do
|
55
|
-
it 'should overwrite empty file' do
|
56
|
-
cf = File.new(content_file)
|
57
|
-
cf.overwrite do
|
58
|
-
content
|
59
|
-
end
|
60
|
-
cf.has_content?(content).should be_true
|
61
|
-
File.delete! content_file
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#overwrite using :with option arg' do
|
66
|
-
it 'should overwrite file content with new content, erasing the old' do
|
67
|
-
cf = File.new(content_file)
|
68
|
-
|
69
|
-
cf.overwrite :with => content
|
70
|
-
|
71
|
-
new_content = "New content"
|
72
|
-
cf.overwrite :with => new_content
|
73
|
-
|
74
|
-
cf.has_content?(content).should be_false
|
75
|
-
cf.has_content?(new_content).should be_true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sugar-high/file_mutate'
|
3
|
-
File.mutate_ext :all
|
4
|
-
|
5
|
-
describe "SugarHigh::File" do
|
6
|
-
let(:empty_file) { fixture_file 'empty.txt' }
|
7
|
-
let(:non_empty_file) { fixture_file 'non-empty.txt'}
|
8
|
-
let(:class_file) { fixture_file 'class_file.rb'}
|
9
|
-
let(:replace_file) { fixture_file 'file.txt' }
|
10
|
-
let(:file_to_delete) { fixture_file 'file_to_delete.txt' }
|
11
|
-
let(:routes_file) { fixture_file 'routes_file.rb' }
|
12
|
-
let(:app_file) { fixture_file 'application_file.rb' }
|
13
|
-
|
14
|
-
describe '#remove_content_from with :where option' do
|
15
|
-
let(:replace_file) { fixture_file 'file.txt' }
|
16
|
-
|
17
|
-
it "should remove content from existing file - class method" do
|
18
|
-
File.overwrite(replace_file) do
|
19
|
-
'Hello You'
|
20
|
-
end
|
21
|
-
File.remove_content_from replace_file, :where => 'You'
|
22
|
-
File.read(replace_file).should_not match /You/
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should remove content from existing file - instance method #remove_content" do
|
26
|
-
File.overwrite(replace_file) do
|
27
|
-
'Hello You'
|
28
|
-
end
|
29
|
-
File.new(replace_file).remove_content :where => 'You'
|
30
|
-
File.read(replace_file).should_not match /You/
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#remove_content_from with :content option' do
|
36
|
-
let(:replace_file) { fixture_file 'file.txt' }
|
37
|
-
|
38
|
-
it "should remove content from existing file - class method" do
|
39
|
-
File.overwrite(replace_file) do
|
40
|
-
'Hello You'
|
41
|
-
end
|
42
|
-
File.remove_content_from replace_file, :content => 'You'
|
43
|
-
File.read(replace_file).should_not match /You/
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should remove content from existing file - instance method #remove_content" do
|
47
|
-
File.overwrite(replace_file) do
|
48
|
-
'Hello You'
|
49
|
-
end
|
50
|
-
File.new(replace_file).remove_content 'You'
|
51
|
-
File.read(replace_file).should_not match /You/
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '#remove_from with String/Regexp argument that is content to remove' do
|
56
|
-
let(:replace_file) { fixture_file 'file.txt' }
|
57
|
-
|
58
|
-
it "should remove content from existing file - class method" do
|
59
|
-
File.overwrite(replace_file) do
|
60
|
-
'Hello You'
|
61
|
-
end
|
62
|
-
File.remove_from replace_file, 'You'
|
63
|
-
File.read(replace_file).should_not match /You/
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should remove content from existing file - instance method #remove" do
|
67
|
-
File.overwrite(replace_file) do
|
68
|
-
'Hello You'
|
69
|
-
end
|
70
|
-
File.new(replace_file).remove_content 'You'
|
71
|
-
File.read(replace_file).should_not match /You/
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#remove_from with block argument that is content to remove' do
|
76
|
-
let(:replace_file) { fixture_file 'file.txt' }
|
77
|
-
|
78
|
-
it "should work using File object as target" do
|
79
|
-
fr = File.new replace_file
|
80
|
-
File.overwrite(fr) do
|
81
|
-
'Hello You'
|
82
|
-
end
|
83
|
-
File.remove_from fr do
|
84
|
-
'You'
|
85
|
-
end
|
86
|
-
File.read(fr).should_not match /You/
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should remove content from existing file - class method" do
|
90
|
-
File.overwrite(replace_file) do
|
91
|
-
'Hello You'
|
92
|
-
end
|
93
|
-
File.remove_from replace_file do
|
94
|
-
'You'
|
95
|
-
end
|
96
|
-
File.read(replace_file).should_not match /You/
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should remove content from existing file - instance method #remove" do
|
100
|
-
File.overwrite(replace_file) do
|
101
|
-
'Hello You'
|
102
|
-
end
|
103
|
-
File.new(replace_file).remove do
|
104
|
-
'You'
|
105
|
-
end
|
106
|
-
File.read(replace_file).should_not match /You/
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|