Class: Aef::Hosts::Entry
Overview
Represents an entry line as element of a hosts file
Instance Attribute Summary collapse
-
#address ⇒ String
The network address.
-
#aliases ⇒ Array<String>
Optional alias hostnames.
-
#comment ⇒ String
Optional comment.
-
#name ⇒ String
The primary hostname for the address.
Attributes inherited from Element
Instance Method Summary collapse
-
#generate_string(options = nil) ⇒ String
protected
abstract
Defines the algorithm to generate a String representation from scratch.
-
#initialize(address, name, options = {}) ⇒ Entry
constructor
Initializes an entry.
-
#inspect ⇒ String
A String representation for debugging purposes.
Methods inherited from Element
#cache_filled?, #cache_string, #invalidate_cache!, #to_s
Constructor Details
#initialize(address, name, options = {}) ⇒ Entry
Initializes an entry.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/aef/hosts/entry.rb', line 57 def initialize(address, name, = {}) (, :aliases, :comment, :cache) raise ArgumentError, 'Address cannot be empty' unless address raise ArgumentError, 'Name cannot be empty' unless name @address = address.to_s @name = name.to_s @aliases = [:aliases] || [] @comment = [:comment].to_s unless [:comment].nil? @cache = [:cache].to_s unless [:cache].nil? end |
Instance Attribute Details
#address ⇒ String
The network address
31 32 33 |
# File 'lib/aef/hosts/entry.rb', line 31 def address @address end |
#aliases ⇒ Array<String>
Optional alias hostnames
46 47 48 |
# File 'lib/aef/hosts/entry.rb', line 46 def aliases @aliases end |
#comment ⇒ String
Optional comment
41 42 43 |
# File 'lib/aef/hosts/entry.rb', line 41 def comment @comment end |
#name ⇒ String
The primary hostname for the address
36 37 38 |
# File 'lib/aef/hosts/entry.rb', line 36 def name @name end |
Instance Method Details
#generate_string(options = nil) ⇒ String (protected)
This method is abstract.
This method needs to be implemented in descendant classes.
Defines the algorithm to generate a String representation from scratch.
111 112 113 114 115 116 117 118 119 |
# File 'lib/aef/hosts/entry.rb', line 111 def generate_string( = nil) if comment suffix = " ##{comment}\n" else suffix = "\n" end [address, name, *aliases].join(' ') << suffix end |
#inspect ⇒ String
A String representation for debugging purposes
101 102 103 |
# File 'lib/aef/hosts/entry.rb', line 101 def inspect generate_inspect(self, :address, :name, :aliases, :comment, :cache) end |