Class: ConfigToolkit::RubyReader

Inherits:
Reader
  • Object
show all
Defined in:
lib/configtoolkit/rubyreader.rb

Overview

This class implements the Reader interface for Ruby configuration files. Ruby configuration files essentially are key-value configuration files parsed by the Ruby interpreter; they allow the full Ruby language to be used while building up a configuration. Parameters are specified by config.param_name or config.containing_object.param_name. They can be assigned to and, after assignment, used in other expressions. If a name first is referred to with a setter (i.e., “age” in “config.first.second.age = 5”), then the name is assumed to be a parameter name. If a name first is referred to with a getter (i.e., “first” and “second” in “config.first.second.age = 5”), then the name is assumed to be an object name (either a containing or a nested configuration object). Objects cannot be set (i.e., “config.first.second = 2” is illegal). Parameter values, once set, can be referenced in later expressions.

See Ruby.txt for more details.

Defined Under Namespace

Classes: Interpreter

Instance Method Summary collapse

Methods inherited from Reader

stream_path

Constructor Details

#initialize(stream) ⇒ RubyReader

Description:

This constructs a RubyReader instance for stream, where stream either is a file name (a String) or an IO object.

Parameters:

stream

A file name (String) or an IO object. If stream is a file name, then the RubyReader will open the associated file.



42
43
44
45
46
47
48
49
50
# File 'lib/configtoolkit/rubyreader.rb', line 42

def initialize(stream)
  if(stream.class == String)
    @stream = File.open(stream, "r")
  else
    @stream = stream
  end

  @stream_path = Reader.stream_path(stream)
end

Instance Method Details

#readObject

Returns:

The contents of the ruby configuration file



264
265
266
267
# File 'lib/configtoolkit/rubyreader.rb', line 264

def read
  interpreter = Interpreter.new()
  return interpreter.interpret(@stream.read(), @stream_path)
end