Skip to content

Commit

Permalink
add loading config values from ini file.
Browse files Browse the repository at this point in the history
  • Loading branch information
funny-falcon committed Jun 8, 2012
1 parent 2f03f15 commit 7b91836
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/funfig/group.rb
Expand Up @@ -26,6 +26,7 @@ def update(hash)
self.send("#{k}=", v)
}
end
self
end

# Iterate over parameter names
Expand Down
28 changes: 27 additions & 1 deletion lib/funfig/load.rb
@@ -1,4 +1,5 @@
require 'funfig/load_proxy'
require 'funfig/ini_parser'
module Funfig
class Group
# Update config by yaml file
Expand All @@ -7,6 +8,24 @@ def load_yaml(filename)
update(params)
end

# Update config by yaml string
def load_yaml_string(string)
params = YAML.load(string)
update(params)
end

# Update config by ini file
def load_ini(filename)
params = IniParser.parse_file(filename)
update(params)
end

# Update config by ini string
def load_ini_string(string, file = nil)
params = IniParser.new.parse(string, file)
update(params)
end

# Update config by evaluating ruby file
def load_ruby(file)
rb = File.read(file)
Expand All @@ -32,11 +51,16 @@ def exec(&block)
end

class Root
# Load config for schema from yaml file
# Load config from yaml file
def self.from_yaml_file(file)
self.new.load_yaml(file)
end

# Load config from ini file
def self.from_ini_file(file)
self.new.load_ini(file)
end

# Evaluate config file inside of configuration object
def self.from_ruby_file(file)
self.new.load_ruby(file)
Expand All @@ -46,6 +70,8 @@ def self.from_file(file)
case file
when /\.yml$/, /\.yaml$/
from_yaml_file(file)
when /\.ini$/
from_ini_file(file)
when /\.rb$/
from_ruby_file(file)
when Hash
Expand Down

0 comments on commit 7b91836

Please sign in to comment.