reality-generators 1.8.0 → 1.9.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: eb271940ea03018e01b712e7b48e7c398f0b60b1
4
- data.tar.gz: ef6ca7b54c3f3b6bc59998a9286db225170702d2
3
+ metadata.gz: e76ea1052bc46ab01b49553d2836611c6da83c1b
4
+ data.tar.gz: d5e6e663a5580a87a61ace92b2836e440620187f
5
5
  SHA512:
6
- metadata.gz: a19d5020200dd18b3597ed8f0cd4c5fca8a6f5b898cafcdee27bee85eddfdca29174dec5a2c1e3839c48844ab6b23359f345acb4900d095ca9fe1257614e7336
7
- data.tar.gz: 73deadfbfdbfdd6cba4d3b418d12d165e8993cb03ba3908960ff5b58c83079f12c90434ffb0851b1773e0f6145cd4eec3143dbd8bed443be964a2c9dcac871aa
6
+ metadata.gz: 9c88db3db21c9c4c81c604043edd85df6681244cee76d95916d02767949a6c4cfbc9732d5ee6187935114bf1615aa31ac33c7fd75e7817528e548504f2a4273e
7
+ data.tar.gz: 3b038a2cf2b0b66c936e9ba4f862cca89bf8eb93b5571d4e9b3a09e86271a092562fefe678607d60081e3b7fc3645edd651c2d3aee667f329bb7ff96575594cd
@@ -42,7 +42,7 @@ module Reality #nodoc
42
42
  artifact_category = options.delete(:artifact_category) || :main
43
43
  Reality::Generators.error("artifact_category '#{artifact_category}' is not a known type") unless [:main, :test].include?(artifact_category)
44
44
  filename_pattern = "#{artifact_category}/java/\#{#{self.target_key}.#{self.facet_key}.qualified_#{artifact_key}_name.gsub(\".\",\"/\")}.java"
45
- artifact(template_set_suffix, artifact_key, filename_pattern, options)
45
+ file_artifact(template_set_suffix, artifact_key, filename_pattern, options)
46
46
  end
47
47
 
48
48
  #
@@ -57,46 +57,65 @@ module Reality #nodoc
57
57
  # * :helpers - additional helpers that are added to the default helpers.
58
58
  # * :guard - The :guard option passed to the template.
59
59
  #
60
- def artifact(template_set_suffix, artifact_key, filename_pattern, options = {})
60
+ def file_artifact(template_set_suffix, artifact_key, filename_pattern, options = {})
61
61
  Reality::Options.check(options, [:facets, :guard, :helpers], Reality::Generators, 'define artifact')
62
62
 
63
- facets = [self.facet_key] + (options[:facets].nil? ? [] : options[:facets])
63
+ file_extension = File.extname(filename_pattern)[1...9999]
64
64
 
65
- guard = options[:guard]
65
+ params = options.merge(:file_type => file_extension)
66
+ artifact(template_set_suffix, params) do |template_set, facets, helpers, template_options|
67
+ base_template_filename = "#{facet_templates_directory}/#{artifact_key}.#{file_extension}"
68
+ template_extension =
69
+ File.exist?("#{base_template_filename}.erb") ?
70
+ 'erb' :
71
+ File.exist?("#{base_template_filename}.rb") ? 'rb' : nil
72
+ template_filename = "#{base_template_filename}.#{template_extension}"
73
+ if 'erb' == template_extension
74
+ template_set.erb_template(facets, self.target_key, template_filename, filename_pattern, helpers, template_options)
75
+ else
76
+ template_set.ruby_template(facets, self.target_key, template_filename, filename_pattern, helpers, template_options)
77
+ end
78
+ end
79
+ end
66
80
 
67
- artifact_type = self.target_key
81
+ #
82
+ # Define an arbitrary artifact and attach it to template_set.
83
+ # This delegates the work of creating the template to the supplied block which is passed the template pattern.
84
+ #
85
+ # The template set is prefixed with the name of the facet from which this is extended if any.
86
+ #
87
+ # The following options are supported. Additional options are passed to helper methods and may be used.
88
+ # * :facets - additional facets that must be enabled for the facet to be generated.
89
+ # * :helpers - additional helpers that are added to the default helpers.
90
+ # * :guard - The :guard option passed to the template.
91
+ #
92
+ def artifact(template_set_suffix, options = {}, &block)
93
+ block.call(template_set_with_suffix(template_set_suffix),
94
+ template_set_facets(options),
95
+ template_set_helpers(options),
96
+ :guard => options[:guard])
97
+ end
68
98
 
69
- template_set_key = :"#{self.facet_key}_#{template_set_suffix}"
99
+ def template_set_facets(options = {})
100
+ (self.default_facets + (options[:facets].nil? ? [] : options[:facets])).compact
101
+ end
70
102
 
