Sha256: 0052b6e93754ced7a8892f5f5d933fd91fab4566bba3417c16bedf0b86c3595e

Contents?: true

Size: 1.69 KB

Versions: 8

Compression:

Stored size: 1.69 KB

Contents

require 'rom/registry'
require 'rom/command_compiler'
require 'rom/command_registry'

module ROM
  class Finalize
    class FinalizeCommands
      attr_reader :notifications

      # Build command registry hash for provided relations
      #
      # @param [RelationRegistry] relations registry
      # @param [Hash] gateways
      # @param [Array] command_classes a list of command subclasses
      #
      # @api private
      def initialize(relations, gateways, command_classes, notifications)
        @relations = relations
        @gateways = gateways
        @command_classes = command_classes
        @notifications = notifications
      end

      # @return [Hash]
      #
      # @api private
      def run!
        commands = @command_classes.map do |klass|
          relation = @relations[klass.relation]
          gateway = @gateways[relation.gateway]

          notifications.trigger(
            'configuration.commands.class.before_build',
            command: klass, gateway: gateway, dataset: relation.dataset
          )

          klass.extend_for_relation(relation) if klass.restrictable

          klass.build(relation)
        end

        registry = Registry.new({})
        compiler = CommandCompiler.new(@gateways, @relations, registry, notifications)

        @relations.each do |(name, relation)|
          commands.
            select { |c| c.relation.name == relation.name }.
            each { |c| relation.commands.elements[c.class.register_as || c.class.default_name] = c }

          relation.commands.set_compiler(compiler)
          relation.commands.set_mappers(relation.mappers)

          registry.elements[name] = relation.commands
        end

        registry
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rom-core-4.0.2 lib/rom/setup/finalize/finalize_commands.rb
rom-core-4.0.1 lib/rom/setup/finalize/finalize_commands.rb
rom-core-4.0.0 lib/rom/setup/finalize/finalize_commands.rb
rom-core-4.0.0.rc2 lib/rom/setup/finalize/finalize_commands.rb
rom-core-4.0.0.rc1 lib/rom/setup/finalize/finalize_commands.rb
rom-core-4.0.0.beta3 lib/rom/setup/finalize/finalize_commands.rb
rom-core-4.0.0.beta2 lib/rom/setup/finalize/finalize_commands.rb
rom-core-4.0.0.beta1 lib/rom/setup/finalize/finalize_commands.rb