Class: TypeGeneric

Inherits:
Object
  • Object
show all
Defined in:
lib/ansible/ruby/models/type_generic.rb

Overview

See LICENSE.txt for license

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ TypeGeneric

Returns a new instance of TypeGeneric.



5
6
7
# File 'lib/ansible/ruby/models/type_generic.rb', line 5

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/ansible/ruby/models/type_generic.rb', line 3

def klass
  @klass
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ansible/ruby/models/type_generic.rb', line 21

def eql?(other)
  other.is_a?(TypeGeneric) && other.klass == @klass
end

#error(attribute, value) ⇒ Object



16
17
18
19
# File 'lib/ansible/ruby/models/type_generic.rb', line 16

def error(attribute, value)
  object = validation_object(value)
  "Attribute #{attribute} expected to be a #{@klass} but was a #{object.class}"
end

#hashObject



25
26
27
# File 'lib/ansible/ruby/models/type_generic.rb', line 25

def hash
  @klass.hash
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/ansible/ruby/models/type_generic.rb', line 9

def valid?(value)
  validation_object = validation_object(value)
  # Don't worry about nil
  return true unless validation_object
  validation_object.is_a? @klass
end