Class: PuppetX::Rustup::Property::Set
- Inherits:
-
Puppet::Property
- Object
- Puppet::Property
- PuppetX::Rustup::Property::Set
- Defined in:
- lib/puppet_x/rustup/property/set.rb
Overview
A list where the order is not important for changes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ignore_removed_entries ⇒ Object
Whether or not to consider it a change if there are entries that exist on the system, but aren’t specified in the resource.
Class Method Summary collapse
-
.array_matching ⇒ Object
Ensure that we compare the entire list.
Instance Method Summary collapse
-
#clean_set(entries) ⇒ Object
Run a normalizer on ‘is` or `should` and make a hash.
-
#entry_changed?(is_entry, should_entry) ⇒ Boolean
Check if entries with the same identity are different.
-
#entry_identity(entry) ⇒ Object
Get the identity of the entry.
-
#initialize ⇒ Set
constructor
A new instance of Set.
-
#insync?(is) ⇒ Boolean
Check if the values are in sync.
-
#normalize_is_entry(entry) ⇒ Object
Do any normalization required for an entry in ‘is`.
-
#normalize_should_entry(entry) ⇒ Object
Do any normalization required for an entry in ‘should`.
-
#should_entry_absent?(_entry) ⇒ Boolean
Does this entry in ‘should` have the equivalent of `ensure => absent`?.
Constructor Details
#initialize ⇒ Set
Returns a new instance of Set.
12 13 14 15 |
# File 'lib/puppet_x/rustup/property/set.rb', line 12 def initialize(*, **) @ignore_removed_entries = false super end |
Instance Attribute Details
#ignore_removed_entries ⇒ Object
Whether or not to consider it a change if there are entries that exist on the system, but aren’t specified in the resource.
For example:
directory { 'bar':
files => [ 'a', 'b' ],
}
Suppose that ‘bar` actually has `a`, `b`, and `c` entries on the system. If this method returns `true`, then the above resource will not be considered changed. If it returns `false`, then it will be.
This is useful for purge-like functionality.
Defaults to false
33 34 35 |
# File 'lib/puppet_x/rustup/property/set.rb', line 33 def ignore_removed_entries @ignore_removed_entries end |
Class Method Details
.array_matching ⇒ Object
Ensure that we compare the entire list.
8 9 10 |
# File 'lib/puppet_x/rustup/property/set.rb', line 8 def self.array_matching :all end |
Instance Method Details
#clean_set(entries) ⇒ Object
Run a normalizer on ‘is` or `should` and make a hash. Takes a block that normalizes an entry.
This makes sure that all entries are unique.
You should not need to override this.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/puppet_x/rustup/property/set.rb', line 74 def clean_set(entries) hash = {} entries.each do |entry| normalized = yield entry if normalized.nil? next end identity = entry_identity(normalized) if hash.include? identity raise Puppet::Error, "Duplicate entry in set: #{entry.inspect}" end hash[identity] = normalized end hash end |
#entry_changed?(is_entry, should_entry) ⇒ Boolean
Check if entries with the same identity are different.
92 93 94 |
# File 'lib/puppet_x/rustup/property/set.rb', line 92 def entry_changed?(is_entry, should_entry) is_entry != should_entry end |
#entry_identity(entry) ⇒ Object
Get the identity of the entry.
This is akin to the title of a resource. It should uniquely identify this entry within in the set. If two entries have the same identity, then it is an error.
40 41 42 |
# File 'lib/puppet_x/rustup/property/set.rb', line 40 def entry_identity(entry) entry.hash end |
#insync?(is) ⇒ Boolean
Check if the values are in sync.
You should not need to override this.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppet_x/rustup/property/set.rb', line 99 def insync?(is) clean_should = clean_set(should) { |e| normalize_should_entry(e) } begin clean_is = clean_set(is) { |e| normalize_is_entry(e) } rescue Puppet::Error => error # `clean_is` represents what actually exists, so if there are duplicates # it should not fail (though it should be considered a bug). Since we # don’t allow `should` to contain duplicates, a duplicate in `is` will # always indicate a change. warn "Error in existing #{name}: #{error}" return false end # Remove entries in clean_should from clean_is. clean_should.each do |identity, should_entry| is_entry = clean_is.delete(identity) if is_entry.nil? # Found an entry in `should`, but not in `is`. If the entry has the # equivalent of `ensure => absent`, then it doesn’t matter. unless should_entry_absent? should_entry return false end elsif entry_changed?(is_entry, should_entry) # Found entries with the same identity, but different details. return false end end if ignore_removed_entries # Every entry in `should` corresponds to an entry in `is`, so nothing was # added. true else # If there is anything left in `clean_is`, then there is a change. clean_is.empty? end end |
#normalize_is_entry(entry) ⇒ Object
Do any normalization required for an entry in ‘is`.
Return the normalized entry or ‘nil` to skip it. If an entry has the equivalent of `ensure => absent`, this should return `nil`.
64 65 66 |
# File 'lib/puppet_x/rustup/property/set.rb', line 64 def normalize_is_entry(entry) entry end |
#normalize_should_entry(entry) ⇒ Object
Do any normalization required for an entry in ‘should`.
Return the normalized entry or ‘nil` to skip it.
56 57 58 |
# File 'lib/puppet_x/rustup/property/set.rb', line 56 def normalize_should_entry(entry) entry end |
#should_entry_absent?(_entry) ⇒ Boolean
Does this entry in ‘should` have the equivalent of `ensure => absent`?
This is used to determine if there is a change. If this returns ‘true` and there is no corresponding entry in `is`, then it will not be considered a change.
49 50 51 |
# File 'lib/puppet_x/rustup/property/set.rb', line 49 def should_entry_absent?(_entry) false end |