Class: ROM::Finalize::FinalizeCommands

Inherits:
Object
  • Object
show all
Defined in:
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



17
18
19
20
21
22
# File 'lib/rom/setup/finalize/finalize_commands.rb', line 17

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.



8
9
10
# File 'lib/rom/setup/finalize/finalize_commands.rb', line 8

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)


27
28
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
# File 'lib/rom/setup/finalize/finalize_commands.rb', line 27

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)|
    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