2010-01-22 05:54:23 +00:00
|
|
|
module Hobo
|
|
|
|
class Config
|
2010-01-22 07:57:43 +00:00
|
|
|
@@settings = nil
|
2010-01-22 05:54:23 +00:00
|
|
|
class << self
|
2010-01-22 07:57:43 +00:00
|
|
|
|
|
|
|
def settings
|
|
|
|
@@settings
|
2010-01-22 05:54:23 +00:00
|
|
|
end
|
|
|
|
|
2010-01-22 07:38:23 +00:00
|
|
|
def from_hash!(hash)
|
2010-01-22 07:57:43 +00:00
|
|
|
@@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
|