Sha256: 50e4c4c6e4d7ff6bf765b1834970bd212f48616211badb2c326971ee49a757e5

Contents?: true

Size: 846 Bytes

Versions: 8

Compression:

Stored size: 846 Bytes

Contents

# coding: utf-8
# frozen_string_literal: true

module Stealth
  module Flow
    class EventCollection < Hash

      def [](name)
        super name.to_sym # Normalize to symbol
      end

      def push(name, event)
        key = name.to_sym
        self[key] ||= []
        self[key] << event
      end

      def flat
        self.values.flatten.uniq do |event|
          [:name, :transitions_to, :meta, :action].map { |m| event.send(m) }
        end
      end

      def include?(name_or_obj)
        case name_or_obj
        when Event
          flat.include? name_or_obj
        else
          !(self[name_or_obj].nil?)
        end
      end

      def first_applicable(name, object_context)
        (self[name] || []).detect do |event|
          event.condition_applicable?(object_context) && event
        end
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stealth-0.9.8 lib/stealth/flow/event_collection.rb
stealth-0.9.7 lib/stealth/flow/event_collection.rb
stealth-0.9.6 lib/stealth/flow/event_collection.rb
stealth-0.9.5 lib/stealth/flow/event_collection.rb
stealth-0.9.4 lib/stealth/flow/event_collection.rb
stealth-0.9.3 lib/stealth/flow/event_collection.rb
stealth-0.9.2 lib/stealth/flow/event_collection.rb
stealth-0.9.1 lib/stealth/flow/event_collection.rb