Class: ROM::Associations::Definitions::Abstract
- Inherits:
-
Object
- Object
- ROM::Associations::Definitions::Abstract
- Extended by:
- Dry::Core::ClassAttributes
- Defined in:
- core/lib/rom/associations/definitions/abstract.rb
Overview
Abstract association definition object
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.
Instance Method Summary collapse
-
#aliased? ⇒ Boolean
Return true if association is aliased.
-
#override? ⇒ Boolean
Return true if association's default relation view should be overridden by a custom one.
-
#type ⇒ Class
Return association class for a given definition object.
Instance Attribute Details
#alias ⇒ Symbol (readonly)
Returns An optional association alias.
46 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 46 option :as, Types::Strict::Symbol.optional, optional: true |
#combine_keys ⇒ Hash<Symbol=>Symbol> (readonly)
Returns Override inferred combine keys.
62 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 62 option :combine_keys, optional: true |
#foreign_key ⇒ Symbol (readonly)
Returns an optional association alias name.
50 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 50 option :foreign_key, Types::Optional::Strict::Symbol, optional: true |
#name ⇒ Symbol (readonly)
Returns The name of an association.
42 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 42 option :name, Types::Strict::Symbol, default: -> { target.to_sym } |
#override ⇒ TrueClass, FalseClass (readonly)
Returns Whether custom view should override default one or not.
58 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 58 option :override, optional: true, default: -> { false } |
#relation ⇒ Symbol (readonly)
Returns an optional relation identifier for the target.
34 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 34 option :relation, Types::Strict::Symbol, optional: true |
#result ⇒ Symbol (readonly)
Returns either :one or :many.
38 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 38 option :result, Types::Strict::Symbol, default: -> { self.class.result } |
#source ⇒ Relation::Name (readonly)
Returns the source relation name.
26 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 26 param :source |
#target ⇒ Relation::Name (readonly)
Returns the target relation name.
30 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 30 param :target |
#view ⇒ Symbol (readonly)
Returns An optional view that should be used to extend assoc relation.
54 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 54 option :view, optional: true |
Class Method Details
.new(source, target, **opts) ⇒ Object
Instantiate a new association definition
76 77 78 79 80 81 82 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 76 def self.new(source, target, **opts) source_name = Relation::Name[source] target_name = resolve_target_name(target, opts) = (target_name, Hash[opts]) super(source_name, target_name, **) end |
Instance Method Details
#aliased? ⇒ Boolean
Return true if association is aliased
119 120 121 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 119 def aliased? .key?(:as) end |
#override? ⇒ Boolean
Return true if association's default relation view should be overridden by a custom one
110 111 112 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 110 def override? [:override].equal?(true) end |
#type ⇒ Class
Return association class for a given definition object
128 129 130 |
# File 'core/lib/rom/associations/definitions/abstract.rb', line 128 def type Inflector.demodulize(self.class.name).to_sym end |