Module: AmsLayout

Defined in:
lib/ams_layout/cli/config.rb,
lib/ams_layout.rb,
lib/ams_layout/cli.rb,
lib/ams_layout/pages.rb,
lib/ams_layout/client.rb,
lib/ams_layout/parser.rb,
lib/ams_layout/writer.rb,
lib/ams_layout/version.rb,
lib/ams_layout/cli/generate.rb,
lib/ams_layout/delegate_writer.rb,
lib/ams_layout/pages/login_page.rb,
lib/ams_layout/pages/prequal_detail.rb

Overview

File

config.rb

Purpose

Config command

Author

Jeff McAffee 2014-07-08

Copyright

Copyright © 2014, kTech Systems LLC. All rights reserved.

Website

ktechsystems.com

Defined Under Namespace

Modules: Pages Classes: CLI, Client, Config, Configuration, DelegateWriter, Generate, Parser, Runner, Writer

Constant Summary collapse

CONFIG_FILE_NAME =
'.ams_layout'
VERSION =
"0.0.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



18
19
20
# File 'lib/ams_layout.rb', line 18

def client
  @client
end

.configurationObject

Returns the value of attribute configuration.



17
18
19
# File 'lib/ams_layout.rb', line 17

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

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.

Yields:



32
33
34
35
36
37
38
39
# 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_pathObject

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.



48
49
50
# 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) ⇒ Object

Load the configuration from disk

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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) ⇒ Object

Write configuration to disk

Writes to current working dir (pwd) if path is nil

Returns path of emitted file



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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