Sha256: 15fd749b0edeedabf0f4eee37d4663b868f9b66c273c7c043f24d22cf17c5676

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

module CommandKit
  #
  # Defines a place-holder {Help#help help} method.
  #
  # ## Examples
  #
  #     class MyCmd
  #       include CommandKit::Help
  #     
  #       def help
  #         puts "..."
  #       end
  #     end
  #     
  #     MyCmd.help
  #
  module Help
    #
    # @api private
    #
    module ModuleMethods
      #
      # Extends {ClassMethods} or {ModuleMethods}, depending on whether {Help}
      # is being included into a class or a module.
      #
      # @param [Class, Module] context
      #   The class or module which is extending {ClassMethods}.
      #
      def included(context)
        super(context)

        if context.class == Module
          context.extend ModuleMethods
        else
          context.extend ClassMethods
        end
      end
    end

    extend ModuleMethods

    #
    # Class-level methods.
    #
    module ClassMethods
      #
      # Prints `--help` information.
      #
      # @param [Hash{Symbol => Object}] kwargs
      #   Additional keyword arguments for `#initialize`.
      #
      # @see Help#help
      #
      # @api public
      #
      def help(**kwargs)
        new(**kwargs).help
      end
    end

    #
    # Prints `--help` information.
    #
    # @abstract
    #
    # @api public
    #
    def help
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
command_kit-0.5.0 lib/command_kit/help.rb
command_kit-0.4.1 lib/command_kit/help.rb
command_kit-0.4.0 lib/command_kit/help.rb
command_kit-0.3.0 lib/command_kit/help.rb
command_kit-0.2.2 lib/command_kit/help.rb
command_kit-0.2.1 lib/command_kit/help.rb
command_kit-0.2.0 lib/command_kit/help.rb
command_kit-0.1.0 lib/command_kit/help.rb