Class: ConfigToolkit::Reader

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

Overview

This is an “abstract class” that documents the Reader interface. I put “abstract class” in quotes because Ruby of course neither supports nor requires abstract classes (that is, one can create a new reader class without extending Reader). It solely serves to document the interface.

Readers read data (the read method) from some underlying source and return configuration represented as a Hash of parameter names to parameter values. The parameter names can be either Strings or Symbols; the parameter values can be scalars, Hashes, or Arrays. Array or Hash parameter values can in turn have Arrays or Hash elements, arbitrarily deeply nested.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.stream_path(stream) ⇒ Object

Description:

This class method attempts to find a file system path for stream, where stream is an argument passed to a reader constructor (if a String, then stream names a file; otherwise, stream should be an IO or IO-like object) This is used by several of the the reader classes.

Parameters:

stream

The underlying data source passed to a reader’s constructor

Returns:

The file system path for stream, or nil if unable to find this



37
38
39
40
41
42
43
44
45
# File 'lib/configtoolkit/reader.rb', line 37

def self.stream_path(stream)
  if(stream.is_a?(String))
    return Pathname.new(stream) # stream must be a file name
  elsif(stream.is_a?(File))
    return Pathname.new(stream.path())
  else
    return nil # Who knows?
  end
end

Instance Method Details

#readObject

This reads and returns configuration represented as a Hash, where the elements are parameter names (Strings or Symbols) mapping to parameter values.

This must be implemented by Readers.

Returns:

The contents of a configuration as a Hash

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/configtoolkit/reader.rb', line 57

def read
  raise NotImplementedError, "abstract method called"
end