Sha256: 2fd0578bf37acf397faa8e6052cb4fd22b7041565a17d27081303e83f896e058

Contents?: true

Size: 1.63 KB

Versions: 69

Compression:

Stored size: 1.63 KB

Contents

require 'puppet/property'

module Puppet
  class Property
    class List < Property

      def should_to_s(should_value)
        #just return the should value
        should_value
      end

      def is_to_s(currentvalue)
        if currentvalue == :absent
          return "absent"
        else
          return currentvalue.join(delimiter)
        end
      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) if ! 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
        if tmp = provider.send(name) and tmp != :absent
          return tmp.split(delimiter)
        else
          return :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) == self.should)
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 4 rubygems

Version Path
puppet-2.7.14 lib/puppet/property/list.rb
puppet-2.6.16 lib/puppet/property/list.rb
puppet-2.7.13 lib/puppet/property/list.rb
puppet-2.6.15 lib/puppet/property/list.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/property/list.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/property/list.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/property/list.rb
puppet-2.7.12 lib/puppet/property/list.rb
puppet-2.7.11 lib/puppet/property/list.rb
puppet-2.6.14 lib/puppet/property/list.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/property/list.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/property/list.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/property/list.rb
puppet-2.6.13 lib/puppet/property/list.rb
puppet-2.7.9 lib/puppet/property/list.rb
puppet-2.7.8 lib/puppet/property/list.rb
puppet-2.7.6 lib/puppet/property/list.rb
puppet-2.6.12 lib/puppet/property/list.rb
puppet-2.7.5 lib/puppet/property/list.rb
puppet-2.6.11 lib/puppet/property/list.rb