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, **options) ⇒ 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


21
22
23
24
25
26
27
# File 'lib/rom/setup/finalize/finalize_commands.rb', line 21

def initialize(relations, gateways, command_classes, **options)
  @relations = relations
  @gateways = gateways
  @command_classes = command_classes
  @inflector = options.fetch(:inflector, Inflector)
  @notifications = options.fetch(:notifications)
end

Instance Attribute Details

#inflectorObject (readonly)

Returns the value of attribute inflector


12
13
14
# File 'lib/rom/setup/finalize/finalize_commands.rb', line 12

def inflector
  @inflector
end

#notificationsObject (readonly)

Returns the value of attribute notifications


10
11
12
# File '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)

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
63
64
65
66
67
68
69
70
71
# File 'lib/rom/setup/finalize/finalize_commands.rb', line 32

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,
    inflector: inflector
  )

  @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