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, #warn

Constructor Details

#initialize(sources = [], targets = []) ⇒ Step

Create Step object.

Parameters:

  • sources (defaults to: [])

    One or more sources.

  • targets (defaults to: [])

    One or more targets.



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/rubu.rb', line 522

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

#sourcesObject (readonly)

Returns the value of attribute sources



515
516
517
# File 'lib/rubu.rb', line 515

def sources
  @sources
end

#targetsObject (readonly)

Returns the value of attribute targets



516
517
518
# File 'lib/rubu.rb', line 516

def targets
  @targets
end

Class Method Details

.use(sources = [], targets = []) ⇒ Object

Create Move and register.

Parameters:

  • sources (defaults to: [])

    One or more sources.

  • targets (defaults to: [])

    One or more targets.



489
490
491
# File 'lib/rubu.rb', line 489

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

.usezip(sources, targets) ⇒ Object

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

Parameters:

  • sources

    List of sources.

  • targets

    List of targets.



508
509
510
511
512
# File 'lib/rubu.rb', line 508

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

.zip(sources, targets) ⇒ Object

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

Parameters:

  • sources

    List of sources.

  • targets

    List of targets.



497
498
499
500
501
# File 'lib/rubu.rb', line 497

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

Instance Method Details

#date_update?Boolean

Check for date (timestamp) based update needs.

Returns:

  • (Boolean)


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

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

#fork(&blk) ⇒ Object

Execute commands (from block) in parallel.



668
669
670
671
672
673
# File 'lib/rubu.rb', line 668

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

#mark_update?Boolean

Check for mark (checksum) based update needs.

Returns:

  • (Boolean)


600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/rubu.rb', line 600

def mark_update?

    unless date_update?
        target.skip = true
        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

#rbrun(desc = nil, &cmd) ⇒ Object

Define and run Ruby command.

Parameters:

  • desc (defaults to: nil)

    Optional description for :verbose mode.



655
656
657
# File 'lib/rubu.rb', line 655

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

#rbuse(desc = nil, &cmd) ⇒ Object

Define and register Ruby command.

Parameters:

  • desc (defaults to: nil)

    Optional description for :verbose mode.



662
663
664
665
# File 'lib/rubu.rb', line 662

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

#runObject

Run Step and capture status.



553
554
555
556
557
558
559
560
# File 'lib/rubu.rb', line 553

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

#setupObject

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



543
544
# File 'lib/rubu.rb', line 543

def setup
end

#shrun(cmd) ⇒ Object

Define and run Shell command.



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

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

#shuse(cmd) ⇒ Object

Define and register Shell command.



647
648
649
650
# File 'lib/rubu.rb', line 647

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

#sourceObject

Main/only (first) source file.



632
633
634
# File 'lib/rubu.rb', line 632

def source
    @sources[0]
end

#stepObject

Default to no action. Typically this method is redefined.



548
549
# File 'lib/rubu.rb', line 548

def step
end

#targetObject

Main/only (first) target file.



637
638
639
# File 'lib/rubu.rb', line 637

def target
    @targets[0]
end

#update?Boolean

Default update. Should be defined again in derived classes.

Returns:

  • (Boolean)


564
565
566
# File 'lib/rubu.rb', line 564

def update?
    true
end

#walk(&blk) ⇒ Object

Execute commands (from block) in sequence.



676
677
678
679
680
681
# File 'lib/rubu.rb', line 676

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