class R::Target

The base target class.

It has simple building logic and a way to register targets. All targets should inherit from this class.

Public Instance Methods

build() click to toggle source

Build.

This is a simple build method. It calls {#build_dependancies} then {#build_self}. Either or both of these methods can be overwritten to customize the build or this function can be overwritten to have more control.

@return [void]

# File lib/rub/r/target.rb, line 180
def build
        build_dependancies
        build_self
        
        nil
end
clean?() click to toggle source

Is this target up to date?

# File lib/rub/r/target.rb, line 116
def clean?
        false
end
description() click to toggle source

Description.

Shown for :help. @return [String,nil]

# File lib/rub/r/target.rb, line 100
def description
        nil
end
hash_input() click to toggle source

Return a hash of this target.

This hash should represent a unique build environment and change if anything in that environment does. This includes, but is not limited to:

  • Input files.

  • Output files.

  • Build commands.

@return [String] the hash.

# File lib/rub/r/target.rb, line 130
def hash_input
        Digest::SHA1.digest(
                (
                        input.map{|i| R::get_target(i).hash_output(i) }
                ).join
        )
end
hash_output(t) click to toggle source
# File lib/rub/r/target.rb, line 139
def hash_output(t)
        if t.is_a? Symbol
                @@symbolcounter++
                "symbol-#{@@symbolcounter.to_s(16)}" # Never clean.
        else
                Digest::SHA1.file(t).to_s
        end
end
hash_outputs(t = output) click to toggle source
# File lib/rub/r/target.rb, line 148
def hash_outputs(t = output)
        Digest::SHA1.digest(t.map{|o| hash_output(o)}.join)
end
hash_self() click to toggle source
# File lib/rub/r/target.rb, line 152
def hash_self
        Digest::SHA1.digest(hash_input+hash_outputs)
end
input() click to toggle source

Inputs

@return [Set<Pathname>] The inputs this target depends on.

# File lib/rub/r/target.rb, line 85
def input
        Set.new
end
output() click to toggle source

Outputs

@return [Set<Pathname>] The outputs this target creates.

# File lib/rub/r/target.rb, line 92
def output
        Set.new
end
register() click to toggle source

Register this target.

Registers this target as building it’s {#output}s.

@return [void]

# File lib/rub/r/target.rb, line 109
def register
        output.each do |d|
                R.set_target(d, self)
        end
end

Private Instance Methods

build_dependancies() click to toggle source

Build the inputs.

# File lib/rub/r/target.rb, line 157
def build_dependancies
        input.each{|i| R::get_target(i).build }
end
build_self() click to toggle source

@return [void]

# File lib/rub/r/target.rb, line 167
def build_self
        raise "#build_self not implemented in #{self.class}."
end