Sha256: 90bd5293e26fbedfa46d10fc20612339fd85540c39ca870a829b310db2b08c7d

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

require 'rprogram/extensions/meta'
require 'rprogram/compat'

module RProgram
  module Nameable
    def self.included(base)
      base.metaclass_eval do
        #
        # Returns the name of the program.
        #
        def program_name
          @program_name ||= nil
        end

        #
        # Returns an Array of the program's aliases.
        #
        def program_aliases
          @program_aliases ||= []
        end

        #
        # Returns an Array of all names the program is known by, combining
        # both program_name and program_aliases.
        #
        def program_names
          ([program_name] + program_aliases).compact
        end

        #
        # Sets the program name for a class to the specified _name_.
        #
        #   name_program 'ls'
        #
        def name_program(name)
          @program_name = name.to_s
        end

        #
        # Sets the program aliases for a class to the specified _aliases_.
        #
        #   alias_program 'vim', 'vi'
        #
        def alias_program(*aliases)
          @program_aliases = aliases.map { |name| name.to_s }
        end
      end
    end

    #
    # Returns the program name of a class.
    #
    def program_name
      self.class.program_name
    end

    #
    # Returns the program aliases.
    #
    def program_aliases
      self.class.program_aliases
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rprogram-0.1.0 lib/rprogram/nameable.rb
rprogram-0.1.1 lib/rprogram/nameable.rb
rprogram-0.1.2 lib/rprogram/nameable.rb
rprogram-0.1.3 lib/rprogram/nameable.rb
rprogram-0.1.5 lib/rprogram/nameable.rb
rprogram-0.1.4 lib/rprogram/nameable.rb