Skip to content

Commit

Permalink
Configuration files are now parsed through ERB filter before being pa…
Browse files Browse the repository at this point in the history
…rsed. [#48 state:resolved]
  • Loading branch information
mtodd committed Jun 19, 2008
1 parent a912bff commit 4855dd4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/halcyon/config/file.rb
@@ -1,3 +1,5 @@
require 'erb'

module Halcyon
class Config

Expand All @@ -14,15 +16,19 @@ class File

# Creates a profile with the default paths.
#
def initialize(file)
# * +file+ is the path to the file.
# * +filter_config+ specifies whether to filter the contents through ERB
# before parsing it.
#
def initialize(file, filter_config = true)
if ::File.exist?(file)
self.path = file
elsif ::File.exist?(Halcyon.paths.for(:config)/file)
self.path = Halcyon.paths.for(:config)/file
else
raise ArgumentError.new("Could not find #{self.path} (it does not exist).")
end
self.content = ::File.read(self.path)
self.content = self.filter(::File.read(self.path), filter_config)
end

# Returns the loaded configuration file's contents parsed by the
Expand All @@ -47,6 +53,13 @@ def to_hash(from = :from_yaml)
end
end

# Filters the contents through ERB.
#
def filter(content, filter_through_erb)
content = ERB.new(content).result if filter_through_erb
content
end

def inspect
"#<Halcyon::Config::File #{self.path}>"
end
Expand Down

0 comments on commit 4855dd4

Please sign in to comment.