class EventSourcery::Rails::Command

Attributes

aggregate_id[R]

Public Class Methods

attributes(*attributes) click to toggle source
# File lib/event_sourcery/rails/command.rb, line 12
      def self.attributes(*attributes)
        attr_reader *attributes

        method_arguments = attributes.map { |arg| "#{arg}:" }.join(', ')
        method_assignments = attributes.map { |arg| "@#{arg} = #{arg}" }.join(';')
        method_attrs_to_hash = attributes.map { |arg| "#{arg}: #{arg}" }.join(',')

        class_eval <<~CODE
          def initialize(aggregate_id:, #{method_arguments})
            @aggregate_id = aggregate_id
            #{method_assignments}
          end

          def to_hash
            {#{method_attrs_to_hash}}
          end
        CODE
      end
new(aggregate_id:) click to toggle source
# File lib/event_sourcery/rails/command.rb, line 8
def initialize(aggregate_id:)
  @aggregate_id = aggregate_id
end