Method: VagrantCloud::Data::Mutable#clean
- Defined in:
- lib/vagrant_cloud/data.rb
#clean(data:, ignores: [], only: []) ⇒ self
Load given data and ignore any fields that are provided. Flush dirty state.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/vagrant_cloud/data.rb', line 254 def clean(data:, ignores: [], only: []) raise TypeError, "Expected type `Hash` but received `#{data.inspect}`" if !data.is_a?(Hash) new_data = @data.dup ignores = Array(ignores).map(&:to_sym) only = Array(only).map(&:to_sym) data.each do |k, v| k = k.to_sym next if ignores.include?(k) next if !only.empty? && !only.include?(k) if self.respond_to?(k) new_data[k] = v @dirty.delete(k) end end @data = freezer(new_data) self end |