Class: AMA::Entity::Mapper::Type::Parameter

Inherits:
Object
  • Object
show all
Includes:
Mixin::Errors
Defined in:
lib/ama-entity-mapper/type/parameter.rb

Overview

This class represents parameter type - an unknown-until-runtime type that belongs to particular other type. For example, Hash<Symbol, Integer> may be described as Type(Hash) with parameters _key: Symbol and _value: Integer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Errors

#compliance_error, #mapping_error, #raise_if_internal, #validation_error

Constructor Details

#initialize(owner, id) ⇒ Parameter

Returns a new instance of Parameter.

Parameters:



25
26
27
28
# File 'lib/ama-entity-mapper/type/parameter.rb', line 25

def initialize(owner, id)
  @owner = owner
  @id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



21
22
23
# File 'lib/ama-entity-mapper/type/parameter.rb', line 21

def id
  @id
end

#ownerObject (readonly)

Returns the value of attribute owner.



18
19
20
# File 'lib/ama-entity-mapper/type/parameter.rb', line 18

def owner
  @owner
end

#typeAMA::Entity::Mapper::Type



18
# File 'lib/ama-entity-mapper/type/parameter.rb', line 18

attr_reader :owner

Instance Method Details

#==(other) ⇒ Object



63
64
65
# File 'lib/ama-entity-mapper/type/parameter.rb', line 63

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/ama-entity-mapper/type/parameter.rb', line 58

def eql?(other)
  return false unless other.is_a?(self.class)
  @id == other.id && @owner == other.owner
end

#hashObject



54
55
56
# File 'lib/ama-entity-mapper/type/parameter.rb', line 54

def hash
  @owner.hash ^ @id.hash
end

#instance?(_) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ama-entity-mapper/type/parameter.rb', line 30

def instance?(_)
  false
end

#resolve_parameterObject



34
35
36
# File 'lib/ama-entity-mapper/type/parameter.rb', line 34

def resolve_parameter(*)
  self
end

#resolved!(context = nil) ⇒ Object



42
43
44
# File 'lib/ama-entity-mapper/type/parameter.rb', line 42

def resolved!(context = nil)
  compliance_error("Type #{self} is not resolved", context: context)
end

#resolved?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ama-entity-mapper/type/parameter.rb', line 38

def resolved?
  false
end

#to_defObject



50
51
52
# File 'lib/ama-entity-mapper/type/parameter.rb', line 50

def to_def
  "#{owner.type}.#{id}"
end

#to_sObject



46
47
48
# File 'lib/ama-entity-mapper/type/parameter.rb', line 46

def to_s
  "Parameter #{owner.type}.#{id}"
end