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.1"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/config_file/config_file.rb', line 12 def config @config end |
Class Method Details
.register(type) ⇒ Object
4 5 6 |
# File 'lib/config_file/config_file.rb', line 4 def self.register(type) @types << type unless @types.include? type end |
.type(extension) ⇒ Object
8 9 10 |
# File 'lib/config_file/config_file.rb', line 8 def self.type(extension) @types.detect { |type| type.extensions.include? extension } end |
Instance Method Details
#load(file_name, ext = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/config_file/config_file.rb', line 14 def load file_name, ext=nil ext = File.extname(file_name) unless ext config_file_type = ConfigFile.type(ext) if config_file_type config_file = config_file_type.new @config = config_file.read file_name else raise ArgumentError, "Configuration from #{ext} is not supported" end end |