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_filter(filter_declaration, code) ⇒ Object
- #add_notifier(code) ⇒ Object
- #add_transformers_to_notifier(code) ⇒ Object
- #compile ⇒ Object
- #compile_worker_class(klazz_name) ⇒ Object
-
#initialize(stage) ⇒ StageWorkerCompiler
constructor
A new instance of StageWorkerCompiler.
- #new_notifier(notifier, options, code) ⇒ Object
- #worker_class(klazz_name) {|code| ... } ⇒ Object
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_filter(filter_declaration, code) ⇒ Object
68 69 70 71 72 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 68 def add_filter(filter_declaration, code) code << <<-EOF @filter_queue.add #{filter_declaration.filter.to_s}.new(#{filter_declaration..to_s}) EOF end |
#add_notifier(code) ⇒ Object
94 95 96 97 98 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 94 def add_notifier(code) code << <<-EOF @filter_queue.add_notifier notifier EOF end |
#add_transformers_to_notifier(code) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 80 def add_transformers_to_notifier(code) if stage.notifier_transformers.any? stage.notifier_transformers.each do |transformer_declaration| code << <<-EOF notifier.add_transformer #{transformer_declaration.transformer}.new(#{transformer_declaration..to_s}) EOF end else code << <<-EOF notifier.add_transformer Batsir::Transformers::JSONOutputTransformer.new EOF end end |
#compile ⇒ Object
10 11 12 13 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 10 def compile klazz_name = "#{stage.name.capitalize.gsub(' ','')}Worker" compile_worker_class(klazz_name) end |
#compile_worker_class(klazz_name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 15 def compile_worker_class(klazz_name) worker_class(klazz_name) do |code| stage.filter_declarations.each do |filter_declaration| add_filter(filter_declaration, code) end stage.conditional_notifiers.each do |conditional_notifier_declaration| conditional_notifier_declaration.compile(code, self) end stage.notifiers.each do |notifier, | .each do || new_notifier(notifier, , code) add_transformers_to_notifier(code) add_notifier(code) end end end end |
#new_notifier(notifier, options, code) ⇒ Object
74 75 76 77 78 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 74 def new_notifier(notifier, , code) code << <<-EOF notifier = #{notifier.to_s}.new(#{.to_s}) EOF end |
#worker_class(klazz_name) {|code| ... } ⇒ Object
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 64 65 66 |
# File 'lib/batsir/compiler/stage_worker_compiler.rb', line 35 def worker_class(klazz_name, &block) 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 yield code code << <<-EOF end include Sidekiq::Worker include Batsir::StageWorker end #{klazz_name}.sidekiq_options(:queue => Batsir::Config.sidekiq_queue) #{klazz_name} EOF end |