File: sensitive.rb

package info (click to toggle)
ruby-rspec-puppet 4.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,444 kB
  • sloc: ruby: 6,377; makefile: 6
file content (43 lines) | stat: -rw-r--r-- 978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module RSpec::Puppet
  # A wrapper representing Sensitive data type, eg. in class params.
  class Sensitive < ::Puppet::Pops::Types::PSensitiveType::Sensitive
    # Create a new Sensitive object
    # @param [Object] value to wrap
    def initialize(value)
      @value = value
    end

    # @return the wrapped value
    def unwrap
      @value
    end

    # @return true
    def sensitive?
      true
    end

    # @return inspect of the wrapped value, inside Sensitive()
    def inspect
      "Sensitive(#{@value.inspect})"
    end

    # Check for equality with another value.
    # If compared to Puppet Sensitive type, it compares the wrapped values.

    # @param other [#unwrap, Object] value to compare to
    def ==(other)
      if other.respond_to? :unwrap
        if unwrap.is_a?(Regexp)
          unwrap =~ other.unwrap
        else
          unwrap == other.unwrap
        end
      else
        super
      end
    end
  end
end