Class: ROM::Relation::Name Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.


62
63
64
65
66
67
# 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

Instance Attribute Details

#aliazObject (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.


57
58
59
# File 'lib/rom/relation/name.rb', line 57

def aliaz
  @aliaz
end

#datasetSymbol (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

Returns:

  • (Symbol)

55
56
57
# File 'lib/rom/relation/name.rb', line 55

def dataset
  @dataset
end

#keyObject (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.


59
60
61
# File 'lib/rom/relation/name.rb', line 59

def key
  @key
end

#relationSymbol (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

Returns:

  • (Symbol)

48
49
50
# File 'lib/rom/relation/name.rb', line 48

def relation
  @relation
end

Class Method Details

.[](*args) ⇒ ROM::Relation::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.

Coerce an object to a Name instance

Returns:


26
27
28
29
30
31
32
33
34
35
36
# 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

.cacheObject

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.


39
40
41
# File 'lib/rom/relation/name.rb', line 39

def self.cache
  @cache ||= Concurrent::Map.new
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.

Returns:

  • (Boolean)

75
76
77
# File 'lib/rom/relation/name.rb', line 75

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.


70
71
72
# File 'lib/rom/relation/name.rb', line 70

def as(aliaz)
  self.class[relation, dataset, aliaz]
end

#inspectString

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

Returns:

  • (String)

108
109
110
# File 'lib/rom/relation/name.rb', line 108

def inspect
  "#{self.class.name}(#{self})"
end

#to_sString

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

Returns:

  • (String)

84
85
86
87
88
89
90
91
92
# 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_symSymbol

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

Returns:

  • (Symbol)

99
100
101
# File 'lib/rom/relation/name.rb', line 99

def to_sym
  relation
end