aboutsummaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-12-30 00:02:01 -0200
committerSilvio Rhatto <rhatto@riseup.net>2017-12-30 00:02:01 -0200
commitfa635e9150e8e1042f357ad328b43f41e5c804b2 (patch)
tree2a535441b8d92a71d6e4f7c453d3bb479e11df4c /spec/support
parent309d5859d9c801218075789fe068869ab49065f5 (diff)
parent1020f7ca2be81c64f4a56816731390a852b62e89 (diff)
downloadpuppet-samba-fa635e9150e8e1042f357ad328b43f41e5c804b2.tar.gz
puppet-samba-fa635e9150e8e1042f357ad328b43f41e5c804b2.tar.bz2
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/augeas.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/support/augeas.rb b/spec/support/augeas.rb
new file mode 100644
index 0000000..7548684
--- /dev/null
+++ b/spec/support/augeas.rb
@@ -0,0 +1,69 @@
+require "delegate"
+
+module Augeas
+ class Change
+ attr_reader :target, :name, :delimiter
+
+ def initialize(target, name, value = nil, delimiter = "\"")
+ @target = target
+ @name = name
+ @value = value
+ @delimiter = delimiter
+ end
+
+ def to_s
+ "#{action} #{delimiter}target[. = '#{target}']/#{name}#{delimiter}#{value}"
+ end
+
+ def hash
+ [target, name, Change].hash
+ end
+
+ def ==(other)
+ other.is_a?(self.class) && [other.target, other.name] == [target, name]
+ end
+ alias_method :eql?, :==
+
+ private
+
+ def action
+ return "set" unless @value.nil?
+ "rm "
+ end
+
+ def value
+ " #{@value}" if @value
+ end
+ end
+
+ class ChangeSet
+ def initialize
+ @set = []
+ end
+
+ def <<(change)
+ index = @set.index(change) || @set.length
+ @set[index] = change
+ end
+
+ def to_a
+ changes
+ end
+
+ def changes
+ @set.map(&:to_s)
+ end
+ end
+
+ class TargetedChangeSet < DelegateClass(ChangeSet)
+ def initialize(target)
+ @target = target
+ super(ChangeSet.new)
+ end
+
+ def with(*args)
+ self << Change.new(@target, *args)
+ self
+ end
+ end
+end