class Build::Rule
A rule is a function with a specific set of input and output parameters, which can match against a given set of specific arguments. For example, there might be several rules for compiling, but the specific rules depend on the language being compiled.
Attributes
full_name[R]
compile_cpp
name[R]
compile.cpp
parameters[R]
primary_output[R]
process_name[R]
compile
Public Class Methods
build(name, &block)
click to toggle source
# File lib/build/rule.rb, line 24 def self.build(name, &block) rule = self.new(*name.split('.', 2)) rule.instance_eval(&block) return rule.freeze end
new(process_name, type)
click to toggle source
# File lib/build/rule.rb, line 116 def initialize(process_name, type) @name = process_name + "." + type @full_name = @name.gsub(/[^\w]/, '_') @process_name = process_name.gsub('-', '_').to_sym @type = type @apply = nil @parameters = [] @primary_output = nil end
Public Instance Methods
<<(parameter)
click to toggle source
# File lib/build/rule.rb, line 169 def << parameter @parameters << parameter if parameter.output? @primary_output ||= parameter end end
applicable?(arguments)
click to toggle source
Check if this rule can process these parameters
# File lib/build/rule.rb, line 178 def applicable?(arguments) @parameters.each do |parameter| next if parameter.implicit? return false unless parameter.applicable?(arguments) end return true end
apply(&block)
click to toggle source
# File lib/build/rule.rb, line 218 def apply(&block) @apply = Proc.new(&block) end
apply!(scope, arguments)
click to toggle source
# File lib/build/rule.rb, line 222 def apply!(scope, arguments) scope.instance_exec(arguments, &@apply) if @apply end
eql?(other)
click to toggle source
# File lib/build/rule.rb, line 236 def eql?(other) other.kind_of?(self.class) and @name.eql?(other.name) and @parameters.eql?(other.parameters) end
files(arguments)
click to toggle source
# File lib/build/rule.rb, line 197 def files(arguments) input_files = [] output_files = [] @parameters.each do |parameter| # This could probably be improved a bit, we are assuming all parameters are file based: value = arguments[parameter.name] next unless value case parameter.direction when :input input_files << value when :output output_files << value end end return Build::Files::Composite.new(input_files), Build::Files::Composite.new(output_files) end
freeze()
click to toggle source
Calls superclass method
# File lib/build/rule.rb, line 142 def freeze return self if frozen? @name.freeze @full_name.freeze @process_name.freeze @type.freeze @apply.freeze @parameters.freeze @primary_output.freeze super end
hash()
click to toggle source
# File lib/build/rule.rb, line 232 def hash [self.class, @name, @parameters].hash end
input(name, options = {}, &block)
click to toggle source
# File lib/build/rule.rb, line 157 def input(name, options = {}, &block) self << Parameter.new(:input, name, options, &block) end
normalize(arguments, scope)
click to toggle source
The scope is the context in which the dynamic rule computation is done, usually an instance of Task
.
# File lib/build/rule.rb, line 189 def normalize(arguments, scope) Hash[ @parameters.collect do |parameter| [parameter.name, parameter.compute(arguments, scope)] end ] end
output(name, options = {}, &block)
click to toggle source
# File lib/build/rule.rb, line 165 def output(name, options = {}, &block) self << Parameter.new(:output, name, options, &block) end
parameter(name, options = {}, &block)
click to toggle source
# File lib/build/rule.rb, line 161 def parameter(name, options = {}, &block) self << Parameter.new(:argument, name, options, &block) end
result(arguments)
click to toggle source
# File lib/build/rule.rb, line 226 def result(arguments) if @primary_output arguments[@primary_output.name] end end
to_s()
click to toggle source
# File lib/build/rule.rb, line 240 def to_s "#<#{self.class} #{@name.dump}>" end