Module: EvilEvents::Core::Events::EventFactory Private

Defined in:
lib/evil_events/core/events/event_factory.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.1

Constant Summary collapse

UNDEFINED_EVENT_ID =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.1

'unknown'
CLASS_INHERITANCE_STRATEGY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.1

:class_inheritance
PROC_EVAL_STRATEGY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.1

:proc_eval

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_abstract_class(event_type) ⇒ Class{EvilEvents::Core::Events::AbstractEvent}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • event_type (String)

Returns:

Raises:

  • (EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError)

Since:

  • 0.1.1



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/evil_events/core/events/event_factory.rb', line 19

def create_abstract_class(event_type)
  Class.new(AbstractEvent).tap do |klass|
    klass.type(event_type)
    klass.__creation_strategy__ = CLASS_INHERITANCE_STRATEGY

    class << klass
      def inherited(child_class)
        child_class.type(type)
        child_class.__creation_strategy__ = CLASS_INHERITANCE_STRATEGY
        child_class.manage!
      rescue EvilEvents::AlreadyManagedEventClassError
        EvilEvents::Core::Bootstrap[:event_system].unregister_event_class(child_class)
        raise
      end
    end
  end
end

.create_class(event_type, &event_class_definitions) {|AbstractEvent| ... } ⇒ Class{EvilEvents::Core::Events::AbstractEvent}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • event_type (String)
  • event_class_definitions (Proc)

Yields:

Returns:

Raises:

  • (EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError)

Since:

  • 0.1.1



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/evil_events/core/events/event_factory.rb', line 44

def create_class(event_type, &event_class_definitions)
  Class.new(AbstractEvent).tap do |klass|
    begin
      klass.__creation_strategy__ = PROC_EVAL_STRATEGY
      klass.type(event_type)
      klass.manage!
      klass.evaluate(&event_class_definitions) if block_given?
    rescue StandardError
      EvilEvents::Core::Bootstrap[:event_system].unregister_event_class(klass)
      raise
    end
  end
end

.restore_instance(event_class, id: UNDEFINED_EVENT_ID, payload: {}, metadata: {}) ⇒ EvilEvents::Core::Events::AbstractEvent

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • event_class (Class{EvilEvents::Core::Events::AbstractEvent})
  • id (Hash) (defaults to: UNDEFINED_EVENT_ID)

    a customizable set of options

  • payload (Hash) (defaults to: {})

    a customizable set of options

  • metadata (Hash) (defaults to: {})

    a customizable set of options

Options Hash (id:):

  • (String, Object)

Options Hash (payload:):

  • (Hash)

Options Hash (metadata:):

  • (Hash)

Returns:

Since:

  • 0.1.1



66
67
68
# File 'lib/evil_events/core/events/event_factory.rb', line 66

def restore_instance(event_class, id: UNDEFINED_EVENT_ID, payload: {}, metadata: {})
  event_class.new(id: id || UNDEFINED_EVENT_ID, payload: payload, metadata: )
end

Instance Method Details

#create_abstract_class(event_type) ⇒ Class{EvilEvents::Core::Events::AbstractEvent} (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • event_type (String)

Returns:

Raises:

  • (EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError)

Since:

  • 0.1.1



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/evil_events/core/events/event_factory.rb', line 19

def create_abstract_class(event_type)
  Class.new(AbstractEvent).tap do |klass|
    klass.type(event_type)
    klass.__creation_strategy__ = CLASS_INHERITANCE_STRATEGY

    class << klass
      def inherited(child_class)
        child_class.type(type)
        child_class.__creation_strategy__ = CLASS_INHERITANCE_STRATEGY
        child_class.manage!
      rescue EvilEvents::AlreadyManagedEventClassError
        EvilEvents::Core::Bootstrap[:event_system].unregister_event_class(child_class)
        raise
      end
    end
  end
end

#create_class(event_type, &event_class_definitions) {|AbstractEvent| ... } ⇒ Class{EvilEvents::Core::Events::AbstractEvent} (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • event_type (String)
  • event_class_definitions (Proc)

Yields:

Returns:

Raises:

  • (EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError)

Since:

  • 0.1.1



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/evil_events/core/events/event_factory.rb', line 44

def create_class(event_type, &event_class_definitions)
  Class.new(AbstractEvent).tap do |klass|
    begin
      klass.__creation_strategy__ = PROC_EVAL_STRATEGY
      klass.type(event_type)
      klass.manage!
      klass.evaluate(&event_class_definitions) if block_given?
    rescue StandardError
      EvilEvents::Core::Bootstrap[:event_system].unregister_event_class(klass)
      raise
    end
  end
end

#restore_instance(event_class, id: UNDEFINED_EVENT_ID, payload: {}, metadata: {}) ⇒ EvilEvents::Core::Events::AbstractEvent (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Options Hash (id:):

  • (String, Object)

Options Hash (payload:):

  • (Hash)

Options Hash (metadata:):

  • (Hash)

Returns:

Since:

  • 0.1.1



66
67
68
# File 'lib/evil_events/core/events/event_factory.rb', line 66

def restore_instance(event_class, id: UNDEFINED_EVENT_ID, payload: {}, metadata: {})
  event_class.new(id: id || UNDEFINED_EVENT_ID, payload: payload, metadata: )
end