Sha256: 230937d59e163630add47bfb447faf2ff2c9ccba6b676f8747bf371004c4664f

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

# encoding: UTF-8
# frozen_string_literal: true

# Requirements
# =======================================================================

# Deps
# -----------------------------------------------------------------------
require 'nrser'


# Refinements
# =======================================================================

using NRSER
using NRSER::Types

# Declarations
# =======================================================================

module Thor::Base; end


# Definitions
# =======================================================================

# Mixin that provides "macros" for including common class options.
# 
module Thor::Base::CommonClassOptions
  @@messages = Concurrent::Hash.new
  
  def self.define name, *args, &block
    @@messages[name.to_sym] = \
      NRSER::Message.new :class_option, name, *args, &block
  end
  
  
  define  :backtrace,
          desc: "Print stack traces with error messages",
          type: :boolean
  
  
  def common_class_options *names
    messages = Hamster::Hash.new @@messages
    
    names.map( &:to_sym ).each do |name|
      unless messages.key? name
        raise KeyError,
          "No common class option named #{ name }"
      end
      
      messages[name].send_to self
    end
  end
  
end # module Thor::Base::CommonClassOptions

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atli-0.1.5 lib/thor/base/common_class_options.rb
atli-0.1.4 lib/thor/base/common_class_options.rb
atli-0.1.3 lib/thor/base/common_class_options.rb