reality-generators 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reality/generators/generator.rb +3 -1
- data/reality-generators.gemspec +1 -1
- data/test/generators/test_generator.rb +40 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b53895e619304dc52428b481c0b1922695039ae
|
4
|
+
data.tar.gz: 3d4aa146c64150afce33a34dc43d9a538b9337cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aae8b67f7bab3ab657620070fddb640789a2b610063ffa5ef9419ba124b639d1c5fb1bcdbf1b33b177e9d537ea38c1c10e5a2b4c00c27b5e0cb614f4afd0f21
|
7
|
+
data.tar.gz: aa5c5fad5e2ff7a0b0af90a32c5b341ac6e7e3aa5297d62efb72ef9e89226a55717e032240166f7808b6ce482bebb7c0c3c61f0f1500ee471cc8b3d530701fda
|
@@ -37,9 +37,11 @@ module Reality #nodoc
|
|
37
37
|
# traverses all elements that are contained transitively by the root element.
|
38
38
|
# The templates then generate files from traversed elements.
|
39
39
|
def generate(element_type, element, directory, templates, filter)
|
40
|
-
templates = load_templates_from_template_sets(templates) if templates.any? {|t| t.is_a?(Symbol)}
|
40
|
+
templates = load_templates_from_template_sets(templates) if templates.any? {|t| t.is_a?(Symbol) || t.is_a?(String)}
|
41
41
|
unprocessed_files = (Dir["#{directory}/**/*.*"] + Dir["#{directory}/**/*"]).uniq
|
42
42
|
|
43
|
+
element.pre_generate if element.respond_to?(:pre_generate)
|
44
|
+
|
43
45
|
Generators.debug "Templates to process: #{templates.collect { |t| t.name }.inspect}"
|
44
46
|
|
45
47
|
targets = {}
|
data/reality-generators.gemspec
CHANGED
@@ -239,6 +239,45 @@ class Reality::Generators::TestGenerator < Reality::TestCase
|
|
239
239
|
assert_equal false, File.exist?("#{target_directory}/main/java/MyRepo/MyEntityB/MyAttr4.java")
|
240
240
|
end
|
241
241
|
|
242
|
+
class Repository2 < Reality.base_element(:name => true)
|
243
|
+
def pre_generate
|
244
|
+
@pre_generate_called = true
|
245
|
+
end
|
246
|
+
|
247
|
+
def pre_generate_called?
|
248
|
+
@pre_generate_called ||= false
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
class Repository2Template < Reality::Generators::SingleFileOutputTemplate
|
253
|
+
def render_to_string(context_binding)
|
254
|
+
eval('"Repository: #{repository2.name}"', context_binding)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_generate_with_pre_generate_hook
|
259
|
+
repository = Repository2.new(:MyRepo)
|
260
|
+
|
261
|
+
TestTemplateSetContainer.target_manager.target(:repository2)
|
262
|
+
|
263
|
+
template_set = TestTemplateSetContainer.template_set(:test) do |t|
|
264
|
+
Repository2Template.new(t, [], :repository2, 'repository.java', 'main/java/#{repository2.name}.java')
|
265
|
+
end
|
266
|
+
|
267
|
+
target_directory = "#{temp_dir}/generated/erb_template"
|
268
|
+
|
269
|
+
# Call toString on template name to ensure it is possible to pass string in
|
270
|
+
TestTemplateSetContainer.generator.
|
271
|
+
generate(:repository2, repository, target_directory, [template_set.name.to_s], nil)
|
272
|
+
|
273
|
+
repo_file = "#{target_directory}/main/java/MyRepo.java"
|
274
|
+
|
275
|
+
assert_equal true, repository.pre_generate_called?
|
276
|
+
assert_equal true, File.directory?("#{target_directory}/main/java")
|
277
|
+
assert_equal true, File.exist?(repo_file)
|
278
|
+
assert_equal 'Repository: MyRepo', IO.read(repo_file)
|
279
|
+
end
|
280
|
+
|
242
281
|
def test_load_templates_from_template_sets
|
243
282
|
|
244
283
|
TestTemplateSetContainer.target_manager.target(:repository)
|
@@ -268,7 +307,7 @@ class Reality::Generators::TestGenerator < Reality::TestCase
|
|
268
307
|
AttributeTemplate.new(template_set, [], :attribute, 'attribute4.java', 'main/java/#{attribute.qualified_name.gsub(".","/")}4.java')
|
269
308
|
end
|
270
309
|
|
271
|
-
template_set_keys = [:template_set_1,
|
310
|
+
template_set_keys = [:template_set_1, 'template_set_4']
|
272
311
|
templates = TestTemplateSetContainer.generator.load_templates_from_template_sets(template_set_keys)
|
273
312
|
|
274
313
|
assert_equal 6, templates.size
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reality-generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Donald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reality-core
|