Module: ConfigSL::FileSupport::ClassMethods
- Defined in:
- lib/configsl/file_support.rb
Overview
Required class methods to support file operations.
Instance Method Summary collapse
-
#config_file_name(filename = nil) ⇒ String
The default name to use for the configuration file.
-
#config_file_path(path = nil) ⇒ String
The default path to use for the configuration file.
-
#file_extensions(format: nil) ⇒ Array<String>
The file extensions supported by this configuration.
-
#register_file_format(format, opts = {}) ⇒ Object
Register support for a file format.
Instance Method Details
#config_file_name(filename = nil) ⇒ String
The default name to use for the configuration file.
29 30 31 32 |
# File 'lib/configsl/file_support.rb', line 29 def config_file_name(filename = nil) @config_file_name = filename unless filename.nil? @config_file_name ||= 'config' end |
#config_file_path(path = nil) ⇒ String
The default path to use for the configuration file.
38 39 40 41 |
# File 'lib/configsl/file_support.rb', line 38 def config_file_path(path = nil) @config_file_path = path unless path.nil? @config_file_path ||= '.' end |
#file_extensions(format: nil) ⇒ Array<String>
The file extensions supported by this configuration.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/configsl/file_support.rb', line 48 def file_extensions(format: nil) @config_file_formats ||= {} if format return @config_file_formats[format][:extensions] if @config_file_formats.key?(format) raise FileFormatError, "File format not found: #{format}" end @config_file_formats.values.map { |o| o[:extensions] }.flatten end |
#register_file_format(format, opts = {}) ⇒ Object
Register support for a file format.
67 68 69 70 71 72 73 |
# File 'lib/configsl/file_support.rb', line 67 def register_file_format(format, opts = {}) @config_file_formats ||= {} opts[:class] ||= ConfigSL::FileFormat.const_get(format.capitalize) opts[:extensions] ||= opts[:class].extensions @config_file_formats[format] = opts end |