class Sfn::Command

Constants

CONFIG_BASE_NAME

Base name of configuration file

VALID_CONFIG_EXTENSIONS

Supported configuration file extensions

Public Class Methods

new(cli_opts, args) click to toggle source

Override to provide config file searching

Calls superclass method
# File lib/sfn/command.rb, line 43
def initialize(cli_opts, args)
  unless cli_opts["config"]
    discover_config(cli_opts)
  end
  unless ENV["DEBUG"]
    ENV["DEBUG"] = "true" if cli_opts[:debug]
  end
  super(cli_opts, args)
  load_api_provider_extensions!
  run_callbacks_for(:after_config)
  run_callbacks_for("after_config_#{Bogo::Utility.snake(self.class.name.split("::").last)}")
end

Public Instance Methods

config() click to toggle source

@return [Smash]

Calls superclass method
# File lib/sfn/command.rb, line 57
def config
  memoize(:config) do
    super
  end
end

Protected Instance Methods

config_class() click to toggle source

@return [Class] attempt to return customized configuration class

Calls superclass method
# File lib/sfn/command.rb, line 111
def config_class
  klass_name = self.class.name.split("::").last
  if Sfn::Config.const_defined?(klass_name)
    Sfn::Config.const_get(klass_name)
  else
    super
  end
end
discover_config(opts) click to toggle source

Start with current working directory and traverse to root looking for a `.sfn` configuration file

@param opts [Slop] @return [Slop]

# File lib/sfn/command.rb, line 91
def discover_config(opts)
  cwd = Dir.pwd.split(File::SEPARATOR)
  detected_path = ""
  until cwd.empty? || File.exists?(detected_path.to_s)
    detected_path = Dir.glob(
      (cwd + ["#{CONFIG_BASE_NAME}{#{VALID_CONFIG_EXTENSIONS.join(",")}}"]).join(
        File::SEPARATOR
      )
    ).first
    cwd.pop
  end
  if opts.respond_to?(:fetch_option)
    opts.fetch_option("config").value = detected_path if detected_path
  else
    opts["config"] = detected_path if detected_path
  end
  opts
end
load_api_provider_extensions!() click to toggle source

Load API provider specific overrides to customize behavior

@return [TrueClass, FalseClass]

# File lib/sfn/command.rb, line 68
def load_api_provider_extensions!
  if config.get(:credentials, :provider)
    base_ext = Bogo::Utility.camel(config.get(:credentials, :provider)).to_sym
    targ_ext = self.class.name.split("::").last
    if ApiProvider.constants.include?(base_ext)
      base_module = ApiProvider.const_get(base_ext)
      ui.debug "Loading core provider extensions via `#{base_module}`"
      extend base_module
      if base_module.constants.include?(targ_ext)
        targ_module = base_module.const_get(targ_ext)
        ui.debug "Loading targeted provider extensions via `#{targ_module}`"
        extend targ_module
      end
      true
    end
  end
end