Sha256: bca1146d7c2409424606c416ad4fc78e7f9758364c03194ae4d91979f62506d6

Contents?: true

Size: 926 Bytes

Versions: 16

Compression:

Stored size: 926 Bytes

Contents

module Larva
  class Processor
    def self.process(message)
      new(message).process_with_logging
    end

    attr_accessor :message, :action, :entity, :id
    def initialize(message)
      @message = message
      @action = message[:action]
      @entity = message[:entity]
      @id = message[:id]
    end

    def process_with_logging
      Propono.config.logger.info "Processing message: #{message}"
      meta_process || normal_process
    end

    private

    def meta_process
      meta_method = "#{entity}_#{action}"
      if respond_to? meta_method
        self.send(meta_method)
        true
      else
        false
      end
    end

    def normal_process
      if respond_to?(:process) && self.process
        Propono.config.logger.info "Message Processed: #{message}"
      else
        Propono.config.logger.info "Unrecognized event type, entity: #{entity} action: #{action}."
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
larva-1.0.0 lib/larva/processor.rb
larva-0.9.2 lib/larva/processor.rb
larva-0.9.1 lib/larva/processor.rb
larva-0.9.0 lib/larva/processor.rb
larva-0.8.0 lib/larva/processor.rb
larva-0.7.3 lib/larva/processor.rb
larva-0.7.2 lib/larva/processor.rb
larva-0.7.1 lib/larva/processor.rb
larva-0.7.0 lib/larva/processor.rb
larva-0.6.4 lib/larva/processor.rb
larva-0.6.3 lib/larva/processor.rb
larva-0.6.2 lib/larva/processor.rb
larva-0.6.1 lib/larva/processor.rb
larva-0.6.0 lib/larva/processor.rb
larva-0.5.0 lib/larva/processor.rb
larva-0.4.1 lib/larva/processor.rb