class PortalModule::Command::Config

Public Instance Methods

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

  with_loaded_config(true) do
    if PortalModule.configuration.base_urls.key? envname.to_sym
      PortalModule.configuration.default_environment = envname.to_sym
    else
      say "argument error: environment '#{envname}' has not been configured", :red
    end
  end
end
download_dir(dir=nil) click to toggle source
# File lib/portal_module/command/config.rb, line 293
def download_dir(dir=nil)
  if dir.nil?
    with_loaded_config do
      say "download dir: #{PortalModule.configuration.download_dir}"
    end
    return
  end

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

Private Instance Methods

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

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

  yield

  PortalModule.save_configuration if save
end