class Build::Rule::Parameter

Attributes

direction[R]
dynamic[R]
name[R]
options[R]

Public Class Methods

new(direction, name, options = {}, &block) click to toggle source
# File lib/build/rule.rb, line 33
def initialize(direction, name, options = {}, &block)
        @direction = direction
        @name = name
        
        @options = options
        
        @dynamic = block_given? ? Proc.new(&block) : nil
end

Public Instance Methods

applicable?(arguments) click to toggle source
# File lib/build/rule.rb, line 74
def applicable? arguments
        value = arguments.fetch(@name) do
                # Value couldn't be found, if it wasn't optional, this parameter didn't apply:
                return optional?
        end
        
        # If a pattern is provided, we must match it.
        if pattern = @options[:pattern]
                return Array(value).all? {|item| pattern.match(item)}
        end
        
        return true
end
compute(arguments, scope) click to toggle source
# File lib/build/rule.rb, line 88
def compute(arguments, scope)
        if implicit?
                # Can be replaced if supplied:
                arguments[@name] || scope.instance_exec(arguments, &@dynamic) || @options[:default]
        elsif dynamic?
                # Argument is optional:
                scope.instance_exec(arguments[@name], arguments, &@dynamic) || @options[:default]
        elsif arguments.key?(@name)
                arguments[@name]
        else
                @options[:default]
        end
end
default?() click to toggle source

Do we have a default value for this parameter?

# File lib/build/rule.rb, line 61
def default?
        @options.key?(:default)
end
dynamic?() click to toggle source
# File lib/build/rule.rb, line 56
def dynamic?
        @dynamic != nil
end
eql?(other) click to toggle source

TODO fix implementation

# File lib/build/rule.rb, line 107
def eql? other
        other.kind_of?(self.class) and @direction.eql?(other.direction) and @name.eql?(other.name) and @options.eql?(other.options) # and @dynamic == other.dynamic
end
hash() click to toggle source
# File lib/build/rule.rb, line 102
def hash
        [self.class, @direction, @name, @options].hash
end
implicit?() click to toggle source
# File lib/build/rule.rb, line 65
def implicit?
        dynamic? and @options[:implicit]
end
input?() click to toggle source
# File lib/build/rule.rb, line 48
def input?
        @direction == :input
end
inspect() click to toggle source
# File lib/build/rule.rb, line 111
def inspect
        "#{direction}:#{@name} (#{options.inspect})"
end
optional?() click to toggle source

Optional parameters are those that are either defined as optional or implicit.

# File lib/build/rule.rb, line 70
def optional?
        @options[:optional] || implicit? || default?
end
output?() click to toggle source
# File lib/build/rule.rb, line 52
def output?
        @direction == :output
end