Sha256: 20841086411e53cfdb1a9bfbe04da82bccaeb9c683c686451dfba544ec160ad8

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

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

module ROM
  class Finalize
    class FinalizeCommands
      # 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)
        @relations = relations
        @gateways = gateways
        @command_classes = command_classes
      end

      # @return [Hash]
      #
      # @api private
      def run!
        registry = @command_classes.each_with_object({}) do |klass, h|
          rel_name = klass.relation
          next unless rel_name

          relation = @relations[rel_name]
          name = klass.register_as || klass.default_name

          gateway = @gateways[relation.class.gateway]
          gateway.extend_command_class(klass, relation.dataset)

          klass.extend_for_relation(relation) if klass.restrictable

          (h[rel_name] ||= {})[name] = klass.build(relation)
        end

        commands = registry.each_with_object({}) do |(name, rel_commands), h|
          h[name] = CommandRegistry.new(name, rel_commands)
        end

        Registry.new(commands)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rom-3.3.3 lib/rom/setup/finalize/finalize_commands.rb
rom-3.3.2 lib/rom/setup/finalize/finalize_commands.rb
rom-3.3.1 lib/rom/setup/finalize/finalize_commands.rb
rom-3.3.0 lib/rom/setup/finalize/finalize_commands.rb
rom-3.2.3 lib/rom/setup/finalize/finalize_commands.rb
rom-3.2.2 lib/rom/setup/finalize/finalize_commands.rb
rom-3.2.1 lib/rom/setup/finalize/finalize_commands.rb
rom-3.2.0 lib/rom/setup/finalize/finalize_commands.rb
rom-3.1.0 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.3 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.2 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.1 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.0 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.0.rc2 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.0.rc1 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.0.beta3 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.0.beta2 lib/rom/setup/finalize/finalize_commands.rb
rom-3.0.0.beta1 lib/rom/setup/finalize/finalize_commands.rb