Sha256: ce3e4c18e093415b87a14911ac7da522ff70942930892bb52534b42d7f8dd4e2

Contents?: true

Size: 1.82 KB

Versions: 13

Compression:

Stored size: 1.82 KB

Contents

module Euston
  module AggregateRootDslMethods
    extend ActiveSupport::Concern
    include Euston::AggregateRootPrivateMethodNames

    module ClassMethods
      def applies event, version = 1, &block
        define_private_method applies_method_name(event, version), &block
      end

      def consumes *arguments, &block #*args is an array of symbols plus an optional options hash at the end
        commands, options = [], {}

        while (arg = arguments.shift) do
          commands << { :name => arg, :version => 1 } if arg.is_a?(Symbol)
          commands.last[:version] = arg if arg.is_a?(Integer)
          options = arg if arg.is_a?(Hash)
        end

        commands.each do |command|
          define_private_method consumes_method_name(command[:name], command[:version]), &block
          map_command :map_command_as_aggregate_method, self, command[:name], options
        end
      end

      def created_by command, version = 1, options = {}, &block
        define_method consumes_method_name(command, version), &block

        map_command :map_command_as_aggregate_constructor, self, command, options
      end

      def load_snapshot version, &block
        define_private_method load_snapshot_method_name(version), &block
      end

      def take_snapshot version, &block
        define_private_method take_snapshot_method_name(version), &block
      end

      private

      def define_private_method name, &block
        define_method name, &(block || method(:null_block))
      end

      def map_command(entry_point, type, command, opts)
        id = opts.has_key?(:id) ? opts[:id] : :id
        to_i = opts.key?(:to_i) ? opts[:to_i] : []

        Euston::AggregateCommandMap.send entry_point, type, command, id, to_i
      end

      def null_block *args
        # block-less definitions get pointed here
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
euston-1.2.10 lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.10-java lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.9-java lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.9 lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.8 lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.8-java lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.7-java lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.7 lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.6 lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.5-java lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.5 lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.4-java lib/euston/aggregate_root_dsl_methods.rb
euston-1.2.4 lib/euston/aggregate_root_dsl_methods.rb