Class: Gem::Command

Inherits:
Object show all
Defined in:
lib/g-gem/gems_extensions.rb

Overview

class Gem::DependencyList

Direct Known Subclasses

Portage::Command

Defined Under Namespace

Modules: WithPortage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.WithPortage(methname, &block) ⇒ Object

module WithPortage



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/g-gem/gems_extensions.rb', line 91

def self.WithPortage(methname, &block)
  Module.new do
    include WithPortage     

    if block
      define_method("maybe_#{methname}_with_portage".intern, &block)
    else
      module_eval <<-MAYBE
      def maybe_#{methname}_with_portage(*args, &prc)
        if with_portage?
          #{methname}_with_portage(*args, &prc)
        else
          #{methname}_without_portage(*args, &prc)
        end
      end
      MAYBE
    end

    singleton_eval do # class << self
      define_method(:append_features) do |mod|
        super
        mod.singleton_eval do # class << mod
          define_method(:extend_object) do |obj|
            super
            obj.singleton_eval <<-ALIAS # class << obj
            alias_method :#{methname}_without_portage, :#{methname}
            alias_method :#{methname}, :maybe_#{methname}_with_portage
            ALIAS
            obj.instance_eval do 
              add_option '--[no-]portage', 
              "#{command.capitalize} using the portage system" do |v, h|
                h[:with_portage] = v
              end
            end
            obj.instance_eval &block if block
          end
        end
      end
    end
  end # WithPortage anon module
end

Instance Method Details

#handle_options_with_portage(args) ⇒ Object Also known as: handle_options



44
45
46
47
48
49
50
# File 'lib/g-gem/gems_extensions.rb', line 44

def handle_options_with_portage(args)
  port_arg = args.index('--portage')
  port_arg = args.slice!(port_arg.succ .. -1) if port_arg
  handle_options_without_portage(args)
  @options[:portage_args] = port_arg if port_arg
  @options[:args]
end