Sha256: ad3f8d67d5057b3c64d94ab3542af9d1c5590535232f469fed13ce92e85e7855

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

module Sandthorn
  module BoundedContext
    module ClassMethods
      def aggregate_types
        @aggregate_list = p_aggregate_types(self)
      end

      private
      
      def p_aggregate_types(bounded_context_module)
        return [] unless bounded_context_module.respond_to?(:constants)
        
        classes = classes_in(bounded_context_module)
        aggregate_list = classes.select { |item| item.include?(Sandthorn::AggregateRoot) }
        modules = modules_in(bounded_context_module, classes)
        
        aggregate_list += modules.flat_map { |m| p_aggregate_types(m) }
        
        aggregate_list
      end

      def classes_in(namespace)
        namespace.constants.map(&namespace.method(:const_get)).grep(Class)
      end

      def modules_in(namespace, classes)
        namespace.constants.map(&namespace.method(:const_get)).grep(Module).delete_if do |m| 
          classes.include?(m) || m == Sandthorn::BoundedContext::ClassMethods
        end
      end
    end

    extend ClassMethods
    
    def self.included( other )
      other.extend( ClassMethods )
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sandthorn-1.3.0 lib/sandthorn/bounded_context.rb
sandthorn-1.2.0 lib/sandthorn/bounded_context.rb
sandthorn-1.1.0 lib/sandthorn/bounded_context.rb
sandthorn-1.0.0 lib/sandthorn/bounded_context.rb
sandthorn-0.13.0 lib/sandthorn/bounded_context.rb
sandthorn-0.12.0 lib/sandthorn/bounded_context.rb
sandthorn-0.11.0 lib/sandthorn/bounded_context.rb
sandthorn-0.10.3 lib/sandthorn/bounded_context.rb
sandthorn-0.10.2 lib/sandthorn/bounded_context.rb
sandthorn-0.10.1 lib/sandthorn/bounded_context.rb
sandthorn-0.10.0 lib/sandthorn/bounded_context.rb
sandthorn-0.9.2 lib/sandthorn/bounded_context.rb
sandthorn-0.9.1 lib/sandthorn/bounded_context.rb
sandthorn-0.9.0 lib/sandthorn/bounded_context.rb