retrospec 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +4 -0
- data/lib/retrospec/plugins/v1/module_helpers.rb +56 -18
- data/lib/retrospec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0659917a8ec821253617d285409639b144be2979
|
4
|
+
data.tar.gz: 4a797031adc73b0bdf1a031d5298682f6b08cc47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b0e34a19203df1f8244021fcfda2f9b5ba89465ce2611405cd81ef0c675124a86995eff308680c0da79e1a6d9812106f5bc509600a6b83f1cf0bf1a36658c68
|
7
|
+
data.tar.gz: f6c4d3c7c6457fa5dbc5c6e63cc3d4f7affae20a43daff185bfd154e225a25573b9cd8bd914fddc46679ba7b5015df2683eb98765c11b79edb674ee825383d2c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# Retrospec Changelog
|
2
|
+
## 0.6.0
|
3
|
+
* Adds the ability to filter out certain files from being generated
|
4
|
+
* Adds the ability to sync any module file when it ends contains a .sync in the file name
|
1
5
|
## 0.5.1
|
2
6
|
* fixes gemspec spefication for runtime dependency
|
3
7
|
## 0.5.0
|
4
8
|
* adds ability to overwrite files
|
5
|
-
* removes jeweler dependency, and uses bundler tasks instead
|
9
|
+
* removes jeweler dependency, and uses bundler tasks instead
|
data/README.md
CHANGED
@@ -119,6 +119,10 @@ Some ideas I have in my head for future plugins that should be created.
|
|
119
119
|
|
120
120
|
The sky is really the limit for what we can create since the usage is limited to any project that contains files.
|
121
121
|
|
122
|
+
## Special file extensions
|
123
|
+
* If a file contains `.sync` the file will be always be synced
|
124
|
+
* If a file contains `.retrospec.erb` this tells retrospec that the file should be rendered as an erb file
|
125
|
+
|
122
126
|
## Contributing to retrospec
|
123
127
|
|
124
128
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
@@ -83,9 +83,40 @@ module Retrospec
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
# @param [String] - destination of the file
|
87
|
+
# @return [Bool] - true if the file should be synced
|
88
|
+
# determines if the file should be synced by checking if the any of the file extensions
|
89
|
+
# have the word sync
|
90
|
+
def sync_file?(file)
|
91
|
+
filename = File.basename(file)
|
92
|
+
parts = filename.split('.')
|
93
|
+
parts.include?('sync')
|
94
|
+
end
|
95
|
+
|
96
|
+
# @param [String] - destination of the file
|
97
|
+
# @return [Bool] - true if the file should be synced
|
98
|
+
# determines if the contains the extension retrospec
|
99
|
+
# have the word sync
|
100
|
+
def retrospec_file?(file)
|
101
|
+
filename = File.basename(file)
|
102
|
+
parts = filename.split('.')
|
103
|
+
parts.include?('retrospec')
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param [String] - destination of the file
|
107
|
+
# @param [Bool] - true if the file should be synced
|
108
|
+
# @return [Bool] - true if the file should be created or overwritten
|
109
|
+
def should_create?(dest, sync_file = false)
|
110
|
+
return true unless File.exists?(dest)
|
111
|
+
return true if sync_file
|
112
|
+
return true if overwrite?(dest)
|
113
|
+
return true if File.zero?(dest)
|
114
|
+
false
|
115
|
+
end
|
116
|
+
|
86
117
|
# move the file, safely
|
87
118
|
def safe_move_file(src,dest)
|
88
|
-
|
119
|
+
unless should_create?(dest)
|
89
120
|
return $stderr.puts "!! #{dest} already exists and differs from template".warning
|
90
121
|
end
|
91
122
|
create_content(:mv, dest, src)
|
@@ -93,15 +124,15 @@ module Retrospec
|
|
93
124
|
|
94
125
|
# copy the symlink and preserve the link
|
95
126
|
def safe_create_symlink(src,dest)
|
96
|
-
|
127
|
+
unless should_create?(dest)
|
97
128
|
return $stderr.puts "!! #{dest} already exists and differs from template".warning
|
98
129
|
end
|
99
130
|
create_content(:link, dest, src)
|
100
131
|
end
|
101
132
|
|
102
133
|
# safely copy an existing file to another dest
|
103
|
-
def safe_copy_file(src, dest)
|
104
|
-
|
134
|
+
def safe_copy_file(src, dest, sync_file = false)
|
135
|
+
unless should_create?(dest, sync_file)
|
105
136
|
return $stderr.puts "!! #{dest} already exists".warning
|
106
137
|
end
|
107
138
|
return safe_touch(src) unless File.exists?(src)
|
@@ -121,11 +152,11 @@ module Retrospec
|
|
121
152
|
end
|
122
153
|
|
123
154
|
# safely creates a file and does not override the existing file
|
124
|
-
def safe_create_file(dest, content)
|
125
|
-
|
155
|
+
def safe_create_file(dest, content, sync_file = false)
|
156
|
+
unless should_create?(dest, sync_file)
|
126
157
|
old_content = File.read(dest)
|
127
158
|
# if we did a better comparison of content we could be smarter about when we create files
|
128
|
-
if old_content != content
|
159
|
+
if old_content != content
|
129
160
|
$stderr.puts "!! #{dest} already exists and differs from template".warning
|
130
161
|
end
|
131
162
|
else
|
@@ -146,17 +177,15 @@ module Retrospec
|
|
146
177
|
# path is the full path of the file to create
|
147
178
|
# template is the full path to the template file
|
148
179
|
# spec_object is any bindable object which the templates uses for context
|
149
|
-
def safe_create_template_file(path, template, spec_object)
|
180
|
+
def safe_create_template_file(path, template, spec_object, sync_file = false)
|
150
181
|
# check to ensure parent directory exists
|
151
182
|
file_dir_path = File.expand_path(File.dirname(path))
|
152
|
-
|
153
|
-
safe_mkdir(file_dir_path)
|
154
|
-
end
|
183
|
+
safe_mkdir(file_dir_path) unless File.exists?(file_dir_path)
|
155
184
|
File.open(template) do |file|
|
156
185
|
renderer = ERB.new(file.read, 0, '-')
|
157
186
|
content = renderer.result spec_object.get_binding
|
158
187
|
dest_path = File.expand_path(path)
|
159
|
-
safe_create_file(dest_path, content)
|
188
|
+
safe_create_file(dest_path, content, sync_file)
|
160
189
|
end
|
161
190
|
end
|
162
191
|
|
@@ -165,9 +194,15 @@ module Retrospec
|
|
165
194
|
# strips the erb extension and renders the template to the current module path
|
166
195
|
# filenames must named how they would appear in the normal module path. The directory
|
167
196
|
# structure where the file is contained
|
168
|
-
|
169
|
-
|
197
|
+
# @param [String] template directory of where to find templates
|
198
|
+
# @param [String] module_path - path to the module
|
199
|
+
# @param [String] spec_object - the context that is used for template rendering
|
200
|
+
# @param [String] filter - a regex string used to filter out files
|
201
|
+
def safe_create_module_files(template_dir, module_path, spec_object, filter = nil)
|
202
|
+
dir = File.join(template_dir,'module_files')
|
203
|
+
templates = Find.find(dir).sort
|
170
204
|
templates.each do |template|
|
205
|
+
next if template =~ filter
|
171
206
|
dest = template.gsub(File.join(template_dir,'module_files'), module_path)
|
172
207
|
if File.symlink?(template)
|
173
208
|
safe_create_symlink(template, dest)
|
@@ -176,12 +211,15 @@ module Retrospec
|
|
176
211
|
else
|
177
212
|
# because some plugins contain erb files themselves any erb file will be copied only
|
178
213
|
# so we need to designate which files should be rendered with .retrospec.erb
|
179
|
-
|
180
|
-
|
214
|
+
# render any file ending in .retrospec_erb as a template
|
215
|
+
sync_file = sync_file?(template)
|
216
|
+
retrospec_file = retrospec_file?(template)
|
217
|
+
dest = dest.gsub(/\.sync/, '') if sync_file
|
218
|
+
if retrospec_file
|
181
219
|
dest = dest.gsub(/\.retrospec\.erb/, '')
|
182
|
-
safe_create_template_file(dest, template, spec_object)
|
220
|
+
safe_create_template_file(dest, template, spec_object, sync_file)
|
183
221
|
else
|
184
|
-
safe_copy_file(template, dest)
|
222
|
+
safe_copy_file(template, dest, sync_file)
|
185
223
|
end
|
186
224
|
end
|
187
225
|
end
|
data/lib/retrospec/version.rb
CHANGED