Method: Rconftool::ConfigFile#read

Defined in:
lib/rconftool.rb

#read(filename) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/rconftool.rb', line 211

def read(filename)
  @version = nil
  curr_setting = Setting.new(HEADER_ID,'')
  @settings = [curr_setting]
  @settings_hash = {}

  File.open(filename) do |f|
    # VERSION header must occur within first 20 lines
    20.times do
      line = f.gets
      break unless line
    linetmp = line.chop + "\r\n"
      curr_setting << linetmp
      if line =~ /\A##VERSION:/
        @version = line.chop
        break
      end
    end
    raise NoVersionLine, "#{filename}: No VERSION line found" unless @version

    while line = f.gets
      unless line =~ /\A##NAME:(.*):(.*)/
linetmp = line.chop + "\r\n"
        curr_setting << linetmp
        next
      end
      curr_setting = Setting.new($1,$2)
      @settings << curr_setting
      @settings_hash[curr_setting.name] = curr_setting
    end
  end
end