Class: ROM::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/setup.rb,
lib/rom/compat/setup.rb

Overview

Setup objects collect component classes during setup/finalization process

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notifications) ⇒ Setup

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 a new instance of Setup.


23
24
25
26
27
28
# File 'lib/rom/setup.rb', line 23

def initialize(notifications)
  @plugins = []
  @notifications = notifications
  @inflector = Inflector
  @components = {relations: [], commands: [], mappers: []}
end

Instance Attribute Details

#componentsObject (readonly)

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.


20
21
22
# File 'lib/rom/setup.rb', line 20

def components
  @components
end

#inflectorObject

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.


17
18
19
# File 'lib/rom/setup.rb', line 17

def inflector
  @inflector
end

#notificationsObject (readonly)

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.


14
15
16
# File 'lib/rom/setup.rb', line 14

def notifications
  @notifications
end

#pluginsObject (readonly)

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.


11
12
13
# File 'lib/rom/setup.rb', line 11

def plugins
  @plugins
end

Instance Method Details

#auto_register(directory, **options) ⇒ Setup

Enable auto-registration for a given setup object

Parameters:

  • directory (String, Pathname)

    The root path to components

  • options (Hash)

Options Hash (**options):

  • :namespace (Boolean)

    Toggle root namespace

Returns:


39
40
41
# File 'lib/rom/setup.rb', line 39

def auto_register(directory, **options)
  @auto_register ||= [directory, {**options}]
end

#auto_registration(directory, **options) ⇒ Setup

Deprecated.

Enable auto-registration for a given setup object

Parameters:

  • directory (String, Pathname)

    The root path to components

  • options (Hash)

Options Hash (**options):

  • :namespace (Boolean, String)

    Toggle root namespace or provide a custom namespace name

Returns:


22
23
24
25
26
27
28
# File 'lib/rom/compat/setup.rb', line 22

def auto_registration(directory, **options)
  auto_registration = AutoRegistration.new(directory, inflector: inflector, **options)
  auto_registration.relations.map { |r| register_relation(r) }
  auto_registration.commands.map { |r| register_command(r) }
  auto_registration.mappers.map { |r| register_mapper(r) }
  self
end

#command_classesObject

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.


70
71
72
# File 'lib/rom/setup.rb', line 70

def command_classes
  @command_classes ||= components[:commands].concat(loader&.commands || [])
end

#mapper_classesObject

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.


75
76
77
# File 'lib/rom/setup.rb', line 75

def mapper_classes
  @mapper_classes ||= components[:mappers].concat(loader&.mappers || [])
end

#register_command(*klasses) ⇒ Object

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.

Command sub-classes are being registered with this method during setup


60
61
62
# File 'lib/rom/setup.rb', line 60

def register_command(*klasses)
  components[:commands].concat(klasses)
end

#register_mapper(*klasses) ⇒ Object

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.

Mapper sub-classes are being registered with this method during setup


53
54
55
# File 'lib/rom/setup.rb', line 53

def register_mapper(*klasses)
  components[:mappers].concat(klasses)
end

#register_plugin(plugin) ⇒ Object

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.


80
81
82
# File 'lib/rom/setup.rb', line 80

def register_plugin(plugin)
  plugins << plugin
end

#register_relation(*klasses) ⇒ Object

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.

Relation sub-classes are being registered with this method during setup


46
47
48
# File 'lib/rom/setup.rb', line 46

def register_relation(*klasses)
  components[:relations].concat(klasses)
end

#relation_classesObject

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.


65
66
67
# File 'lib/rom/setup.rb', line 65

def relation_classes
  @relation_classes ||= components[:relations].concat(loader&.relations || [])
end