Class: Aef::Hosts::Section
- Defined in:
- lib/hosts/aef/hosts/section.rb
Overview
This represents a section as element of a hosts file. It consists of a header, futher included elements and a footer
Instance Attribute Summary collapse
-
#elements ⇒ Array<Aef::Host::Element>
Elements inside the section.
-
#name ⇒ String
Title of the section.
Attributes inherited from Element
Instance Method Summary collapse
-
#cache_filled? ⇒ true, false
Tells if a String representation is cached or not.
-
#initialize(name, options = {}) ⇒ Section
constructor
Initializes a section.
-
#inspect ⇒ String
A String representation for debugging purposes.
-
#invalidate_cache!(options = {}) ⇒ Aef::Hosts::Section
Deletes the cached String representation.
Methods inherited from Element
Constructor Details
#initialize(name, options = {}) ⇒ Section
Initializes a section
49 50 51 52 53 54 55 56 57 |
# File 'lib/hosts/aef/hosts/section.rb', line 49 def initialize(name, = {}) (, :cache, :elements) raise ArgumentError, 'Name cannot be empty' unless name @name = name.to_s @elements = [:elements] || [] @cache = [:cache] || {:header => nil, :footer => nil} end |
Instance Attribute Details
#elements ⇒ Array<Aef::Host::Element>
Note:
If the Array is modified in place, you need to manually invalidate the cache with option :only_section => true.
Elements inside the section
40 41 42 |
# File 'lib/hosts/aef/hosts/section.rb', line 40 def elements @elements end |
#name ⇒ String
Title of the section
32 33 34 |
# File 'lib/hosts/aef/hosts/section.rb', line 32 def name @name end |
Instance Method Details
#cache_filled? ⇒ true, false
Tells if a String representation is cached or not
78 79 80 |
# File 'lib/hosts/aef/hosts/section.rb', line 78 def cache_filled? !!@cache[:header] && !!@cache[:footer] end |
#inspect ⇒ String
A String representation for debugging purposes
99 100 101 |
# File 'lib/hosts/aef/hosts/section.rb', line 99 def inspect generate_inspect(self, :name, :cache, :elements) end |
#invalidate_cache!(options = {}) ⇒ Aef::Hosts::Section
Deletes the cached String representation
65 66 67 68 69 70 71 72 73 |
# File 'lib/hosts/aef/hosts/section.rb', line 65 def invalidate_cache!( = {}) @cache = {:header => nil, :footer => nil} unless [:only_section] elements.each do |element| element.invalidate_cache! end end end |