Sha256: 279305b28d44613ce7c645d0ae55cb35474567c1b0f79bba9dcfc0ba25722c7b

Contents?: true

Size: 883 Bytes

Versions: 6

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

require 'thor'

# Allows us to use variables passed into a Thor class's `config[:locals]`
# Allows us to call the variables passed into `config[:locals]` as methods
# in our cli classes
module ThorInstanceVariableHook
  def method_missing method, *args, &block
    var = instance_variable_get(:@_initializer).last[:locals][method]
    return var unless var.nil?

    super
  end

  def respond_to_missing? name, include_private = false
    super
  end
end

module ThorInteractive
  # Don't show app name in command help, i.e, instead of
  # `app command desc`, use `command desc`
  def banner task, _namespace = false, subcommand = false
    task.formatted_usage(self, false, subcommand).to_s
  end

  # Include the instance variable to method hook in our cli classes
  def self.extended base
    base.send :include, ThorInstanceVariableHook
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
whatup-0.3.5 lib/whatup/cli/thor_interactive.rb
whatup-0.3.4 lib/whatup/cli/thor_interactive.rb
whatup-0.3.3 lib/whatup/cli/thor_interactive.rb
whatup-0.3.2 lib/whatup/cli/thor_interactive.rb
whatup-0.3.1 lib/whatup/cli/thor_interactive.rb
whatup-0.3.0 lib/whatup/cli/thor_interactive.rb