Class: ROM::Finalize::FinalizeCommands

Inherits:
Object
  • Object
show all
Defined in:
core/lib/rom/setup/finalize/finalize_commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relations, gateways, command_classes, notifications) ⇒ FinalizeCommands

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build command registry hash for provided relations

Parameters:

  • relations (RelationRegistry)

    registry

  • gateways (Hash)
  • command_classes (Array)

    a list of command subclasses



19
20
21
22
23
24
# File 'core/lib/rom/setup/finalize/finalize_commands.rb', line 19

def initialize(relations, gateways, command_classes, notifications)
  @relations = relations
  @gateways = gateways
  @command_classes = command_classes
  @notifications = notifications
end

Instance Attribute Details

#notificationsObject (readonly)

Returns the value of attribute notifications.



10
11
12
# File 'core/lib/rom/setup/finalize/finalize_commands.rb', line 10

def notifications
  @notifications
end

Instance Method Details

#run!Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'core/lib/rom/setup/finalize/finalize_commands.rb', line 29

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, adapter: relation.adapter
    )

    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)|
    rel_commands = commands.select { |c| c.relation.name == relation.name }

    rel_commands.each do |command|
      identifier = command.class.register_as || command.class.default_name
      relation.commands.elements[identifier] = command
    end

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

    registry.elements[name] = relation.commands
  end

  registry
end