Class: Batsir::Compiler::StageWorkerCompiler
- Inherits:
-
Object
- Object
- Batsir::Compiler::StageWorkerCompiler
- Defined in:
- lib/batsir/compiler/stage_worker_compiler.rb
Instance Attribute Summary collapse
-
#stage ⇒ Object
Returns the value of attribute stage.
Instance Method Summary collapse
- #add_notifier(notifier_name, code) ⇒ Object
- #add_transformers_to_notifier(notifier_name, code) ⇒ Object
- #compile ⇒ Object
-
#initialize(stage) ⇒ StageWorkerCompiler
constructor
A new instance of StageWorkerCompiler.
Constructor Details
#initialize(stage) ⇒ StageWorkerCompiler
Returns a new instance of StageWorkerCompiler.
6 7 8 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 6 def initialize(stage) @stage = stage end |
Instance Attribute Details
#stage ⇒ Object
Returns the value of attribute stage.
4 5 6 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 4 def stage @stage end |
Instance Method Details
#add_notifier(notifier_name, code) ⇒ Object
79 80 81 82 83 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 79 def add_notifier(notifier_name, code) code << <<-EOF @filter_queue.add_notifier #{notifier_name} EOF end |
#add_transformers_to_notifier(notifier_name, code) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 65 def add_transformers_to_notifier(notifier_name, code) if stage.notifier_transformers.any? stage.notifier_transformers.each do |transformer_declaration| code << <<-EOF #{notifier_name}.add_transformer #{transformer_declaration.transformer}.new(#{transformer_declaration..to_s}) EOF end else code << <<-EOF #{notifier_name}.add_transformer Batsir::Transformers::JSONOutputTransformer.new EOF end end |
#compile ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 10 def compile klazz_name = "#{stage.name.capitalize.gsub(' ','')}Worker" code = <<-EOF class #{klazz_name} def self.stage_name "#{stage.name}" end def initialize @filter_queue = self.class.filter_queue end def self.filter_queue @filter_queue end def self.initialize_filter_queue @filter_queue = Batsir::FilterQueue.new EOF stage.filter_declarations.each do |filter_declaration| code << <<-EOF @filter_queue.add #{filter_declaration.filter.to_s}.new(#{filter_declaration..to_s}) EOF end stage.conditional_notifiers.each do |conditional_notifier_declaration| conditional_notifier_declaration.compile(code, self) end stage.notifiers.each do |notifier, | .each do || code << <<-EOF notifier = #{notifier.to_s}.new(#{.to_s}) EOF self.add_transformers_to_notifier("notifier", code) self.add_notifier("notifier", code) end end code << <<-EOF end include Sidekiq::Worker include Batsir::StageWorker end #{klazz_name}.sidekiq_options(:queue => Batsir::Config.sidekiq_queue) #{klazz_name} EOF code end |