module AmsLayout
- File
-
config.rb
- Purpose
-
Config
command - Author
-
Jeff McAffee 2014-07-08
- Copyright
-
Copyright © 2014, kTech Systems LLC. All rights reserved.
- Website
Constants
- CONFIG_FILE_NAME
- VERSION
Attributes
client[RW]
configuration[RW]
Public Class Methods
configure() { |configuration| ... }
click to toggle source
Setup ams_layout configuration
Attempts to find and load a configuration file the first time it’s requested. If a config file cannot be found on disk, a default configuration object is created.
If a block is provided, the configuration object is yielded to the block after the configuration is loaded/created.
# File lib/ams_layout.rb, line 32 def self.configure if self.configuration.nil? unless self.load_configuration self.configuration = Configuration.new end end yield(configuration) if block_given? end
find_config_path()
click to toggle source
Walk up the directory tree from current working dir (pwd) till a file named .ams_layout is found.
Returns file path if found, nil if not.
# File lib/ams_layout.rb, line 48 def self.find_config_path path = Pathname(Pathname.pwd).ascend{|d| h=d+CONFIG_FILE_NAME; break h if h.file?} end
load_configuration(path = nil)
click to toggle source
Load the configuration from disk
Returns true if config file found and loaded, false otherwise.
# File lib/ams_layout.rb, line 83 def self.load_configuration(path = nil) # If no path provided, see if we can find one in the dir tree. if path.nil? path = find_config_path end return false if path.nil? return false unless path.exist? File.open(path, 'r') do |f| self.configuration = YAML.load(f) puts "configuration loaded from #{path}" if $debug end true end
save_configuration(path = nil)
click to toggle source
Write configuration to disk
Writes to current working dir (pwd) if path is nil
Returns path of emitted file
# File lib/ams_layout.rb, line 60 def self.save_configuration(path = nil) # If no path provided, see if we can find one in the dir tree. if path.nil? path = find_config_path end # Still no path? Use the current working dir. if path.nil? path = Pathname.pwd + CONFIG_FILE_NAME end path = Pathname(path).expand_path File.write(path, YAML.dump(configuration)) path end