Class: ROM::Relation::Name Private
- Inherits:
-
Object
- Object
- ROM::Relation::Name
- Defined in:
- lib/rom/relation/name.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Relation name container
This is a simple struct with two fields. It handles both relation registration name (i.e. Symbol) and dataset name. The reason we need it is a simplification of passing around these two objects. It is quite common to have a dataset named differently from a relation built on top if you are dealing with a legacy DB and often you need both to support things such as associations (rom-sql as an example).
Instance Attribute Summary collapse
- #aliaz ⇒ Object readonly private
-
#dataset ⇒ Symbol
readonly
private
Underlying dataset name.
- #key ⇒ Object readonly private
-
#relation ⇒ Symbol
readonly
private
Relation registration name.
Class Method Summary collapse
- .cache ⇒ Object private
-
.call(*args) ⇒ ROM::Relation::Name
(also: [])
private
Coerce an object to a Name instance.
Instance Method Summary collapse
- #aliased? ⇒ Boolean private
- #as(aliaz) ⇒ Object private
-
#initialize(relation, dataset = relation, aliaz = nil) ⇒ Name
constructor
private
A new instance of Name.
-
#inspect ⇒ String
private
Return inspected relation.
-
#to_s ⇒ String
private
Return relation name.
-
#to_sym ⇒ Symbol
private
Alias for registration key implicitly called by ROM::Registry.
Constructor Details
#initialize(relation, dataset = relation, aliaz = nil) ⇒ Name
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.
Returns a new instance of Name.
70 71 72 73 74 75 76 |
# File 'lib/rom/relation/name.rb', line 70 def initialize(relation, dataset = relation, aliaz = nil) @relation = relation @dataset = dataset || relation @key = aliaz || relation @aliaz = aliaz freeze end |
Instance Attribute Details
#aliaz ⇒ Object (readonly)
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.
65 66 67 |
# File 'lib/rom/relation/name.rb', line 65 def aliaz @aliaz end |
#dataset ⇒ Symbol (readonly)
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.
Underlying dataset name
63 64 65 |
# File 'lib/rom/relation/name.rb', line 63 def dataset @dataset end |
#key ⇒ Object (readonly)
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.
67 68 69 |
# File 'lib/rom/relation/name.rb', line 67 def key @key end |
#relation ⇒ Symbol (readonly)
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.
Relation registration name
56 57 58 |
# File 'lib/rom/relation/name.rb', line 56 def relation @relation end |
Class Method Details
.cache ⇒ 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.
47 48 49 |
# File 'lib/rom/relation/name.rb', line 47 def self.cache @cache ||= Concurrent::Map.new end |
.call(*args) ⇒ ROM::Relation::Name Also known as: []
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.
Coerce an object to a Name instance
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rom/relation/name.rb', line 27 def self.call(*args) cache.fetch_or_store(args.hash) do relation, dataset, aliaz = args case relation when self then relation when Symbol then new(relation, dataset, aliaz) when Class, String then new(Inflector.component_id(relation).to_sym) else raise ArgumentError, "+#{relation}+ is not supported" end end end |
Instance Method Details
#aliased? ⇒ Boolean
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.
84 85 86 |
# File 'lib/rom/relation/name.rb', line 84 def aliased? aliaz && aliaz != relation end |
#as(aliaz) ⇒ 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.
79 80 81 |
# File 'lib/rom/relation/name.rb', line 79 def as(aliaz) self.class[relation, dataset, aliaz] end |
#inspect ⇒ String
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.
Return inspected relation
117 118 119 |
# File 'lib/rom/relation/name.rb', line 117 def inspect "#{self.class.name}(#{self})" end |
#to_s ⇒ String
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.
Return relation name
93 94 95 96 97 98 99 100 101 |
# File 'lib/rom/relation/name.rb', line 93 def to_s if aliased? "#{relation} on #{dataset} as #{aliaz}" elsif relation == dataset relation.to_s else "#{relation} on #{dataset}" end end |
#to_sym ⇒ Symbol
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.
Alias for registration key implicitly called by ROM::Registry
108 109 110 |
# File 'lib/rom/relation/name.rb', line 108 def to_sym relation end |