Class: Mxrb::Runtime::RuntimeSchema

Inherits:
Data
  • Object
show all
Defined in:
lib/mxrb/runtime/schema_migrator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#associationsObject (readonly)

Returns the value of attribute associations

Returns:

  • (Object)

    the current value of associations



15
16
17
# File 'lib/mxrb/runtime/schema_migrator.rb', line 15

def associations
  @associations
end

#entitiesObject (readonly)

Returns the value of attribute entities

Returns:

  • (Object)

    the current value of entities



15
16
17
# File 'lib/mxrb/runtime/schema_migrator.rb', line 15

def entities
  @entities
end

Instance Method Details

#association(name) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
# File 'lib/mxrb/runtime/schema_migrator.rb', line 27

def association(name)
  key = name.to_s
  matches = associations.select do |candidate|
    candidate.qualified_name == key || candidate.name == key ||
      candidate.qualified_name.split('.').last == key
  end
  return matches.first if matches.one?

  raise ArgumentError, matches.empty? ? "unknown association #{name}" : "ambiguous association #{name}"
end

#entity(name) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
# File 'lib/mxrb/runtime/schema_migrator.rb', line 16

def entity(name)
  qualified = name.to_s
  exact = entities.find { _1.name == qualified }
  return exact if exact

  matches = entities.select { _1.name.split('.').last == qualified }
  return matches.first if matches.one?

  raise ArgumentError, matches.empty? ? "unknown entity #{name}" : "ambiguous entity #{name}"
end