Class: DAP::Relation::OneOf
- Inherits:
-
Object
- Object
- DAP::Relation::OneOf
- Defined in:
- lib/dap/relation.rb
Overview
Indicates a property is expected to be one of a set of types
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
The name of the key property.
-
#types ⇒ Object
readonly
The allowed key property values and expected types.
Instance Method Summary collapse
-
#[]=(k, v) ⇒ Object
Sets the expected type for a specified value of the key property.
-
#initialize(types) ⇒ OneOf
constructor
A new instance of OneOf.
-
#with(key) ⇒ Object
Specifies the key property that is used to determine which type is selected.
Constructor Details
#initialize(types) ⇒ OneOf
Returns a new instance of OneOf.
29 30 31 32 |
# File 'lib/dap/relation.rb', line 29 def initialize(types) types.values.each { |k| DAP::Relation.supported!(k) } @types = types end |
Instance Attribute Details
#key ⇒ Object (readonly)
The name of the key property.
26 27 28 |
# File 'lib/dap/relation.rb', line 26 def key @key end |
#types ⇒ Object (readonly)
The allowed key property values and expected types.
23 24 25 |
# File 'lib/dap/relation.rb', line 23 def types @types end |
Instance Method Details
#[]=(k, v) ⇒ Object
Sets the expected type for a specified value of the key property.
45 46 47 |
# File 'lib/dap/relation.rb', line 45 def []=(k, v) @types[k] = v end |
#with(key) ⇒ Object
Specifies the key property that is used to determine which type is selected.
36 37 38 39 40 |
# File 'lib/dap/relation.rb', line 36 def with(key) o = dup o.instance_eval { @key = key } o end |