Class: Bizflow::SourceGenerator
- Inherits:
-
Object
- Object
- Bizflow::SourceGenerator
- Defined in:
- lib/bizflow/source_generator.rb
Constant Summary collapse
- JsTemplatesPath =
"#{File.dirname(__FILE__)}/templates/js"
- RbTemplatesPath =
"#{File.dirname(__FILE__)}/templates/rb"
Instance Attribute Summary collapse
-
#domain_repo ⇒ Object
readonly
Returns the value of attribute domain_repo.
Instance Method Summary collapse
- #generate(config) ⇒ Object
- #generate_handlers(source_dest) ⇒ Object
- #generate_processes(source_dest) ⇒ Object
- #generate_processes_descriptor(source_dest) ⇒ Object
-
#initialize(builder) ⇒ SourceGenerator
constructor
A new instance of SourceGenerator.
Constructor Details
#initialize(builder) ⇒ SourceGenerator
Returns a new instance of SourceGenerator.
13 14 15 16 |
# File 'lib/bizflow/source_generator.rb', line 13 def initialize(builder) @builder = builder @domain_repo = @builder.build end |
Instance Attribute Details
#domain_repo ⇒ Object (readonly)
Returns the value of attribute domain_repo.
11 12 13 |
# File 'lib/bizflow/source_generator.rb', line 11 def domain_repo @domain_repo end |
Instance Method Details
#generate(config) ⇒ Object
18 19 20 21 22 |
# File 'lib/bizflow/source_generator.rb', line 18 def generate(config) generate_processes(config[:dest_process_path]) generate_processes_descriptor(config[:dest_descriptor_path]) #generate_handlers(source_dest) end |
#generate_handlers(source_dest) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bizflow/source_generator.rb', line 36 def generate_handlers(source_dest) domain_repo.processes.each do |_, process| presenter = Bizflow::ProcessTemplatePresenter.new(process) handler_source = ERB.new(File.read("#{RbTemplatesPath}/handler.tt")).result(presenter.get_binding) Dir.mkdir "#{source_dest}/handlers" process.handlers.each do |handler| out_file = File.new("#{source_dest}/handlers/#{handler.name}_handler.rb", "w") out_file.puts(handler_source) out_file.close end end end |
#generate_processes(source_dest) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bizflow/source_generator.rb', line 24 def generate_processes(source_dest) domain_repo.processes.each do |_, process| presenter = Bizflow::ProcessTemplatePresenter.new(process) process_source = ERB.new(File.read("#{RbTemplatesPath}/process.tt"), nil, '-').result(presenter.get_binding) out_file = File.new("#{source_dest}/#{presenter.name}_process.rb", "w") out_file.puts(process_source) out_file.close end end |
#generate_processes_descriptor(source_dest) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/bizflow/source_generator.rb', line 51 def generate_processes_descriptor(source_dest) descriptor = ERB.new(File.read("#{JsTemplatesPath}/descriptor.tt"), nil, '-').result(domain_repo.get_binding) out_file = File.new("#{source_dest}/process-descriptor.json", "w") out_file.puts(descriptor) out_file.close end |