Module: ROM::Repository::ClassInterface
- Included in:
- ROM::Repository
- Defined in:
- 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, **opts) ⇒ Array<Symbol>
Defines command methods on a root repository.
-
#inherited(klass) ⇒ Object
private
Inherits configured relations and commands.
-
#relations(*names) ⇒ Array<Symbol>
Define which relations your repository is going to use.
Instance Method Details
#[](name) ⇒ Class
Create a root-repository class and set its root relation
19 20 21 22 23 24 |
# File 'lib/rom/repository/class_interface.rb', line 19 def [](name) klass = Class.new(self < Repository::Root ? self : Repository::Root) klass.relations(name) klass.root(name) klass end |
#commands(*names, mapper: nil, use: nil, **opts) ⇒ Array<Symbol>
Defines command methods on a root repository
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rom/repository/class_interface.rb', line 93 def commands(*names, mapper: nil, use: nil, **opts) if names.any? || opts.any? @commands = names + opts.to_a @commands.each do |spec| type, *view = Array(spec).flatten if view.size > 0 define_restricted_command_method(type, view, mapper: mapper, use: use) else define_command_method(type, mapper: mapper, use: use) end end else @commands || [] end end |
#inherited(klass) ⇒ 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.
Inherits configured relations and commands
29 30 31 32 33 34 35 36 |
# File 'lib/rom/repository/class_interface.rb', line 29 def inherited(klass) super return if self === Repository klass.relations(*relations) klass.commands(*commands) end |
#relations(*names) ⇒ Array<Symbol>
Define which relations your repository is going to use
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rom/repository/class_interface.rb', line 53 def relations(*names) if names.any? attr_reader(*names) if defined?(@relations) @relations.concat(names).uniq! else @relations = names end @relations else @relations end end |