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

aliaz[R]
dataset[R]

Underlying dataset name

@return [Symbol]

@api private

key[R]
relation[R]

Relation registration name

@return [Symbol]

@api private

Public Class Methods

[](*args) click to toggle source

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
cache() click to toggle source

@api private

# File lib/rom/relation/name.rb, line 39
def self.cache
  @cache ||= Concurrent::Map.new
end
new(relation, dataset = relation, aliaz = nil) click to toggle source

@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

aliased?() click to toggle source

@api private

# File lib/rom/relation/name.rb, line 75
def aliased?
  aliaz && aliaz != relation
end
as(aliaz) click to toggle source

@api private

# File lib/rom/relation/name.rb, line 70
def as(aliaz)
  self.class[relation, dataset, aliaz]
end
inspect() click to toggle source

Return inspected relation

@return [String]

@api private

# File lib/rom/relation/name.rb, line 108
def inspect
  "#{self.class.name}(#{self})"
end
to_s() click to toggle source

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
to_sym() click to toggle source

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