Class: FReCon::ConfigurationFile
- Defined in:
- lib/frecon/configuration_file.rb
Overview
Public: A class to handle configuration files.
Instance Attribute Summary collapse
-
#filename ⇒ Object
Public: The filename for the file.
Class Method Summary collapse
-
.config_directory ⇒ Object
Public: Returns the User’s config home directory.
-
.default ⇒ Object
Public: Create a new ConfigurationFile corresponding to the default defaults configuration location.
-
.system ⇒ Object
Public: Create a new ConfigurationFile corresponding to the default system configuration location.
-
.user ⇒ Object
Public: Create a new ConfigurationFile corresponding to the default user configuration location.
Instance Method Summary collapse
-
#initialize(filename) ⇒ ConfigurationFile
constructor
Public: Initialize a ConfigurationFile.
-
#read ⇒ Object
Public: Read from the file and generate a Configuration from the YAML data therein.
Constructor Details
#initialize(filename) ⇒ ConfigurationFile
Public: Initialize a ConfigurationFile.
filename - The name of the file.
22 23 24 |
# File 'lib/frecon/configuration_file.rb', line 22 def initialize(filename) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object
Public: The filename for the file.
17 18 19 |
# File 'lib/frecon/configuration_file.rb', line 17 def filename @filename end |
Class Method Details
.config_directory ⇒ Object
Public: Returns the User’s config home directory.
64 65 66 |
# File 'lib/frecon/configuration_file.rb', line 64 def self.config_directory ENV['XDG_CONFIG_HOME'] || File.join(Dir.home, '.config') end |
.default ⇒ Object
Public: Create a new ConfigurationFile corresponding to the default defaults configuration location.
45 46 47 |
# File 'lib/frecon/configuration_file.rb', line 45 def self.default self.new(File.(File.join(File.dirname(__FILE__), "..", "..", "config", "default.yml"))) end |
.system ⇒ Object
Public: Create a new ConfigurationFile corresponding to the default system configuration location.
51 52 53 |
# File 'lib/frecon/configuration_file.rb', line 51 def self.system self.new(File.join("", "etc", "frecon", "config.yml")) end |
.user ⇒ Object
Public: Create a new ConfigurationFile corresponding to the default user configuration location.
57 58 59 |
# File 'lib/frecon/configuration_file.rb', line 57 def self.user self.new(File.join(config_directory, "frecon.yml")) end |
Instance Method Details
#read ⇒ Object
Public: Read from the file and generate a Configuration from the YAML data therein.
Returns a Configuration representing the file’s data or nil if it didn’t exist.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/frecon/configuration_file.rb', line 31 def read begin data = open(@filename, "rb") do |io| io.read end Configuration.new(YAML.load(data)) rescue Errno::ENOENT nil end end |