Class: SC::TaskArguments

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/sproutcore/buildfile/task_arguments.rb

Overview

TaskAguments manage the arguments passed to a task. Borrowed from Rake 0.8.3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



73
74
75
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 73

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

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



16
17
18
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 16

def names
  @names
end

Class Method Details

.new(keys, values, parent = nil) ⇒ Object

for compatibility with normal TaskArguments



19
20
21
22
23
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 19

def self.new(keys, values, parent = nil)
  args = super()
  args.setup_with_arrays(keys, values, parent)
  args
end

.with_hash(hash) ⇒ Object



25
26
27
28
29
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 25

def self.with_hash(hash)
  args = allocate
  args.setup_with_hash(hash)
  args
end

Instance Method Details

#[](index) ⇒ Object

Find an argument value by name or index.



58
59
60
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 58

def [](index)
  lookup(index)
end

#each(&block) ⇒ Object



69
70
71
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 69

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

#inspectObject



85
86
87
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 85

def inspect
  to_s
end

#new_scope(names) ⇒ Object

Create a new argument scope using the prerequisite argument names.



52
53
54
55
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 52

def new_scope(names)
  values = names.collect { |n| self[n] }
  self.class.new(names, values, self)
end

#setup_with_arrays(keys, values, parent = nil) ⇒ Object

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.



40
41
42
43
44
45
46
47
48
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 40

def setup_with_arrays(keys, values, parent=nil)
  @names  = keys
  @parent = parent
  @hash   = {}

  names.each_with_index { |name, i|
    @hash[name.to_sym] = values[i] unless values[i].nil?
  }
end

#setup_with_hash(hash) ⇒ Object



31
32
33
34
35
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 31

def setup_with_hash(hash)
  @names  = hash.keys
  @parent = nil
  @hash   = hash
end

#to_hashObject



77
78
79
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 77

def to_hash
  @hash
end

#to_sObject



81
82
83
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 81

def to_s
  @hash.inspect
end

#with_defaults(defaults) ⇒ Object

Specify a hash of default values for task arguments. Use the defaults only if there is no specific value for the given argument.



65
66
67
# File 'lib/sproutcore/buildfile/task_arguments.rb', line 65

def with_defaults(defaults)
  @hash = defaults.merge(@hash)
end