Class: Rubu::Step
- Inherits:
-
Move
- Object
- Move
- Rubu::Step
- 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
Instance Attribute Summary (collapse)
-
- (Object) sources
readonly
Returns the value of attribute sources.
-
- (Object) targets
readonly
Returns the value of attribute targets.
Attributes inherited from Move
#errmsg, #output, #status, #subs
Class Method Summary (collapse)
-
+ (Object) use(sources = [], targets = [])
Create Move and register.
-
+ (Object) usezip(sources, targets)
Combine list of sources and targets to source/target pairs and register.
-
+ (Object) zip(sources, targets)
Combine list of sources and targets to source/target pairs.
Instance Method Summary (collapse)
-
- (Boolean) date_update?
Check for date (timestamp) based update needs.
-
- (Object) fork(&blk)
Execute commands (from block) in parallel.
-
- (Step) initialize(sources = [], targets = [])
constructor
Create Step object.
-
- (Boolean) mark_update?
Check for mark (checksum) based update needs.
-
- (Object) rbrun(desc = nil, &cmd)
Define and run Ruby command.
-
- (Object) rbuse(desc = nil, &cmd)
Define and register Ruby command.
-
- (Object) run
Run Step and capture status.
-
- (Object) setup
Setup variables for Step.
-
- (Object) shrun(cmd)
Define and run Shell command.
-
- (Object) shuse(cmd)
Define and register Shell command.
-
- (Object) source
Main/only (first) source file.
-
- (Object) step
Default to no action.
-
- (Object) target
Main/only (first) target file.
-
- (Boolean) update?
Default update.
-
- (Object) walk(&blk)
Execute commands (from block) in sequence.
Methods included from MoveStyles
Methods inherited from Move
#display, #error, #host, #host_in, #host_out, #set_show_shell_warning, #use, #warn
Constructor Details
- (Step) initialize(sources = [], targets = [])
Create Step object.
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/rubu.rb', line 518 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
511 512 513 |
# File 'lib/rubu.rb', line 511 def sources @sources end |
- (Object) targets (readonly)
Returns the value of attribute targets
512 513 514 |
# File 'lib/rubu.rb', line 512 def targets @targets end |
Class Method Details
+ (Object) use(sources = [], targets = [])
Create Move and register.
485 486 487 |
# File 'lib/rubu.rb', line 485 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.
504 505 506 507 508 |
# File 'lib/rubu.rb', line 504 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.
493 494 495 496 497 |
# File 'lib/rubu.rb', line 493 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.
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/rubu.rb', line 566 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.
664 665 666 667 668 669 |
# File 'lib/rubu.rb', line 664 def fork( &blk ) host_in instance_eval &blk host_out parallel_run end |
- (Boolean) mark_update?
Check for mark (checksum) based update needs.
596 597 598 599 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 |
# File 'lib/rubu.rb', line 596 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 |
- (Object) rbrun(desc = nil, &cmd)
Define and run Ruby command.
651 652 653 |
# File 'lib/rubu.rb', line 651 def rbrun( desc = nil, &cmd ) RubyCommand.new( desc, &cmd ).run end |
- (Object) rbuse(desc = nil, &cmd)
Define and register Ruby command.
658 659 660 661 |
# File 'lib/rubu.rb', line 658 def rbuse( desc = nil, &cmd ) rb = RubyCommand.new( desc, &cmd ) rb.use end |
- (Object) run
Run Step and capture status.
549 550 551 552 553 554 555 556 |
# File 'lib/rubu.rb', line 549 def run if update? step else @status = :success end self end |
- (Object) setup
Setup variables for Step. Should be defined again in derived classes.
539 540 |
# File 'lib/rubu.rb', line 539 def setup end |
- (Object) shrun(cmd)
Define and run Shell command.
638 639 640 |
# File 'lib/rubu.rb', line 638 def shrun( cmd ) ShellCommand.new( cmd ).run end |
- (Object) shuse(cmd)
Define and register Shell command.
643 644 645 646 |
# File 'lib/rubu.rb', line 643 def shuse( cmd ) sh = ShellCommand.new( cmd ) sh.use end |
- (Object) source
Main/only (first) source file.
628 629 630 |
# File 'lib/rubu.rb', line 628 def source @sources[0] end |
- (Object) step
Default to no action. Typically this method is redefined.
544 545 |
# File 'lib/rubu.rb', line 544 def step end |
- (Object) target
Main/only (first) target file.
633 634 635 |
# File 'lib/rubu.rb', line 633 def target @targets[0] end |
- (Boolean) update?
Default update. Should be defined again in derived classes.
560 561 562 |
# File 'lib/rubu.rb', line 560 def update? true end |
- (Object) walk(&blk)
Execute commands (from block) in sequence.
672 673 674 675 676 677 |
# File 'lib/rubu.rb', line 672 def walk( &blk ) host_in instance_eval &blk host_out serial_run end |