Sha256: 3bc08597d08d6a960eddf859f9f07ed3e065afb4212438096f07d0692cc8f802

Contents?: true

Size: 1.75 KB

Versions: 20

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require_relative '../../puppet/property'

module Puppet
  class Property
    # This subclass of {Puppet::Property} manages an unordered list of values.
    # For an ordered list see {Puppet::Property::OrderedList}.
    #
    class List < Property
      def is_to_s(currentvalue) # rubocop:disable Naming/PredicateName
        currentvalue == :absent ? super(currentvalue) : currentvalue.join(delimiter)
      end

      def membership
        :membership
      end

      def add_should_with_current(should, current)
        should += current if current.is_a?(Array)
        should.uniq
      end

      def inclusive?
        @resource[membership] == :inclusive
      end

      # dearrayify was motivated because to simplify the implementation of the OrderedList property
      def dearrayify(array)
        array.sort.join(delimiter)
      end

      def should
        return nil unless @should

        members = @should
        # inclusive means we are managing everything so if it isn't in should, its gone
        members = add_should_with_current(members, retrieve) unless inclusive?

        dearrayify(members)
      end

      def delimiter
        ","
      end

      def retrieve
        # ok, some 'convention' if the list property is named groups, provider should implement a groups method
        tmp = provider.send(name) if provider
        if tmp && tmp != :absent
          tmp.instance_of?(Array) ? tmp : tmp.split(delimiter)
        else
          :absent
        end
      end

      def prepare_is_for_comparison(is)
        if is == :absent
          is = []
        end
        dearrayify(is)
      end

      def insync?(is)
        return true unless is

        (prepare_is_for_comparison(is) == should)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/property/list.rb
puppet-8.10.0-x86-mingw32 lib/puppet/property/list.rb
puppet-8.10.0-x64-mingw32 lib/puppet/property/list.rb
puppet-8.10.0-universal-darwin lib/puppet/property/list.rb
puppet-8.9.0 lib/puppet/property/list.rb
puppet-8.9.0-x86-mingw32 lib/puppet/property/list.rb
puppet-8.9.0-x64-mingw32 lib/puppet/property/list.rb
puppet-8.9.0-universal-darwin lib/puppet/property/list.rb
puppet-8.8.1 lib/puppet/property/list.rb
puppet-8.8.1-x86-mingw32 lib/puppet/property/list.rb
puppet-8.8.1-x64-mingw32 lib/puppet/property/list.rb
puppet-8.8.1-universal-darwin lib/puppet/property/list.rb
puppet-8.7.0 lib/puppet/property/list.rb
puppet-8.7.0-x86-mingw32 lib/puppet/property/list.rb
puppet-8.7.0-x64-mingw32 lib/puppet/property/list.rb
puppet-8.7.0-universal-darwin lib/puppet/property/list.rb
puppet-8.6.0 lib/puppet/property/list.rb
puppet-8.6.0-x86-mingw32 lib/puppet/property/list.rb
puppet-8.6.0-x64-mingw32 lib/puppet/property/list.rb
puppet-8.6.0-universal-darwin lib/puppet/property/list.rb