Class: MilkTea::Types::Event

Inherits:
Base
  • Object
show all
Defined in:
lib/milk_tea/core/types/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accept, #bitwise?, #boolean?, #field_c_name, #float?, #integer?, #numeric?, #sendable?, #void?

Constructor Details

#initialize(name, capacity:, payload_type: nil, module_name: nil, visibility: :private, owner_type_name: nil) ⇒ Event

Returns a new instance of Event.



741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
# File 'lib/milk_tea/core/types/types.rb', line 741

def initialize(name, capacity:, payload_type: nil, module_name: nil, visibility: :private, owner_type_name: nil)
  @name = name
  @capacity = capacity
  @payload_type = payload_type
  @module_name = module_name
  @visibility = visibility
  @owner_type_name = owner_type_name
  @linkage_name = begin
    parts = ["mt_event"]
    parts << module_name&.gsub(/[^A-Za-z0-9_]+/, "_")
    parts << owner_type_name&.gsub(/[^A-Za-z0-9_]+/, "_")
    parts << name.gsub(/[^A-Za-z0-9_]+/, "_")
    parts << payload_type.to_s.gsub(/[^A-Za-z0-9_]+/, "_") if payload_type
    parts << capacity.to_s
    parts.compact.reject(&:empty?).join("_")
  end
  @hash = [self.class, name, capacity, payload_type, module_name, visibility, owner_type_name].hash
  freeze
end

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity.



739
740
741
# File 'lib/milk_tea/core/types/types.rb', line 739

def capacity
  @capacity
end

#hashObject (readonly)

Returns the value of attribute hash.



773
774
775
# File 'lib/milk_tea/core/types/types.rb', line 773

def hash
  @hash
end

#linkage_nameObject (readonly)

Returns the value of attribute linkage_name.



739
740
741
# File 'lib/milk_tea/core/types/types.rb', line 739

def linkage_name
  @linkage_name
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



739
740
741
# File 'lib/milk_tea/core/types/types.rb', line 739

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name.



739
740
741
# File 'lib/milk_tea/core/types/types.rb', line 739

def name
  @name
end

#owner_type_nameObject (readonly)

Returns the value of attribute owner_type_name.



739
740
741
# File 'lib/milk_tea/core/types/types.rb', line 739

def owner_type_name
  @owner_type_name
end

#payload_typeObject (readonly)

Returns the value of attribute payload_type.



739
740
741
# File 'lib/milk_tea/core/types/types.rb', line 739

def payload_type
  @payload_type
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



739
740
741
# File 'lib/milk_tea/core/types/types.rb', line 739

def visibility
  @visibility
end

Instance Method Details

#childrenObject



785
786
787
# File 'lib/milk_tea/core/types/types.rb', line 785

def children
  [payload_type].compact
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


761
762
763
764
765
766
767
768
769
# File 'lib/milk_tea/core/types/types.rb', line 761

def eql?(other)
  other.is_a?(Event) &&
    other.name == name &&
    other.capacity == capacity &&
    other.payload_type == payload_type &&
    other.module_name == module_name &&
    other.visibility == visibility &&
    other.owner_type_name == owner_type_name
end

#hidden_field_nameObject



775
776
777
# File 'lib/milk_tea/core/types/types.rb', line 775

def hidden_field_name
  "__event_#{name}"
end

#to_sObject



779
780
781
782
783
# File 'lib/milk_tea/core/types/types.rb', line 779

def to_s
  label = owner_type_name ? "#{owner_type_name}.#{name}" : name
  payload = payload_type ? "(#{payload_type})" : ""
  "event #{label}[#{capacity}]#{payload}"
end