Sha256: 65a8d39dd724ab53882e628862054a82f35fa207973d6eb9290390a9b6121d50

Contents?: true

Size: 1.64 KB

Versions: 79

Compression:

Stored size: 1.64 KB

Contents

module Rake

  ####################################################################
  # TaskArguments manage the arguments passed to a task.
  #
  class TaskArguments
    include Enumerable

    attr_reader :names

    # Create a TaskArgument object with a list of named arguments
    # (given by :names) and a set of associated values (given by
    # :values).  :parent is the parent argument object.
    def initialize(names, values, parent=nil)
      @names = names
      @parent = parent
      @hash = {}
      names.each_with_index { |name, i|
        @hash[name.to_sym] = values[i] unless values[i].nil?
      }
    end

    # Create a new argument scope using the prerequisite argument
    # names.
    def new_scope(names)
      values = names.collect { |n| self[n] }
      self.class.new(names, values, self)
    end

    # Find an argument value by name or index.
    def [](index)
      lookup(index.to_sym)
    end

    # Specify a hash of default values for task arguments. Use the
    # defaults only if there is no specific value for the given
    # argument.
    def with_defaults(defaults)
      @hash = defaults.merge(@hash)
    end

    def each(&block)
      @hash.each(&block)
    end

    def values_at(*keys)
      keys.map { |k| lookup(k) }
    end

    def method_missing(sym, *args, &block)
      lookup(sym.to_sym)
    end

    def to_hash
      @hash
    end

    def to_s
      @hash.inspect
    end

    def inspect
      to_s
    end

    protected

    def lookup(name)
      if @hash.has_key?(name)
        @hash[name]
      elsif @parent
        @parent.lookup(name)
      end
    end
  end

  EMPTY_TASK_ARGS = TaskArguments.new([], [])
end

Version data entries

79 entries across 65 versions & 20 rubygems

Version Path
gss-0.0.7 vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
gss-0.0.6 vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
gss-0.0.5 vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
candlepin-api-0.4.0 bundle/ruby/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
simple-client-0.0.3 vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
challah-rolls-0.2.0 vendor/bundle/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
challah-0.8.3 vendor/bundle/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
challah-0.8.1 vendor/bundle/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
challah-rolls-0.1.0 vendor/bundle/gems/rake-0.9.2.2/lib/rake/task_arguments.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task_arguments.rb