module PortalModule

File

client.rb

Purpose

PortalModule client object

Author

Jeff McAffee 2015-03-27

File

command.rb

Purpose

Command module for Thor commands

Author

Jeff McAffee 03/28/2015

File

client_access.rb

Purpose

Module providing client access helper methods for CLI classes.

Author

Jeff McAffee 2015-03-27

File

config.rb

Purpose

Config command

Author

Jeff McAffee 2015-03-27

File

dts.rb

Purpose

DTS command line interface

Author

Jeff McAffee 2015-03-27

File

loan_entry.rb

Purpose

LoanEntry command line interface

Author

Jeff McAffee 2015-03-29

File

config_helper.rb

Purpose

Configuration object wrapper

Author

Jeff McAffee 2015-03-29

Constants

CONFIG_FILE_NAME
VERSION

Attributes

client[RW]
configuration[RW]

Public Class Methods

configure() { |configuration| ... } click to toggle source

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.

# 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() click to toggle source

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.

# 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) click to toggle source

Load the configuration from disk

Returns true if config file found and loaded, false otherwise.

# 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) 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/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).expand_path
  File.write(path, YAML.dump(configuration))

  path
end