Sha256: c74e052397502f7b7fca41e32dfaf322f0151b47422654aede8346ec56ee29db

Contents?: true

Size: 1.01 KB

Versions: 35

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'evostream/event/event/events'

module Evostream
  # Reacts to event
  class Event
    EVENTS = Evostream::Events::Event.descendants

    def initialize(type, payload)
      @payload = payload
      @model = type.sub(/^(\w)/, &:capitalize)
    end

    def execute_action
      klass = "Evostream::Events::#{@model}".constantize
      Evostream.logger "Execute Action : #{klass}"
      execute_klass(klass) if EVENTS.include?(klass)
    end

    private

    def execute_klass(klass)
      name_flux = extract_name_flux
      Evostream.logger "Name Flux : #{name_flux}"
      Evostream.logger "Event : #{klass}"
      case [klass]
      when [Evostream::Events::OutStreamCreated]
        klass.new(name_flux, @payload).execute
      else
        # when [Evostream::Events::InStreamCreated]
        # when [Evostream::Events::InStreamClosed]
        klass.new(name_flux).execute
      end
    end

    def extract_name_flux
      @payload[:name].gsub(Evostream::Service.name, '')
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
evostream-event-2.0.3 lib/evostream/event/event.rb
evostream-event-2.0.3.pre.1265906291 lib/evostream/event/event.rb
evostream-event-2.0.3.pre.1265756691 lib/evostream/event/event.rb
evostream-event-2.0.3.pre.1265752332 lib/evostream/event/event.rb
evostream-event-2.0.2 lib/evostream/event/event.rb
evostream-event-2.0.2.pre.994185738 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.994170151 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.994165179 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.994159616 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.856454391 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.856447460 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.856441003 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.816370746 lib/evostream/event/event.rb
evostream-event-2.0.0.pre.809444619 lib/evostream/event/event.rb
evostream-event-1.0.3 lib/evostream/event/event.rb
evostream-event-1.0.3.pre.95 lib/evostream/event/event.rb
evostream-event-1.0.3.pre.93 lib/evostream/event/event.rb
evostream-event-1.0.3.pre.91 lib/evostream/event/event.rb
evostream-event-1.0.3.pre.83 lib/evostream/event/event.rb
evostream-event-1.0.2 lib/evostream/event/event.rb