Class: CFA::AugeasWriter::LocatedEntry Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cfa/augeas_parser/writer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

CFA::AugeasElement together with information about its location and a few helper methods to detect siblings.

Examples:

data for an already existing comment living under /main

entry.orig_key # => "#comment[15]"
entry.path # => "/main/#comment[15]"
entry.key # => "#comment"
entry.entry_tree # => AugeasTree.new
entry.entry_value # => "old boring comment"

data for a new comment under /main

entry.orig_key # => nil
entry.path # => nil
entry.key # => "#comment"
entry.entry_tree # => AugeasTree.new
entry.entry_value # => "new boring comment"

data for new tree placed at /main

entry.orig_key # => "main"
entry.path # => "/main"
entry.key # => "main"
entry.entry_tree # => entry[:value]
entry.entry_value # => nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree, entry, prefix) ⇒ LocatedEntry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LocatedEntry.



62
63
64
65
66
67
# File 'lib/cfa/augeas_parser/writer.rb', line 62

def initialize(tree, entry, prefix)
  @tree = tree
  @entry = entry
  @prefix = prefix
  detect_tree_value_modification
end

Instance Attribute Details

#entryObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



59
60
61
# File 'lib/cfa/augeas_parser/writer.rb', line 59

def entry
  @entry
end

#prefixObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/cfa/augeas_parser/writer.rb', line 58

def prefix
  @prefix
end

#treeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
# File 'lib/cfa/augeas_parser/writer.rb', line 60

def tree
  @tree
end

Instance Method Details

#any_following?true, false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if there is any following entry in the Augeas tree

Returns:

  • (true, false)

    returns true if there is any following entry in the Augeas tree



103
104
105
# File 'lib/cfa/augeas_parser/writer.rb', line 103

def any_following?
  following_entries.any? { |e| e[:operation] != :remove }
end

#entry_treeAugeasTree

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the Augeas tree nested under this entry. If there is no such tree, it creates an empty one.

Returns:

  • (AugeasTree)

    the Augeas tree nested under this entry. If there is no such tree, it creates an empty one.



109
110
111
112
113
114
115
116
# File 'lib/cfa/augeas_parser/writer.rb', line 109

def entry_tree
  value = entry[:value]
  case value
  when AugeasTree then value
  when AugeasTreeValue then value.tree
  else AugeasTree.new
  end
end

#entry_valueString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

If the value is an CFA::AugeasTree then return nil.

Returns:

  • (String, nil)

    the Augeas value of this entry. Can be nil.



120
121
122
123
124
125
126
127
# File 'lib/cfa/augeas_parser/writer.rb', line 120

def entry_value
  value = entry[:value]
  case value
  when AugeasTree then nil
  when AugeasTreeValue then value.value
  else value
  end
end

#keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



80
81
82
83
84
85
86
# File 'lib/cfa/augeas_parser/writer.rb', line 80

def key
  return @key if @key

  @key = @entry[:key]
  @key = @key[0..-3] if @key.end_with?("[]")
  @key
end

#orig_keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
# File 'lib/cfa/augeas_parser/writer.rb', line 69

def orig_key
  entry[:orig_key]
end

#pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
78
# File 'lib/cfa/augeas_parser/writer.rb', line 73

def path
  return @path if @path
  return nil unless orig_key

  @path = @prefix + "/" + orig_key
end

#preceding_existingLocatedEntry?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a preceding entry that already exists in the Augeas tree or nil if it does not exist.

Returns:

  • (LocatedEntry, nil)

    a preceding entry that already exists in the Augeas tree or nil if it does not exist.



91
92
93
94
95
96
97
98
99
# File 'lib/cfa/augeas_parser/writer.rb', line 91

def preceding_existing
  preceding_entry = preceding_entries.reverse_each.find do |entry|
    entry[:operation] != :add
  end

  return nil unless preceding_entry

  LocatedEntry.new(tree, preceding_entry, prefix)
end