Class: Rubu::Step
Overview
Step in Trail. Step takes one or more sources, and turns them into one or more targets.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Attributes inherited from Move
#errmsg, #output, #status, #subs
Class Method Summary collapse
-
.use(sources = [], targets = []) ⇒ Object
Create Move and register.
-
.useset(sources) ⇒ Object
Create Move's for all in sources and register.
-
.usezip(sources, targets) ⇒ Object
Combine list of sources and targets to source/target pairs and register.
-
.zip(sources, targets) ⇒ Object
Combine list of sources and targets to source/target pairs.
Instance Method Summary collapse
-
#date_update? ⇒ Boolean
Check for date (timestamp) based update needs.
-
#fork(&blk) ⇒ Object
Execute commands (from block) in parallel.
-
#initialize(sources = [], targets = []) ⇒ Step
constructor
Create Step object.
-
#mark_update? ⇒ Boolean
Check for mark (checksum) based update needs.
-
#rbrun(desc = nil, &cmd) ⇒ Object
Define and run Ruby command.
-
#rbuse(desc = nil, &cmd) ⇒ Object
Define and register Ruby command.
-
#run ⇒ Object
Run Step and capture status.
-
#setup ⇒ Object
Setup variables for Step.
-
#shrun(cmd) ⇒ Object
Define and run Shell command.
-
#shuse(cmd) ⇒ Object
Define and register Shell command.
-
#source ⇒ Object
Main/only (first) source file.
-
#step ⇒ Object
Default to no action.
-
#target ⇒ Object
Main/only (first) target file.
-
#update? ⇒ Boolean
Default update.
-
#walk(&blk) ⇒ Object
Execute commands (from block) in sequence.
Methods included from MoveStyles
Methods inherited from Move
#display, #error, #host, #host_in, #host_out, #use, #warn
Constructor Details
#initialize(sources = [], targets = []) ⇒ Step
Create Step object.
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/rubu.rb', line 540 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
#sources ⇒ Object (readonly)
Returns the value of attribute sources
533 534 535 |
# File 'lib/rubu.rb', line 533 def sources @sources end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets
534 535 536 |
# File 'lib/rubu.rb', line 534 def targets @targets end |
Class Method Details
.use(sources = [], targets = []) ⇒ Object
Create Move and register.
495 496 497 |
# File 'lib/rubu.rb', line 495 def self.use( sources = [], targets = [] ) self.new( sources, targets ).use end |
.useset(sources) ⇒ Object
Create Move's for all in sources and register.
This creates Moves without targets, i.e. it is suitable for example for cleanups.
526 527 528 529 530 |
# File 'lib/rubu.rb', line 526 def self.useset( sources ) sources.map do |source| self.new( source ).use end end |
.usezip(sources, targets) ⇒ Object
Combine list of sources and targets to source/target pairs and register.
514 515 516 517 518 |
# File 'lib/rubu.rb', line 514 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.
503 504 505 506 507 |
# File 'lib/rubu.rb', line 503 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.
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/rubu.rb', line 588 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.
686 687 688 689 690 691 |
# File 'lib/rubu.rb', line 686 def fork( &blk ) host_in instance_eval &blk host_out parallel_run end |
#mark_update? ⇒ Boolean
Check for mark (checksum) based update needs.
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/rubu.rb', line 618 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.
673 674 675 |
# File 'lib/rubu.rb', line 673 def rbrun( desc = nil, &cmd ) RubyCommand.new( desc, &cmd ).run end |
#rbuse(desc = nil, &cmd) ⇒ Object
Define and register Ruby command.
680 681 682 683 |
# File 'lib/rubu.rb', line 680 def rbuse( desc = nil, &cmd ) rb = RubyCommand.new( desc, &cmd ) rb.use end |
#run ⇒ Object
Run Step and capture status.
571 572 573 574 575 576 577 578 |
# File 'lib/rubu.rb', line 571 def run if update? step else @status = :success end self end |
#setup ⇒ Object
Setup variables for Step. Should be defined again in derived classes.
561 562 |
# File 'lib/rubu.rb', line 561 def setup end |
#shrun(cmd) ⇒ Object
Define and run Shell command.
660 661 662 |
# File 'lib/rubu.rb', line 660 def shrun( cmd ) ShellCommand.new( cmd ).run end |
#shuse(cmd) ⇒ Object
Define and register Shell command.
665 666 667 668 |
# File 'lib/rubu.rb', line 665 def shuse( cmd ) sh = ShellCommand.new( cmd ) sh.use end |
#source ⇒ Object
Main/only (first) source file.
650 651 652 |
# File 'lib/rubu.rb', line 650 def source @sources[0] end |
#step ⇒ Object
Default to no action. Typically this method is redefined.
566 567 |
# File 'lib/rubu.rb', line 566 def step end |
#target ⇒ Object
Main/only (first) target file.
655 656 657 |
# File 'lib/rubu.rb', line 655 def target @targets[0] end |
#update? ⇒ Boolean
Default update. Should be defined again in derived classes.
582 583 584 |
# File 'lib/rubu.rb', line 582 def update? true end |
#walk(&blk) ⇒ Object
Execute commands (from block) in sequence.
694 695 696 697 698 699 |
# File 'lib/rubu.rb', line 694 def walk( &blk ) host_in instance_eval &blk host_out serial_run end |