class ROM::Relation::Name
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).
@api private
Attributes
Underlying dataset name
@return [Symbol]
@api private
Public Class Methods
Coerce an object to a Name
instance
@return [ROM::Relation::Name]
@api private
# File lib/rom/relation/name.rb, line 26 def self.[](*args) cache.fetch_or_store(args.hash) do relation, dataset, aliaz = args if relation.is_a?(Name) relation else new(relation, dataset, aliaz) end end end
@api private
# File lib/rom/relation/name.rb, line 39 def self.cache @cache ||= Concurrent::Map.new end
@api private
# File lib/rom/relation/name.rb, line 62 def initialize(relation, dataset = relation, aliaz = nil) @relation = relation @dataset = dataset || relation @key = aliaz || relation @aliaz = aliaz end
Public Instance Methods
@api private
# File lib/rom/relation/name.rb, line 75 def aliased? aliaz && aliaz != relation end
@api private
# File lib/rom/relation/name.rb, line 70 def as(aliaz) self.class[relation, dataset, aliaz] end
Return inspected relation
@return [String]
@api private
# File lib/rom/relation/name.rb, line 108 def inspect "#{self.class.name}(#{self})" end
Return relation name
@return [String]
@api private
# File lib/rom/relation/name.rb, line 84 def to_s if aliased? "#{relation} on #{dataset} as #{aliaz}" elsif relation == dataset relation.to_s else "#{relation} on #{dataset}" end end
Alias for registration key implicitly called by ROM::Registry
@return [Symbol]
@api private
# File lib/rom/relation/name.rb, line 99 def to_sym relation end