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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6322e54d0c9bacedc3edb469578c543d94dadebd
4
- data.tar.gz: 7fb99a4f8c009f5bcd3be891caf512cc93788765
3
+ metadata.gz: 5b53895e619304dc52428b481c0b1922695039ae
4
+ data.tar.gz: 3d4aa146c64150afce33a34dc43d9a538b9337cb
5
5
  SHA512:
6
- metadata.gz: 8ad82eca218ba25ceb6eae4d8febc07e97cac46e28d51cd3346268c8189de32997956d6957a878f5ca2a878c8228f0a0b08ddf41227dfb79d55c9a684d5ed8d7
7
- data.tar.gz: 9be8bca65a4dd993d484368e47c0dab6e3b309a5a92eb7d070136681867fbe4123323036cc9e3f2c885d358d2c273cf16d36a3bc8970ee512ddba83b4ac37c8f
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 = {}
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-generators}
5
- s.version = '1.10.0'
5
+ s.version = '1.11.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -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, :template_set_4]
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.10.0
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 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core