Module: ROM::SQL::Plugin::AssocMacros::ClassInterface Private
- Defined in:
- lib/rom/sql/plugin/assoc_macros/class_interface.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class DSL for SQL relations
Class Method Summary collapse
- .extended(klass) ⇒ Object private
- .prepare(klass) ⇒ Object private
Instance Method Summary collapse
-
#finalize(relations, relation) ⇒ Object
private
Finalize the relation by setting up its associations (if any).
-
#inherited(klass) ⇒ Object
private
Set up model and association ivars for descendant class.
-
#many_to_many(name, options = {}) ⇒ Object
Set up a many-to-many association.
-
#many_to_one(name, options = {}) ⇒ Object
Set up a many-to-one association.
-
#one_to_many(name, options) ⇒ Object
Set up a one-to-many association.
Class Method Details
.extended(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.
21 22 23 |
# File 'lib/rom/sql/plugin/assoc_macros/class_interface.rb', line 21 def self.extended(klass) prepare(klass) end |
.prepare(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.
10 11 12 13 14 15 16 17 18 |
# File 'lib/rom/sql/plugin/assoc_macros/class_interface.rb', line 10 def self.prepare(klass) klass.class_eval do class << self attr_reader :model, :associations end end klass.instance_variable_set('@model', Class.new(Sequel::Model)) klass.instance_variable_set('@associations', []) end |
Instance Method Details
#finalize(relations, relation) ⇒ 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.
Finalize the relation by setting up its associations (if any)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rom/sql/plugin/assoc_macros/class_interface.rb', line 108 def finalize(relations, relation) return unless relation.dataset.db.table_exists?(dataset) model.set_dataset(relation.dataset) model.dataset.naked! associations.each do |*args, assoc_opts| = Hash[assoc_opts] other = relations[.delete(:relation) || args[1]].model model.public_send(*args, .merge(class: other)) end model.freeze super 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.
Set up model and association ivars for descendant class
28 29 30 31 |
# File 'lib/rom/sql/plugin/assoc_macros/class_interface.rb', line 28 def inherited(klass) super ClassInterface.prepare(klass) end |
#many_to_many(name, options = {}) ⇒ Object
Set up a many-to-many association
78 79 80 |
# File 'lib/rom/sql/plugin/assoc_macros/class_interface.rb', line 78 def many_to_many(name, = {}) associations << [__method__, name, { relation: name }.merge()] end |
#many_to_one(name, options = {}) ⇒ Object
Set up a many-to-one association
101 102 103 |
# File 'lib/rom/sql/plugin/assoc_macros/class_interface.rb', line 101 def many_to_one(name, = {}) associations << [__method__, name, { relation: name }.merge()] end |
#one_to_many(name, options) ⇒ Object
Set up a one-to-many association
51 52 53 |
# File 'lib/rom/sql/plugin/assoc_macros/class_interface.rb', line 51 def one_to_many(name, ) associations << [__method__, name, { relation: name }.merge()] end |