Sha256: 4446d30993050c472b386f3f5b81f3eaa8b3831d7fec0abc465945c91a42ebfd

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require 'rom/setup/auto_registration'

module ROM
  class Setup
    # @return [Array] registered relation subclasses
    #
    # @api private
    attr_reader :relation_classes

    # @return [Array] registered mapper subclasses
    #
    # @api private
    attr_reader :mapper_classes

    # @return [Array] registered command subclasses
    #
    # @api private
    attr_reader :command_classes

    # @api private
    attr_reader :plugins

    # @api private
    attr_reader :notifications

    # @api private
    def initialize(notifications)
      @relation_classes = []
      @command_classes = []
      @mapper_classes = []
      @plugins = []
      @notifications = notifications
    end

    # Relation sub-classes are being registered with this method during setup
    #
    # @api private
    def register_relation(*klasses)
      klasses.reduce(@relation_classes, :<<)
    end

    # Mapper sub-classes are being registered with this method during setup
    #
    # @api private
    def register_mapper(*klasses)
      klasses.reduce(@mapper_classes, :<<)
    end

    # Command sub-classes are being registered with this method during setup
    #
    # @api private
    def register_command(*klasses)
      klasses.reduce(@command_classes, :<<)
    end

    # @api private
    def register_plugin(plugin)
      plugins << plugin
    end

    def auto_registration(directory, options = {})
      auto_registration = AutoRegistration.new(directory, options)
      auto_registration.relations.map { |r| register_relation(r) }
      auto_registration.commands.map { |r| register_command(r) }
      auto_registration.mappers.map { |r| register_mapper(r) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-core-4.0.0.beta3 lib/rom/setup.rb
rom-core-4.0.0.beta2 lib/rom/setup.rb
rom-core-4.0.0.beta1 lib/rom/setup.rb