class AmsLayout::Config

Public Instance Methods

defenv(envname=nil) click to toggle source
# File lib/ams_layout/cli/config.rb, line 217
def defenv(envname=nil)
  if envname.nil?
    with_loaded_config do
      say "default environment: #{AmsLayout.configuration.default_environment}"
    end
    return
  end

  with_loaded_config(true) do
    if AmsLayout.configuration.base_urls.key? envname.to_sym
      AmsLayout.configuration.default_environment = envname.to_sym
    else
      say "argument error: environment '#{envname}' has not been configured"
    end
  end
end
init(filedir = nil) click to toggle source
# File lib/ams_layout/cli/config.rb, line 173
def init(filedir = nil)
  if filedir.nil?
    filedir = Pathname.pwd + AmsLayout::CONFIG_FILE_NAME
  else
    filedir = Pathname(filedir) + AmsLayout::CONFIG_FILE_NAME unless filedir.to_s.end_with?("/#{AmsLayout::CONFIG_FILE_NAME}")
  end

  outpath = AmsLayout.save_configuration filedir
  say("configuration written to #{outpath.to_s}", :green) unless options[:quiet]
end
timeout(seconds=nil) click to toggle source
# File lib/ams_layout/cli/config.rb, line 194
def timeout(seconds=nil)
  if seconds.nil?
    with_loaded_config do
      say "browser timeout: #{AmsLayout.configuration.browser_timeout}"
    end
  else
    with_loaded_config(true) do
      AmsLayout.configuration.browser_timeout = Integer(seconds)
    end
  end
rescue ArgumentError => e
  say 'argument error: seconds must be an integer'
end

Private Instance Methods

with_loaded_config(save = false) { || ... } click to toggle source
# File lib/ams_layout/cli/config.rb, line 236
def with_loaded_config save = false
  fail "expecting block" unless block_given?

  unless AmsLayout.load_configuration
    say "Configuration file not found!", :red
    say "Have you tried 'config init' first?"
    return
  end

  yield

  AmsLayout.save_configuration if save
end