Class: ROM::Associations::Definitions::Abstract
- Inherits:
-
Object
- Object
- ROM::Associations::Definitions::Abstract
- Extended by:
- Dry::Core::ClassAttributes, Initializer
- Defined in:
- lib/rom/associations/definitions/abstract.rb
Overview
Abstract association definition object
Direct Known Subclasses
Instance Attribute Summary collapse
-
#alias ⇒ Symbol
readonly
An optional association alias.
-
#combine_keys ⇒ Hash<Symbol=>Symbol>
readonly
Override inferred combine keys.
-
#foreign_key ⇒ Symbol
readonly
An optional association alias name.
-
#name ⇒ Symbol
readonly
The name of an association.
-
#override ⇒ TrueClass, FalseClass
readonly
Whether custom view should override default one or not.
-
#relation ⇒ Symbol
readonly
An optional relation identifier for the target.
-
#result ⇒ Symbol
readonly
Either :one or :many.
-
#source ⇒ Relation::Name
readonly
The source relation name.
-
#target ⇒ Relation::Name
readonly
The target relation name.
-
#view ⇒ Symbol
readonly
An optional view that should be used to extend assoc relation.
Class Method Summary collapse
-
.new(source, target, **opts) ⇒ Object
Instantiate a new association definition.
- .process_options(target, options) ⇒ Object private
- .resolve_target_name(target, options) ⇒ Object private
Instance Method Summary collapse
-
#aliased? ⇒ Boolean
Return true if association is aliased.
- #id ⇒ Object
-
#override? ⇒ Boolean
Return true if association's default relation view should be overridden by a custom one.
- #to_h ⇒ Object
-
#type ⇒ Class
Return association class for a given definition object.
Instance Attribute Details
#alias ⇒ Symbol (readonly)
Returns An optional association alias.
43 |
# File 'lib/rom/associations/definitions/abstract.rb', line 43 option :as, Types::Strict::Symbol.optional, optional: true |
#combine_keys ⇒ Hash<Symbol=>Symbol> (readonly)
Returns Override inferred combine keys.
63 |
# File 'lib/rom/associations/definitions/abstract.rb', line 63 option :combine_keys, optional: true |
#foreign_key ⇒ Symbol (readonly)
Returns an optional association alias name.
47 |
# File 'lib/rom/associations/definitions/abstract.rb', line 47 option :foreign_key, Types::Optional::Strict::Symbol, optional: true |
#name ⇒ Symbol (readonly)
Returns The name of an association.
35 |
# File 'lib/rom/associations/definitions/abstract.rb', line 35 option :name, Types::Strict::Symbol, default: -> { target.to_sym } |
#override ⇒ TrueClass, FalseClass (readonly)
Returns Whether custom view should override default one or not.
59 |
# File 'lib/rom/associations/definitions/abstract.rb', line 59 option :override, default: -> { false } |
#relation ⇒ Symbol (readonly)
Returns an optional relation identifier for the target.
39 |
# File 'lib/rom/associations/definitions/abstract.rb', line 39 option :relation, Types::Strict::Symbol, default: -> { name } |
#result ⇒ Symbol (readonly)
Returns either :one or :many.
51 |
# File 'lib/rom/associations/definitions/abstract.rb', line 51 option :result, Types::Strict::Symbol, default: -> { self.class.result } |
#source ⇒ Relation::Name (readonly)
Returns the source relation name.
27 |
# File 'lib/rom/associations/definitions/abstract.rb', line 27 param :source |
#target ⇒ Relation::Name (readonly)
Returns the target relation name.
31 |
# File 'lib/rom/associations/definitions/abstract.rb', line 31 param :target |
#view ⇒ Symbol (readonly)
Returns An optional view that should be used to extend assoc relation.
55 |
# File 'lib/rom/associations/definitions/abstract.rb', line 55 option :view, optional: true |
Class Method Details
.new(source, target, **opts) ⇒ Object
Instantiate a new association definition
77 78 79 80 81 82 83 |
# File 'lib/rom/associations/definitions/abstract.rb', line 77 def self.new(source, target, **opts) source_name = Relation::Name[source] target_name = resolve_target_name(target, opts) = (target_name, opts.to_h) super(source_name, target_name, **) end |
.process_options(target, options) ⇒ 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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rom/associations/definitions/abstract.rb', line 94 def self.(target, ) through = [:through] if through [:through] = ThroughIdentifier[ through, target.relation, [:assoc], inflector: .fetch(:inflector, Inflector) ] end [:name] = target.relation end |
.resolve_target_name(target, options) ⇒ 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.
86 87 88 89 90 91 |
# File 'lib/rom/associations/definitions/abstract.rb', line 86 def self.resolve_target_name(target, ) dataset = target relation = .fetch(:relation, target) Relation::Name[relation, dataset, [:as]] end |
Instance Method Details
#aliased? ⇒ Boolean
Return true if association is aliased
135 136 137 |
# File 'lib/rom/associations/definitions/abstract.rb', line 135 def aliased? ![:as].nil? end |
#id ⇒ Object
112 113 114 |
# File 'lib/rom/associations/definitions/abstract.rb', line 112 def id aliased? ? as : name end |
#override? ⇒ Boolean
Return true if association's default relation view should be overridden by a custom one
126 127 128 |
# File 'lib/rom/associations/definitions/abstract.rb', line 126 def override? [:override].equal?(true) end |
#to_h ⇒ Object
117 118 119 |
# File 'lib/rom/associations/definitions/abstract.rb', line 117 def to_h {id: id, **} end |
#type ⇒ Class
Return association class for a given definition object
144 145 146 |
# File 'lib/rom/associations/definitions/abstract.rb', line 144 def type Inflector.demodulize(self.class.name).to_sym end |