Module: ROM::ConfigurationDSL

Included in:
Configuration
Defined in:
lib/rom/configuration_dsl.rb,
lib/rom/configuration_dsl/command.rb,
lib/rom/configuration_dsl/relation.rb,
lib/rom/configuration_dsl/mapper_dsl.rb,
lib/rom/configuration_dsl/command_dsl.rb

Overview

This extends Configuration class with the DSL methods

Defined Under Namespace

Classes: Command, CommandDSL, MapperDSL, Relation

Instance Method Summary collapse

Instance Method Details

#commands(name) ⇒ Object

Command definition DSL

Examples:

setup.commands(:users) do
  define(:create) do
    input NewUserParams
    result :one
  end

  define(:update) do
    input UserParams
    result :many
  end

  define(:delete) do
    result :many
  end
end


51
52
53
# File 'lib/rom/configuration_dsl.rb', line 51

def commands(name, &)
  register_command(*CommandDSL.new(name, default_adapter, &).command_classes)
end

#mappers(&block) ⇒ Object

Mapper definition DSL



58
59
60
# File 'lib/rom/configuration_dsl.rb', line 58

def mappers(&block)
  register_mapper(*MapperDSL.new(self, mapper_classes, block).mapper_classes)
end

#plugin(adapter, spec) ⇒ Plugin

Configures a plugin for a specific adapter to be enabled for all relations

Examples:

config = ROM::Configuration.new(:sql, 'sqlite::memory')

config.plugin(:sql, relations: :instrumentation) do |p|
  p.notifications = MyNotificationsBackend
end

config.plugin(:sql, relations: :pagination)


79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rom/configuration_dsl.rb', line 79

def plugin(adapter, spec, &)
  type, name = spec.flatten(1)
  plugin = plugin_registry[type].adapter(adapter).fetch(name) do
    plugin_registry[type].fetch(name)
  end

  if block_given?
    register_plugin(plugin.configure(&))
  else
    register_plugin(plugin)
  end
end

#plugin_registryObject

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.



93
# File 'lib/rom/configuration_dsl.rb', line 93

def plugin_registry = ::ROM.plugin_registry

#relation(name, options = EMPTY_HASH) ⇒ Object

Relation definition DSL

Examples:

setup.relation(:users) do
  def names
    project(:name)
  end
end


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

def relation(name, options = EMPTY_HASH, &)
  klass_opts = { adapter: default_adapter }.merge(options)
  klass = Relation.build_class(name, klass_opts)
  klass.schema_opts(dataset: name, relation: name)
  klass.class_eval(&) if block_given?
  register_relation(klass)
  klass
end