vagrant/lib/hobo/config.rb

29 lines
506 B
Ruby
Raw Normal View History

2010-01-22 05:54:23 +00:00
module Hobo
class Config
@@settings = nil
2010-01-22 05:54:23 +00:00
class << self
def settings
@@settings
2010-01-22 05:54:23 +00:00
end
2010-01-22 07:38:23 +00:00
def from_hash!(hash)
@@settings = hash_to_struct(hash)
2010-01-22 05:54:23 +00:00
end
private
2010-01-22 07:38:23 +00:00
def hash_to_struct(value)
2010-01-22 05:54:23 +00:00
return value unless value.instance_of?(Hash)
result = value.inject({}) do |acc, pair|
2010-01-22 07:38:23 +00:00
acc[pair.first] = hash_to_struct(pair.last)
2010-01-22 05:54:23 +00:00
acc
end
OpenStruct.new(result)
end
end
end
end