Class: ConfigFile
- Inherits:
-
Object
- Object
- ConfigFile
- Defined in:
- lib/config_file/version.rb,
lib/config_file/config_file.rb
Constant Summary collapse
- VERSION =
"1.0.0"- YAML_EXT =
'.yaml'- RUBY_EXT =
'.rb'- JSON_EXT =
'json'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/config_file/config_file.rb', line 10 def config @config end |
Instance Method Details
#load(file_name, ext = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/config_file/config_file.rb', line 12 def load file_name, ext=nil ext = File.extname(file_name) unless ext @config = case ext when YAML_EXT YAML.load_file(File.(file_name)) when RUBY_EXT content = File.open(file_name).read MetaMethods::Core.instance.block_to_hash(content) when JSON_EXT content = File.open(file_name).read JSON.parse(content) else content = File.open(file_name).read JSON.parse(content) end end |