Class: NetConfGen::BlockEngine
- Inherits:
-
Object
- Object
- NetConfGen::BlockEngine
- Defined in:
- lib/netconfgen/netconfgen.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#initialize(basepath, settings = nil) ⇒ BlockEngine
constructor
A new instance of BlockEngine.
- #load(name) ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(basepath, settings = nil) ⇒ BlockEngine
Returns a new instance of BlockEngine.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/netconfgen/netconfgen.rb', line 124 def initialize(basepath, settings=nil) @basepath = basepath @settings = settings if !File.directory?(basepath) raise "Basepath #{basepath} does not exists" end @suffix = '.txt' @blocks = {} @context = BlockContext.new(self, @settings) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
123 124 125 |
# File 'lib/netconfgen/netconfgen.rb', line 123 def context @context end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
123 124 125 |
# File 'lib/netconfgen/netconfgen.rb', line 123 def settings @settings end |
Instance Method Details
#load(name) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/netconfgen/netconfgen.rb', line 141 def load(name) if @blocks[name] return @blocks[name] end @code = ''; File.open(@basepath + '/' + name + @suffix, "r") do |f| code_started = false code = '' f.each_line do |line| if line == "<code>\n" code_started = true elsif line == "</code>\n" || line == "</code>" code_started = false elsif code_started == true code += line end end block = Block.new(name) block.code = code block.blockengine = self @blocks[name] = block return block end end |
#set(key, value) ⇒ Object
137 138 139 |
# File 'lib/netconfgen/netconfgen.rb', line 137 def set(key, value) @context.instance_variable_set("@" + key, value) end |