Module: ROM::Components::DSL
- Defined in:
- lib/rom/components/dsl.rb,
lib/rom/components/dsl/core.rb,
lib/rom/components/dsl/view.rb,
lib/rom/components/dsl/mapper.rb,
lib/rom/components/dsl/schema.rb,
lib/rom/components/dsl/command.rb,
lib/rom/components/dsl/dataset.rb,
lib/rom/components/dsl/gateway.rb,
lib/rom/components/dsl/relation.rb,
lib/rom/components/dsl/association.rb,
lib/rom/compat/components/dsl/schema.rb
Defined Under Namespace
Classes: Association, Command, Core, Dataset, Gateway, Mapper, Relation, Schema, View
Instance Method Summary collapse
-
#associations(source: config.component.id, namespace: source, **options, &block) ⇒ Array<Components::Association>
Define associations for a relation.
-
#commands(namespace, **options, &block) ⇒ Object
Command definition DSL.
-
#dataset(id = nil, **options, &block) ⇒ Object
Set or get custom dataset block.
- #gateway(id, **options, &block) ⇒ Object
-
#mappers(namespace = nil, **options, &block) ⇒ Object
Mapper definition DSL.
-
#plugin(*args, &block) ⇒ Plugin
Configures a plugin for a specific adapter to be enabled for all relations.
-
#relation(id, dataset: id, **options, &block) ⇒ Object
Relation definition DSL.
-
#schema(id = nil, **options, &block) ⇒ Schema
Specify a relation schema.
-
#view(id, *args, &block) ⇒ Symbol
Define a relation view with a specific schema.
Instance Method Details
#associations(source: config.component.id, namespace: source, **options, &block) ⇒ Array<Components::Association>
Define associations for a relation
152 153 154 155 |
# File 'lib/rom/components/dsl.rb', line 152 def associations(source: config.component.id, namespace: source, **, &block) __dsl__(DSL::Association, source: source, namespace: namespace, **, &block) components.associations end |
#commands(namespace, **options, &block) ⇒ Object
Command definition DSL
177 178 179 180 |
# File 'lib/rom/components/dsl.rb', line 177 def commands(namespace, **, &block) __dsl__(DSL::Command, namespace: namespace, relation: namespace, **, &block) components.commands end |
#dataset(id = nil, **options, &block) ⇒ Object
Set or get custom dataset block
This block will be evaluated when a relation is instantiated and registered in a relation registry.
31 32 33 |
# File 'lib/rom/components/dsl.rb', line 31 def dataset(id = nil, **, &block) __dsl__(DSL::Dataset, id: id, **, &block) end |
#gateway(id, **options, &block) ⇒ Object
231 232 233 |
# File 'lib/rom/components/dsl.rb', line 231 def gateway(id, **, &block) __dsl__(DSL::Gateway, id: id, **, &block) end |
#mappers(namespace = nil, **options, &block) ⇒ Object
Mapper definition DSL
185 186 187 188 |
# File 'lib/rom/components/dsl.rb', line 185 def mappers(namespace = nil, **, &block) __dsl__(DSL::Mapper, namespace: namespace, relation: namespace, **, &block) components.mappers end |
#plugin(*args, &block) ⇒ Plugin
Configures a plugin for a specific adapter to be enabled for all relations
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/rom/components/dsl.rb', line 207 def plugin(*args, &block) case args.size when 2 adapter, spec = args type, name = spec.flatten(1) # TODO: plugin types are singularized, so this is not consistent # with the configuration DSL for plugins that uses plural # names of the components - this should be unified plugin = ROM .plugins[Inflector.singularize(type)].adapter(adapter).fetch(name) .configure(&block) config.component.plugins << plugin plugin when 1 plugin(self.adapter, *args) else raise ArgumentError, "+plugin+ accepts either 1 or 2 arguments (#{args.size} given)" end end |
#relation(id, dataset: id, **options, &block) ⇒ Object
Relation definition DSL
71 72 73 |
# File 'lib/rom/components/dsl.rb', line 71 def relation(id, dataset: id, **, &block) __dsl__(DSL::Relation, id: id, dataset: dataset, **, &block) end |
#schema(id = nil, **options, &block) ⇒ Schema
Specify a relation schema
With a schema defined commands will set up a type-safe input handler automatically
57 58 59 |
# File 'lib/rom/components/dsl.rb', line 57 def schema(id = nil, **, &block) __dsl__(DSL::Schema, id: id, dataset: id, **, &block) end |
#view(name, schema, &block) ⇒ Symbol #view(name, &block) ⇒ Symbol
Define a relation view with a specific schema
This method should only be used in cases where a given adapter doesn't support automatic schema projection at run-time.
122 123 124 125 |
# File 'lib/rom/components/dsl.rb', line 122 def view(id, *args, &block) __dsl__(DSL::View, id: id, args: args, &block) id end |