Class: Puppet::Pops::Types::PSensitiveType

Inherits:
PTypeWithContainedType show all
Defined in:
lib/puppet/pops/types/p_sensitive_type.rb

Overview

A Puppet Language type that wraps sensitive information. The sensitive type is parameterized by the wrapped value type.

Defined Under Namespace

Classes: Sensitive

Instance Attribute Summary

Attributes inherited from PTypeWithContainedType

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PTypeWithContainedType

#accept, #eql?, #generalize, #hash, #normalize, #resolve

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #eql?, #generalize, #hash, #iterable?, #iterable_type, #kind_of_callable?, #loader, #name, #new_function, #normalize, #really_instance?, #resolve, #roundtrip_with_string?, #simple_name, simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_pcore_type, create_ptype, register_ptypes

Methods included from Visitable

#accept

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type, #to_s

Constructor Details

#initialize(type = nil) ⇒ PSensitiveType

Returns a new instance of PSensitiveType


33
34
35
# File 'lib/puppet/pops/types/p_sensitive_type.rb', line 33

def initialize(type = nil)
  @type = type.nil? ? PAnyType.new : type.generalize
end

Class Method Details

.new_function(type) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/puppet/pops/types/p_sensitive_type.rb', line 41

def self.new_function(type)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_Sensitive, type.loader) do

    dispatch :from_sensitive do
      param 'Sensitive', :value
    end

    dispatch :from_any do
      param 'Any', :value
    end

    def from_any(value)
      Sensitive.new(value)
    end

    # Since the Sensitive value is immutable we can reuse the existing instance instead of making a copy.
    def from_sensitive(value)
      value
    end
  end
end

.register_ptype(loader, ir) ⇒ Object


29
30
31
# File 'lib/puppet/pops/types/p_sensitive_type.rb', line 29

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'AnyType')
end

Instance Method Details

#instance?(o, guard = nil) ⇒ Boolean


37
38
39
# File 'lib/puppet/pops/types/p_sensitive_type.rb', line 37

def instance?(o, guard = nil)
  o.is_a?(Sensitive) && @type.instance?(o.unwrap, guard)
end