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,10 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'rails'
|
3
3
|
require 'sugar-high/rails/concerns'
|
4
|
+
require 'active_support/dependencies'
|
5
|
+
|
6
|
+
# The same procedure as one that needed for common #require - It should know path.
|
7
|
+
$:.unshift File.dirname __FILE__
|
8
|
+
|
9
|
+
class FixtureUser
|
10
|
+
concerned_with :scopes, :validations
|
11
|
+
shared_concerns :associations
|
12
|
+
include_shared_concerns :caching
|
13
|
+
end
|
4
14
|
|
5
15
|
describe "SugarHigh Rails" do
|
6
16
|
describe "Concerns pack" do
|
7
|
-
|
17
|
+
describe "#concerned_with" do
|
18
|
+
it 'should require files from #{name.underscore}/#{concern}' do
|
19
|
+
[:scopes, :validations].each do |concern|
|
20
|
+
FixtureUser.new.should respond_to("method_from_#{concern}_concern")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#shared_concerns" do
|
26
|
+
it 'should require files from shared/#{concern}' do
|
27
|
+
pending "How to be with namespaces? Is such raw implementation enough? Or just drop this kind of method?"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#include_shared_concerns" do
|
32
|
+
it 'should require and include from shared/#{concern}' do
|
33
|
+
FixtureUser.new.should respond_to("method_from_shared_concern")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
8
37
|
end
|
9
38
|
end
|
10
39
|
|
40
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
puts "+++++++++"
|
data/sugar-high.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sugar-high}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Kristian Mandrup}]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-21}
|
13
13
|
s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,15 +35,6 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/sugar-high/enumerable.rb",
|
36
36
|
"lib/sugar-high/file.rb",
|
37
37
|
"lib/sugar-high/file_ext.rb",
|
38
|
-
"lib/sugar-high/file_mutate.rb",
|
39
|
-
"lib/sugar-high/file_mutate/append_content.rb",
|
40
|
-
"lib/sugar-high/file_mutate/delete.rb",
|
41
|
-
"lib/sugar-high/file_mutate/insert_content.rb",
|
42
|
-
"lib/sugar-high/file_mutate/mutate.rb",
|
43
|
-
"lib/sugar-high/file_mutate/overwrite_content.rb",
|
44
|
-
"lib/sugar-high/file_mutate/remove_content.rb",
|
45
|
-
"lib/sugar-high/file_mutate/replace_content.rb",
|
46
|
-
"lib/sugar-high/file_mutation.rb",
|
47
38
|
"lib/sugar-high/hash.rb",
|
48
39
|
"lib/sugar-high/includes.rb",
|
49
40
|
"lib/sugar-high/kind_of.rb",
|
@@ -60,46 +51,15 @@ Gem::Specification.new do |s|
|
|
60
51
|
"lib/sugar-high/rspec/configure.rb",
|
61
52
|
"lib/sugar-high/rspec/matchers/have_aliases.rb",
|
62
53
|
"lib/sugar-high/string.rb",
|
63
|
-
"sandbox/test_routes_mutate.rb",
|
64
|
-
"spec/auto_load_blank_root.rb",
|
65
|
-
"spec/autoload_blank_root.rb",
|
66
|
-
"spec/autoload_blank_root/hello.rb",
|
67
|
-
"spec/autoload_blank_root/sailor.rb",
|
68
|
-
"spec/fixtures/application_file.rb",
|
69
|
-
"spec/fixtures/autoload_modules.rb",
|
70
|
-
"spec/fixtures/autoload_modules/subdir/first.rb",
|
71
|
-
"spec/fixtures/autoload_modules/subdir/second.rb",
|
72
|
-
"spec/fixtures/autoload_modules/subdir/third.rb",
|
73
|
-
"spec/fixtures/autoload_modules_root.rb",
|
74
|
-
"spec/fixtures/autoload_modules_root/first.rb",
|
75
|
-
"spec/fixtures/autoload_modules_root/second.rb",
|
76
|
-
"spec/fixtures/autoload_modules_root/third.rb",
|
77
|
-
"spec/fixtures/autoload_modulez.rb",
|
78
|
-
"spec/fixtures/autoload_modulez/first.rb",
|
79
|
-
"spec/fixtures/autoload_modulez/second.rb",
|
80
|
-
"spec/fixtures/autoload_modulez/third_one_here.rb",
|
81
|
-
"spec/fixtures/class_file.rb",
|
82
|
-
"spec/fixtures/class_file.txt",
|
83
|
-
"spec/fixtures/content_file.txt",
|
84
54
|
"spec/fixtures/empty.txt",
|
85
55
|
"spec/fixtures/non-empty.txt",
|
86
|
-
"spec/fixtures/routes_file.rb",
|
87
56
|
"spec/fixtures/search_file.txt",
|
88
57
|
"spec/spec_helper.rb",
|
89
58
|
"spec/sugar-high/alias_spec.rb",
|
90
59
|
"spec/sugar-high/arguments_spec.rb",
|
91
60
|
"spec/sugar-high/array_spec.rb",
|
92
61
|
"spec/sugar-high/blank_spec.rb",
|
93
|
-
"spec/sugar-high/class_ext_spec.rb",
|
94
62
|
"spec/sugar-high/dsl_spec.rb",
|
95
|
-
"spec/sugar-high/file/file_dsl_spec.rb",
|
96
|
-
"spec/sugar-high/file_mutate/append_content_spec.rb",
|
97
|
-
"spec/sugar-high/file_mutate/delete_spec.rb",
|
98
|
-
"spec/sugar-high/file_mutate/insert_before_last_spec.rb",
|
99
|
-
"spec/sugar-high/file_mutate/insert_content_spec.rb",
|
100
|
-
"spec/sugar-high/file_mutate/overwrite_content_spec.rb",
|
101
|
-
"spec/sugar-high/file_mutate/remove_content_spec.rb",
|
102
|
-
"spec/sugar-high/file_mutate/replace_content_spec.rb",
|
103
63
|
"spec/sugar-high/file_spec.rb",
|
104
64
|
"spec/sugar-high/hash_spec.rb",
|
105
65
|
"spec/sugar-high/includes_spec.rb",
|
@@ -110,6 +70,10 @@ Gem::Specification.new do |s|
|
|
110
70
|
"spec/sugar-high/path_spec.rb",
|
111
71
|
"spec/sugar-high/properties_spec.rb",
|
112
72
|
"spec/sugar-high/rails/concerns_spec.rb",
|
73
|
+
"spec/sugar-high/rails/fixture_user/scopes.rb",
|
74
|
+
"spec/sugar-high/rails/fixture_user/validations.rb",
|
75
|
+
"spec/sugar-high/rails/shared/associations.rb",
|
76
|
+
"spec/sugar-high/rails/shared/caching.rb",
|
113
77
|
"spec/sugar-high/regexp_spec.rb",
|
114
78
|
"spec/sugar-high/string_spec.rb",
|
115
79
|
"sugar-high.gemspec"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugar-high
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &2155469300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2155469300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2155468820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.4.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2155468820
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &2155468340 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.0.1
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2155468340
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &2155467860 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2155467860
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &2155467380 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.1
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2155467380
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdoc
|
71
|
-
requirement: &
|
71
|
+
requirement: &2155466900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2155466900
|
80
80
|
description: More Ruby sugar - inspired by the 'zuker' project
|
81
81
|
email: kmandrup@gmail.com
|
82
82
|
executables: []
|
@@ -103,15 +103,6 @@ files:
|
|
103
103
|
- lib/sugar-high/enumerable.rb
|
104
104
|
- lib/sugar-high/file.rb
|
105
105
|
- lib/sugar-high/file_ext.rb
|
106
|
-
- lib/sugar-high/file_mutate.rb
|
107
|
-
- lib/sugar-high/file_mutate/append_content.rb
|
108
|
-
- lib/sugar-high/file_mutate/delete.rb
|
109
|
-
- lib/sugar-high/file_mutate/insert_content.rb
|
110
|
-
- lib/sugar-high/file_mutate/mutate.rb
|
111
|
-
- lib/sugar-high/file_mutate/overwrite_content.rb
|
112
|
-
- lib/sugar-high/file_mutate/remove_content.rb
|
113
|
-
- lib/sugar-high/file_mutate/replace_content.rb
|
114
|
-
- lib/sugar-high/file_mutation.rb
|
115
106
|
- lib/sugar-high/hash.rb
|
116
107
|
- lib/sugar-high/includes.rb
|
117
108
|
- lib/sugar-high/kind_of.rb
|
@@ -128,46 +119,15 @@ files:
|
|
128
119
|
- lib/sugar-high/rspec/configure.rb
|
129
120
|
- lib/sugar-high/rspec/matchers/have_aliases.rb
|
130
121
|
- lib/sugar-high/string.rb
|
131
|
-
- sandbox/test_routes_mutate.rb
|
132
|
-
- spec/auto_load_blank_root.rb
|
133
|
-
- spec/autoload_blank_root.rb
|
134
|
-
- spec/autoload_blank_root/hello.rb
|
135
|
-
- spec/autoload_blank_root/sailor.rb
|
136
|
-
- spec/fixtures/application_file.rb
|
137
|
-
- spec/fixtures/autoload_modules.rb
|
138
|
-
- spec/fixtures/autoload_modules/subdir/first.rb
|
139
|
-
- spec/fixtures/autoload_modules/subdir/second.rb
|
140
|
-
- spec/fixtures/autoload_modules/subdir/third.rb
|
141
|
-
- spec/fixtures/autoload_modules_root.rb
|
142
|
-
- spec/fixtures/autoload_modules_root/first.rb
|
143
|
-
- spec/fixtures/autoload_modules_root/second.rb
|
144
|
-
- spec/fixtures/autoload_modules_root/third.rb
|
145
|
-
- spec/fixtures/autoload_modulez.rb
|
146
|
-
- spec/fixtures/autoload_modulez/first.rb
|
147
|
-
- spec/fixtures/autoload_modulez/second.rb
|
148
|
-
- spec/fixtures/autoload_modulez/third_one_here.rb
|
149
|
-
- spec/fixtures/class_file.rb
|
150
|
-
- spec/fixtures/class_file.txt
|
151
|
-
- spec/fixtures/content_file.txt
|
152
122
|
- spec/fixtures/empty.txt
|
153
123
|
- spec/fixtures/non-empty.txt
|
154
|
-
- spec/fixtures/routes_file.rb
|
155
124
|
- spec/fixtures/search_file.txt
|
156
125
|
- spec/spec_helper.rb
|
157
126
|
- spec/sugar-high/alias_spec.rb
|
158
127
|
- spec/sugar-high/arguments_spec.rb
|
159
128
|
- spec/sugar-high/array_spec.rb
|
160
129
|
- spec/sugar-high/blank_spec.rb
|
161
|
-
- spec/sugar-high/class_ext_spec.rb
|
162
130
|
- spec/sugar-high/dsl_spec.rb
|
163
|
-
- spec/sugar-high/file/file_dsl_spec.rb
|
164
|
-
- spec/sugar-high/file_mutate/append_content_spec.rb
|
165
|
-
- spec/sugar-high/file_mutate/delete_spec.rb
|
166
|
-
- spec/sugar-high/file_mutate/insert_before_last_spec.rb
|
167
|
-
- spec/sugar-high/file_mutate/insert_content_spec.rb
|
168
|
-
- spec/sugar-high/file_mutate/overwrite_content_spec.rb
|
169
|
-
- spec/sugar-high/file_mutate/remove_content_spec.rb
|
170
|
-
- spec/sugar-high/file_mutate/replace_content_spec.rb
|
171
131
|
- spec/sugar-high/file_spec.rb
|
172
132
|
- spec/sugar-high/hash_spec.rb
|
173
133
|
- spec/sugar-high/includes_spec.rb
|
@@ -178,6 +138,10 @@ files:
|
|
178
138
|
- spec/sugar-high/path_spec.rb
|
179
139
|
- spec/sugar-high/properties_spec.rb
|
180
140
|
- spec/sugar-high/rails/concerns_spec.rb
|
141
|
+
- spec/sugar-high/rails/fixture_user/scopes.rb
|
142
|
+
- spec/sugar-high/rails/fixture_user/validations.rb
|
143
|
+
- spec/sugar-high/rails/shared/associations.rb
|
144
|
+
- spec/sugar-high/rails/shared/caching.rb
|
181
145
|
- spec/sugar-high/regexp_spec.rb
|
182
146
|
- spec/sugar-high/string_spec.rb
|
183
147
|
- sugar-high.gemspec
|
@@ -195,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
159
|
version: '0'
|
196
160
|
segments:
|
197
161
|
- 0
|
198
|
-
hash:
|
162
|
+
hash: -2156933571915273099
|
199
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
164
|
none: false
|
201
165
|
requirements:
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module SugarHigh
|
2
|
-
module FileMutate
|
3
|
-
module AppendContent
|
4
|
-
def append content=nil, &block
|
5
|
-
File.append self.path, content, &block
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def append path, content=nil, &block
|
10
|
-
File.open(path, 'a') do |f|
|
11
|
-
f.puts content ||= yield
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'sugar-high/blank'
|
2
|
-
require 'sugar-high/arguments'
|
3
|
-
require 'sugar-high/path'
|
4
|
-
require 'sugar-high/regexp'
|
5
|
-
require 'sugar-high/string'
|
6
|
-
require 'sugar-high/file'
|
7
|
-
|
8
|
-
module SugarHigh
|
9
|
-
module FileMutate
|
10
|
-
module Delete
|
11
|
-
module ClassMethods
|
12
|
-
def delete! name
|
13
|
-
return nil if !File.exist?(name)
|
14
|
-
File.delete name
|
15
|
-
end
|
16
|
-
alias_method :delete_file!, :delete!
|
17
|
-
end
|
18
|
-
|
19
|
-
def delete!
|
20
|
-
File.delete(self.path)
|
21
|
-
end
|
22
|
-
alias_method :delete_file!, :delete!
|
23
|
-
|
24
|
-
def mutate marker, place, &block
|
25
|
-
File.mutate_file self.path, marker, place, &block
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module SugarHigh
|
2
|
-
module FileMutate
|
3
|
-
module InsertContent
|
4
|
-
def insert *args, &block
|
5
|
-
File.insert_into self.path, *args, &block
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
# insert_into 'my_file.txt', :after => 'Blip', :content => 'Hello
|
10
|
-
# insert_into 'my_file.txt', 'Hello', :after => 'Blip'
|
11
|
-
# insert_into 'my_file.txt', :after => 'Blip' do
|
12
|
-
# 'Hello'
|
13
|
-
# end
|
14
|
-
def insert_into file_name, *args, &block
|
15
|
-
options = last_option args
|
16
|
-
content = insertion_content options, *args, &block
|
17
|
-
|
18
|
-
# no content to insert?
|
19
|
-
return nil if content.blank?
|
20
|
-
|
21
|
-
file = begin
|
22
|
-
get_file(file_name)
|
23
|
-
rescue
|
24
|
-
return nil
|
25
|
-
end
|
26
|
-
|
27
|
-
# already inserted?
|
28
|
-
return nil if !options[:repeat] && file.has_content?(content)
|
29
|
-
|
30
|
-
# find where to insert
|
31
|
-
place, marker = if options[:before]
|
32
|
-
[ :before, options[:before] ]
|
33
|
-
elsif options[:before_last]
|
34
|
-
[ :before_last, options[:before_last] ]
|
35
|
-
else
|
36
|
-
[ :after, options[:after] ]
|
37
|
-
end
|
38
|
-
|
39
|
-
return nil if !file.has_content?(marker)
|
40
|
-
|
41
|
-
# do mutation
|
42
|
-
res = file.mutate marker, place do
|
43
|
-
content
|
44
|
-
end
|
45
|
-
res
|
46
|
-
end
|
47
|
-
|
48
|
-
def insertion_content options = {}, *args, &block
|
49
|
-
case args.first
|
50
|
-
when String
|
51
|
-
args.first
|
52
|
-
when Hash
|
53
|
-
options[:content] || (yield if block)
|
54
|
-
else
|
55
|
-
return yield if block
|
56
|
-
raise ArgumentError, "You must supply content to insert, either as a String before the options hash, a :content option or a block"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module SugarHigh
|
2
|
-
module FileMutate
|
3
|
-
module Mutate
|
4
|
-
module ClassMethods
|
5
|
-
def mutate_file file, marker, place, &block
|
6
|
-
raise ArgumentError, "You must define a replacement marker for a :before, :before_last or :after key" if !marker
|
7
|
-
|
8
|
-
file = File.get_file(file)
|
9
|
-
|
10
|
-
if place == :before_last
|
11
|
-
content = file.read
|
12
|
-
content = content.insert_before_last yield, marker
|
13
|
-
file.overwrite content
|
14
|
-
return
|
15
|
-
end
|
16
|
-
|
17
|
-
marker_found = file.has_content? marker
|
18
|
-
return nil if !marker_found
|
19
|
-
|
20
|
-
replace_in_file file, /(#{marker})/mi do |match|
|
21
|
-
place == :after ? "#{match}\n #{yield}" : "#{yield}\n #{match}"
|
22
|
-
end
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
|
-
def replace_in_file(file, regexp, *args, &block)
|
27
|
-
file = File.get_file(file)
|
28
|
-
content = file.read.gsub(regexp, *args, &block)
|
29
|
-
file.overwrite content
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def get_file file_name
|
34
|
-
case file_name
|
35
|
-
when PathString, String
|
36
|
-
File.new file_name
|
37
|
-
when File
|
38
|
-
file_name
|
39
|
-
else
|
40
|
-
raise ArgumentError, "Could not be converted to a File object: #{file_name}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def get_filepath file
|
45
|
-
case file
|
46
|
-
when PathString, String
|
47
|
-
file
|
48
|
-
when File
|
49
|
-
file.path
|
50
|
-
else
|
51
|
-
raise ArgumentError, "Could not be converted to a file path: #{file_name}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|