Class: Mxrb::Runtime::RuntimeSchema
- Inherits:
-
Data
- Object
- Data
- Mxrb::Runtime::RuntimeSchema
- Defined in:
- lib/mxrb/runtime/schema_migrator.rb
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
Instance Method Summary collapse
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations
15 16 17 |
# File 'lib/mxrb/runtime/schema_migrator.rb', line 15 def associations @associations end |
#entities ⇒ Object (readonly)
Returns the value of attribute entities
15 16 17 |
# File 'lib/mxrb/runtime/schema_migrator.rb', line 15 def entities @entities end |
Instance Method Details
#association(name) ⇒ Object
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
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 |