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.



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

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.



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

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.



56
57
58
# File 'lib/cfa/augeas_parser/writer.rb', line 56

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.



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

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



101
102
103
# File 'lib/cfa/augeas_parser/writer.rb', line 101

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.



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

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.



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

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.



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

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.



67
68
69
# File 'lib/cfa/augeas_parser/writer.rb', line 67

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.



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

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.



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

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