module SleepingKingStudios::Tasks::Task::ClassMethods

Public Instance Methods

description() click to toggle source

@return [String] The description of the task.

# File lib/sleeping_king_studios/tasks/task.rb, line 14
def description
  'A non-descript task if ever there was one.'
end
option(option_name, option_params) click to toggle source

Defines a permitted option for the task.

@param option_name [String, Symbol] The name of the option. @param option_params [Hash] Additional params for the option.

@see github.com/erikhuda/thor/wiki/Method-Options

# File lib/sleeping_king_studios/tasks/task.rb, line 24
def option option_name, option_params
  options[option_name] = option_params

  define_helpers option_name, option_params
end
options() click to toggle source

@return [Hash] The permitted options for the task.

# File lib/sleeping_king_studios/tasks/task.rb, line 31
def options
  @options ||= {}
end
task_name() click to toggle source

@return [String] The name of the task.

# File lib/sleeping_king_studios/tasks/task.rb, line 36
def task_name
  tools = SleepingKingStudios::Tools::Toolbelt.instance

  tools.str.underscore(name.split('::').last).sub(/_task$/, '')
end

Private Instance Methods

define_helpers(option_name, option_params) click to toggle source
# File lib/sleeping_king_studios/tasks/task.rb, line 44
def define_helpers option_name, option_params
  tools = SleepingKingStudios::Tools::Toolbelt.instance
  name  = tools.str.underscore option_name

  define_method(name) { options[option_name.to_s] }

  return unless option_params[:type] == :boolean

  default = option_params.fetch(:default, false)
  define_method(:"#{name}?") { options.fetch(option_name.to_s, default) }
end