Class: Rubu::Step

Inherits:
Move
  • Object
show all
Includes:
MoveStyles
Defined in:
lib/rubu.rb

Overview

Step in Trail. Step takes one or more sources, and turns them into one or more targets.

Direct Known Subclasses

StepAged, StepAlways, StepMark

Instance Attribute Summary (collapse)

Attributes inherited from Move

#errmsg, #output, #status, #subs

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from MoveStyles

#parallel_run, #serial_run

Methods inherited from Move

#display, #error, #host, #host_in, #host_out, #use

Constructor Details

- (Step) initialize(sources = [], targets = [])

Create Step object.

Parameters:

  • sources (defaults to: [])

    One or more sources.

  • targets (defaults to: [])

    One or more targets.



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/rubu.rb', line 500

def initialize( sources = [], targets = [] )
    super()

    unless sources.kind_of? Array
        @sources = [ sources ]
    else
        @sources = sources
    end

    unless targets.kind_of? Array
        @targets = [ targets ]
    else
        @targets = targets
    end

    setup
end

Instance Attribute Details

- (Object) sources (readonly)

Returns the value of attribute sources



493
494
495
# File 'lib/rubu.rb', line 493

def sources
  @sources
end

- (Object) targets (readonly)

Returns the value of attribute targets



494
495
496
# File 'lib/rubu.rb', line 494

def targets
  @targets
end

Class Method Details

+ (Object) use(sources = [], targets = [])

Create Move and register.

Parameters:

  • sources (defaults to: [])

    One or more sources.

  • targets (defaults to: [])

    One or more targets.



467
468
469
# File 'lib/rubu.rb', line 467

def self.use( sources = [], targets = [] )
    self.new( sources, targets ).use
end

+ (Object) usezip(sources, targets)

Combine list of sources and targets to source/target pairs and register.

Parameters:

  • sources

    List of sources.

  • targets

    List of targets.



486
487
488
489
490
# File 'lib/rubu.rb', line 486

def self.usezip( sources, targets )
    sources.zip( targets ).map do |pair|
        self.new( *pair ).use
    end
end

+ (Object) zip(sources, targets)

Combine list of sources and targets to source/target pairs.

Parameters:

  • sources

    List of sources.

  • targets

    List of targets.



475
476
477
478
479
# File 'lib/rubu.rb', line 475

def self.zip( sources, targets )
    sources.zip( targets ).map do |pair|
        self.new( *pair )
    end
end

Instance Method Details

- (Boolean) date_update?

Check for date (timestamp) based update needs.

Returns:

  • (Boolean)


543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/rubu.rb', line 543

def date_update?

    # Check if targets are missing.
    @targets.each do |target|
        unless target.exist?
            return true
        end
    end

    # Check if source(s) are newer than target(s).

    newest_source = Time.new( 0 )
    @sources.each do |source|
        if source.time > newest_source && !source.skip
            newest_source = source.time
        end
    end

    oldest_target = Time.now
    @targets.each do |target|
        if target.time < oldest_target
            oldest_target = target.time
        end
    end

    return newest_source > oldest_target
end

- (Object) fork(&blk)

Execute commands (from block) in parallel.



640
641
642
643
644
645
# File 'lib/rubu.rb', line 640

def fork( &blk )
    host_in
    instance_eval &blk
    host_out
    parallel_run
end

- (Boolean) mark_update?

Check for mark (checksum) based update needs.

Returns:

  • (Boolean)


573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/rubu.rb', line 573

def mark_update?

    unless date_update?
        return false
    end

    # Check if targets are missing.
    unless target.exist?
        return true
    end

    old_verbose = Order[ :verbose ]
    Order[ :verbose ] = false
    step
    Order[ :verbose ] = old_verbose

    unless target.exist?
        error "file generation failure"
        exit false
    end

    unless State.md5_check_and_update?( target.rpath )
        target.skip = true
        return false
    end

    true
end

- (Object) rbrun(desc = nil, &cmd)

Define and run Ruby command.

Parameters:

  • desc (defaults to: nil)

    Optional description for :verbose mode.



627
628
629
# File 'lib/rubu.rb', line 627

def rbrun( desc = nil, &cmd )
    RubyCommand.new( desc, &cmd ).run
end

- (Object) rbuse(desc = nil, &cmd)

Define and register Ruby command.

Parameters:

  • desc (defaults to: nil)

    Optional description for :verbose mode.



634
635
636
637
# File 'lib/rubu.rb', line 634

def rbuse( desc = nil, &cmd )
    rb = RubyCommand.new( desc, &cmd )
    rb.use
end

- (Object) run

Run Step and capture status.



526
527
528
529
530
531
532
533
# File 'lib/rubu.rb', line 526

def run
    if update?
        step
    else
        @status = :success
    end
    self
end

- (Object) setup

Setup variables for Step. Should be defined again in derived classes.



521
522
# File 'lib/rubu.rb', line 521

def setup
end

- (Object) shrun(cmd)

Define and run Shell command.



614
615
616
# File 'lib/rubu.rb', line 614

def shrun( cmd )
    ShellCommand.new( cmd ).run
end

- (Object) shuse(cmd)

Define and register Shell command.



619
620
621
622
# File 'lib/rubu.rb', line 619

def shuse( cmd )
    sh = ShellCommand.new( cmd )
    sh.use
end

- (Object) source

Main/only (first) source file.



604
605
606
# File 'lib/rubu.rb', line 604

def source
    @sources[0]
end

- (Object) target

Main/only (first) target file.



609
610
611
# File 'lib/rubu.rb', line 609

def target
    @targets[0]
end

- (Boolean) update?

Default update. Should be defined again in derived classes.

Returns:

  • (Boolean)


537
538
539
# File 'lib/rubu.rb', line 537

def update?
    true
end

- (Object) walk(&blk)

Execute commands (from block) in sequence.



648
649
650
651
652
653
# File 'lib/rubu.rb', line 648

def walk( &blk )
    host_in
    instance_eval &blk
    host_out
    serial_run
end