Class: Construqt::Flavour::Ciscian::Result
- Inherits:
-
Object
- Object
- Construqt::Flavour::Ciscian::Result
- Defined in:
- lib/construqt/flavour/ciscian/ciscian.rb
Defined Under Namespace
Classes: Lines
Instance Attribute Summary collapse
-
#dialect ⇒ Object
Returns the value of attribute dialect.
-
#host ⇒ Object
Returns the value of attribute host.
-
#sections ⇒ Object
Returns the value of attribute sections.
Class Method Summary collapse
Instance Method Summary collapse
- #add(section, clazz = NestedSection) {|| ... } ⇒ Object
- #commit ⇒ Object
-
#initialize(host) ⇒ Result
constructor
A new instance of Result.
- #parse(lines) ⇒ Object
- #parse_line(line, lines, section, result) ⇒ Object
Constructor Details
#initialize(host) ⇒ Result
Returns a new instance of Result.
21 22 23 24 25 26 27 28 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 21 def initialize(host) @host = host @sections = {} throw "ciscian flavour can only be created with dialect" unless host.dialect require_relative "dialect_#{host.dialect}.rb" throw "cannot load dialect class #{host.dialect}" unless Ciscian.dialects[host.dialect] self.dialect=Ciscian.dialects[host.dialect].new(self) end |
Instance Attribute Details
#dialect ⇒ Object
Returns the value of attribute dialect.
20 21 22 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 20 def dialect @dialect end |
#host ⇒ Object
Returns the value of attribute host.
20 21 22 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 20 def host @host end |
#sections ⇒ Object
Returns the value of attribute sections.
20 21 22 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 20 def sections @sections end |
Class Method Details
.compare(nu, old) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 122 def self.compare(nu, old) result = Result.new(nu.host) nu_root=NestedSection.new("root") nu_root.sections.merge!(nu.sections) other_root=NestedSection.new("root") other_root.sections.merge!(old.sections) deltas=NestedSection.compare(nu_root, other_root) throw "illegal state" if deltas.length != 1 result.sections = deltas[0] result end |
.normalize_section_key(key) ⇒ Object
78 79 80 81 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 78 def self.normalize_section_key(key) matchdata=key.match(/^\s*(no\s+|)(.*)/) matchdata[2] end |
.starts_with_no(key) ⇒ Object
83 84 85 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 83 def self.starts_with_no(key) return key.match(/^\s*no\s+/) end |
Instance Method Details
#add(section, clazz = NestedSection) {|| ... } ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 106 def add(section, clazz=NestedSection) throw "section is nil" unless section section = Lines::Line.new(section, -1) unless section.kind_of?(Lines::Line) section_key=Result.normalize_section_key(section.to_s) @sections[section_key] ||= clazz.new(section_key) if Result.starts_with_no(section.to_s) @sections[section_key].no else @sections[section_key].yes end yield(@sections[section_key]) if block_given? @sections[section_key] end |
#commit ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 94 def commit self.dialect.commit block=[] @sections.keys.sort.each do |key| section = @sections[key] block += section.serialize end Util.write_str(block.join("\n"), File.join(@host.name, "#{@host.fname||self.dialect.class.name}.cfg")) end |
#parse(lines) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 69 def parse(lines) lines = Lines.new(lines) while line = lines.shift parse_line(line, lines, self, self) end self end |
#parse_line(line, lines, section, result) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/construqt/flavour/ciscian/ciscian.rb', line 87 def parse_line(line, lines, section, result) return if self.dialect.parse_line(line, lines, section, result) [NestedSection, SingleValueVerb].find do |clazz| clazz.parse_line(line, lines, section, result) end end |