Class: Sxn::Rules::BaseRule::RuleChange
- Inherits:
-
Object
- Object
- Sxn::Rules::BaseRule::RuleChange
- Defined in:
- lib/sxn/rules/base_rule.rb
Overview
Represents a single change made by a rule
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, target, metadata = {}) ⇒ RuleChange
constructor
A new instance of RuleChange.
-
#rollback ⇒ Object
Rollback this specific change.
- #to_h ⇒ Object
Constructor Details
#initialize(type, target, metadata = {}) ⇒ RuleChange
Returns a new instance of RuleChange.
330 331 332 333 334 335 |
# File 'lib/sxn/rules/base_rule.rb', line 330 def initialize(type, target, = {}) @type = type @target = target = .freeze = Time.now end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
328 329 330 |
# File 'lib/sxn/rules/base_rule.rb', line 328 def end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
328 329 330 |
# File 'lib/sxn/rules/base_rule.rb', line 328 def target @target end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
328 329 330 |
# File 'lib/sxn/rules/base_rule.rb', line 328 def end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
328 329 330 |
# File 'lib/sxn/rules/base_rule.rb', line 328 def type @type end |
Instance Method Details
#rollback ⇒ Object
Rollback this specific change
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/sxn/rules/base_rule.rb', line 338 def rollback case @type when :file_created FileUtils.rm_f(@target) when :file_modified FileUtils.mv([:backup_path], @target) if [:backup_path] && File.exist?([:backup_path]) when :directory_created Dir.rmdir(@target) if File.directory?(@target) && Dir.empty?(@target) when :symlink_created File.unlink(@target) if File.symlink?(@target) when :command_executed # Command execution cannot be rolled back # This is logged for audit purposes only else raise Sxn::Rules::RollbackError, "Unknown change type for rollback: #{@type}" end end |
#to_h ⇒ Object
356 357 358 359 360 361 362 363 |
# File 'lib/sxn/rules/base_rule.rb', line 356 def to_h { type: @type, target: @target, metadata: , timestamp: .iso8601 } end |