Class: Cucumber::Core::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-core-11.0.0/lib/cucumber/core/event.rb

Class Method Summary collapse

Class Method Details

.event_idObject

 @return [Symbol] the underscored name of the class to be used   as the key in an event registry.



43
44
45
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-core-11.0.0/lib/cucumber/core/event.rb', line 43

def event_id
  underscore(self.name.split("::").last).to_sym
end

.new(*attributes) ⇒ Object

Macro to generate new sub-classes of Cucumber::Core::Event with attribute readers.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-core-11.0.0/lib/cucumber/core/event.rb', line 7

def self.new(*attributes)
  # Use normal constructor for subclasses of Event
  return super if self.ancestors.index(Event) > 0

  Class.new(Event) do
    attr_reader(*attributes)

    define_method(:initialize) do |*args|
      attributes.zip(args) do |name, value|
        instance_variable_set "@#{name}".to_sym, value
      end
    end

    define_method(:attributes) do
      attributes.map { |attribute| self.send(attribute) }
    end

    define_method(:to_h) do
      attributes.reduce({}) { |result, attribute|
        value = self.send(attribute)
        result[attribute] = value
        result
      }
    end

    define_method(:event_id) do
      self.class.event_id
    end
  end
end