Module: PortalModule
- Defined in:
- lib/portal_module/client.rb,
lib/portal_module.rb,
lib/portal_module/cli.rb,
lib/portal_module/dts.rb,
lib/portal_module/command.rb,
lib/portal_module/version.rb,
lib/portal_module/loan_entry.rb,
lib/portal_module/command/dts.rb,
lib/portal_module/page_factory.rb,
lib/portal_module/config_helper.rb,
lib/portal_module/command/config.rb,
lib/portal_module/command/loan_entry.rb,
lib/portal_module/command/client_access.rb
Overview
- File
-
client_access.rb
- Purpose
-
Module providing client access helper methods for CLI classes.
- Author
-
Jeff McAffee 2015-03-27
Defined Under Namespace
Modules: Command, Pages, Rake Classes: CLI, Client, ConfigHelper, Configuration, Dts, LoanEntry, PageFactory, Runner
Constant Summary collapse
- CONFIG_FILE_NAME =
'.portal_module'
- VERSION =
"0.0.3"
Class Attribute Summary collapse
-
.client ⇒ Object
Returns the value of attribute client.
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Object
Setup portal_module configuration.
-
.find_config_path ⇒ Object
Walk up the directory tree from current working dir (pwd) till a file named .portal_module is found.
-
.load_configuration(path = nil) ⇒ Object
Load the configuration from disk.
-
.save_configuration(path = nil) ⇒ Object
Write configuration to disk.
Class Attribute Details
.client ⇒ Object
Returns the value of attribute client.
29 30 31 |
# File 'lib/portal_module.rb', line 29 def client @client end |
.configuration ⇒ Object
Returns the value of attribute configuration.
28 29 30 |
# File 'lib/portal_module.rb', line 28 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
Setup portal_module configuration
Attempts to find and load a configuration file the first time it’s requested. If a config file cannot be found on in the current directory tree (moving towards trunk, not the leaves), 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.
44 45 46 47 48 49 50 51 |
# File 'lib/portal_module.rb', line 44 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 ⇒ Object
Walk up the directory tree from current working dir (pwd) till a file named .portal_module is found
Returns file path if found, nil if not.
60 61 62 |
# File 'lib/portal_module.rb', line 60 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) ⇒ Object
Load the configuration from disk
Returns true if config file found and loaded, false otherwise.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/portal_module.rb', line 99 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 Pathname(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) ⇒ Object
Write configuration to disk
Writes to current working dir (pwd) if path is nil
Returns path of emitted file
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/portal_module.rb', line 72 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 end unless path.to_s.end_with?('/' + CONFIG_FILE_NAME) path = Pathname(path) + CONFIG_FILE_NAME end path = Pathname(path). File.write(path, YAML.dump(configuration)) path end |