Class: DAP::Relation::OneOf

Inherits:
Object
  • Object
show all
Defined in:
lib/dap/relation.rb

Overview

Indicates a property is expected to be one of a set of types

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ OneOf

Returns a new instance of OneOf.

Parameters:

  • types (Hash<Symbol, Class>)

    the allowed key property values and expected types



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

#keyObject (readonly)

The name of the key property.



26
27
28
# File 'lib/dap/relation.rb', line 26

def key
  @key
end

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

Parameters:

  • k (Symbol)

    the specified value

  • v (Class)

    the expected type



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.

Parameters:

  • key (Symbol)

    the name of the key property



36
37
38
39
40
# File 'lib/dap/relation.rb', line 36

def with(key)
  o = dup
  o.instance_eval { @key = key }
  o
end