71
- file_extension = File.extname(filename_pattern)[1...9999]
103
+ def template_set_helpers(options = {})
104
+ template_set_container.
105
+ derive_default_helpers(options.merge(:artifact_type => self.target_key, :facet_key => self.facet_key)) +
106
+ (options[:helpers].nil? ? [] : options[:helpers])
107
+ end
108
+
109
+ def template_set_with_suffix(suffix)
110
+ template_set_key = [self.facet_key, suffix].compact.join('_').to_sym
72
111
 
73
- template_set = template_set_container.template_set_by_name?(template_set_key) ?
112
+ template_set_container.template_set_by_name?(template_set_key) ?
74
113
  template_set_container.template_set_by_name(template_set_key) :
75
114
  template_set_container.template_set(template_set_key)
115
+ end
76
116
 
77
- base_template_filename = "#{facet_templates_directory}/#{artifact_key}.#{file_extension}"
78
- template_extension = File.exist?("#{base_template_filename}.erb") ? 'erb' : 'rb'
79
- template_filename = "#{base_template_filename}.#{template_extension}"
80
-
81
-
82
- helpers = template_set_container.derive_default_helpers(options.merge(:file_type => file_extension, :artifact_type => artifact_type, :facet_key => self.facet_key)) +
83
- (options[:helpers].nil? ? [] : options[:helpers])
84
-
85
- if 'erb' == template_extension
86
- template_set.erb_template(facets,
87
- artifact_type,
88
- template_filename,
89
- filename_pattern,
90
- helpers,
91
- :guard => guard)
92
- else
93
- template_set.ruby_template(facets,
94
- artifact_type,
95
- template_filename,
96
- filename_pattern,
97
- helpers,
98
- :guard => guard)
99
- end
117
+ def default_facets
118
+ [self.facet_key]
100
119
  end
101
120
 
102
121
  def facet_templates_directory
@@ -110,12 +129,12 @@ module Reality #nodoc
110
129
  caller_locations.collect { |c| c.absolute_path } :
111
130
  caller.collect { |s| s.split(':')[0] }
112
131
  locations.each do |location|
113
- if location =~ /.*\/#{self.facet_key}\/model\.rb$/
132
+ if !self.facet_key.nil? && location =~ /.*\/#{self.facet_key}\/model\.rb$/
114
133
  @facet_directory = File.dirname(location)
115
134
  break
116
135
  end
117
136
  end
118
- Reality::Generators.error("Unable to locate facet_directory for facet #{self.facet_key}. Caller trace: #{locations.inspect}") if @facet_directory.nil?
137
+ Reality::Generators.error("Unable to locate facet_directory for facet '#{self.facet_key}'. Caller trace: #{locations.inspect}") if @facet_directory.nil?
119
138
  end
120
139
  @facet_directory
121
140
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-generators}
5
- s.version = '1.8.0'
5
+ s.version = '1.9.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -18,34 +18,34 @@ class TestFacetExtension
18
18
  end
19
19
 
20
20
  def define_artifacts1
21
- artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
21
+ file_artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
22
22
  end
23
23
 
24
24
  def define_artifacts2
25
- artifact(:models, :rubytemplate, 'main/java/#{entity.qualified_name}.java')
25
+ file_artifact(:models, :rubytemplate, 'main/java/#{entity.qualified_name}.java')
26
26
  end
27
27
 
28
28
  def define_artifacts3
29
- artifact(:models,
30
- :mytemplate,
31
- 'main/java/#{entity.qualified_name}.java',
32
- :facets => [:ee],
33
- :helpers => [MyHelperModule],
34
- :guard => 'entity.jpa.good?')
29
+ file_artifact(:models,
30
+ :mytemplate,
31
+ 'main/java/#{entity.qualified_name}.java',
32
+ :facets => [:ee],
33
+ :helpers => [MyHelperModule],
34
+ :guard => 'entity.jpa.good?')
35
35
  end
36
36
 
37
37
  def define_artifacts4
38
- artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
38
+ file_artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
39
39
  end
40
40
 
41
41
  def define_artifacts5
42
- artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
43
- artifact(:qa_models, :mytemplate, 'test/java/#{entity.qualified_name}.java')
44
- artifact(:qa_models, :rubytemplate, 'main/java/#{entity.qualified_name}.java')
42
+ file_artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
43
+ file_artifact(:qa_models, :mytemplate, 'test/java/#{entity.qualified_name}.java')
44
+ file_artifact(:qa_models, :rubytemplate, 'main/java/#{entity.qualified_name}.java')
45
45
  end
46
46
 
47
47
  def define_artifacts6
48
- artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java', :bad_option => true)
48
+ file_artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java', :bad_option => true)
49
49
  end
50
50
 
51
51
  def define_artifacts7
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.8.0
4
+ version: 1.9.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-07 00:00:00.000000000 Z
11
+ date: 2017-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core