Module: ROM::Repository::ClassInterface
- Included in:
- ROM::Repository
- Defined in:
- repository/lib/rom/repository/class_interface.rb
Overview
Class-level APIs for repositories
Instance Method Summary collapse
-
#[](name) ⇒ Class
Create a root-repository class and set its root relation.
-
#commands(*names, mapper: nil, use: nil, plugins_options: EMPTY_HASH, **opts) ⇒ Array<Symbol>
Defines command methods on a root repository.
-
#new(container = nil, **options) ⇒ Object
Initialize a new repository object, establishing configured relation proxies from the passed container.
- #use(plugin, **options) ⇒ Object
Instance Method Details
#[](name) ⇒ Class
Create a root-repository class and set its root relation
25 26 27 28 29 30 31 |
# File 'repository/lib/rom/repository/class_interface.rb', line 25 def [](name) fetch_or_store(name) do klass = Class.new(self < Repository::Root ? self : Repository::Root) klass.root(name) klass end end |
#commands(*names, mapper: nil, use: nil, plugins_options: EMPTY_HASH, **opts) ⇒ Array<Symbol>
Defines command methods on a root repository
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'repository/lib/rom/repository/class_interface.rb', line 101 def commands(*names, mapper: nil, use: nil, plugins_options: EMPTY_HASH, **opts) if names.any? || opts.any? @commands = names + opts.to_a @commands.each do |spec| type, *view = Array(spec).flatten if !view.empty? define_restricted_command_method(type, view, mapper: mapper, use: use, plugins_options: ) else define_command_method(type, mapper: mapper, use: use, plugins_options: ) end end else @commands ||= [] end end |
#new(container, **options) ⇒ Object #new(**options) ⇒ Object
Initialize a new repository object, establishing configured relation proxies from the passed container
54 55 56 57 58 59 60 61 62 63 |
# File 'repository/lib/rom/repository/class_interface.rb', line 54 def new(container = nil, **) container ||= .fetch(:container) unless relation_reader relation_reader(RelationReader.new(self, container.relations.elements.keys)) include(relation_reader) end super(**, container: container) end |
#use(plugin, **options) ⇒ Object
120 121 122 |
# File 'repository/lib/rom/repository/class_interface.rb', line 120 def use(plugin, **) ROM.plugin_registry[:repository].fetch(plugin).apply_to(self, **) end |