Class: Rubu::Trail

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

Overview

Trail with name. Trail is a collection of Steps and/or Trails.

Direct Known Subclasses

Fork, Walk

Constant Summary collapse

@@trails =

Trail hash.

{}

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(name = nil, &blk) ⇒ Trail

Create Trail object. Named Trails are registered and can be referenced later.



761
762
763
764
765
766
767
768
769
770
# File 'lib/rubu.rb', line 761

def initialize( name = nil, &blk )
    super()
    @name = name
    host_in
    instance_eval &blk
    host_out
    if @name
        @@trails[ @name ] = self
    end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



757
758
759
# File 'lib/rubu.rb', line 757

def name
  @name
end

Class Method Details

.[](name) ⇒ Object

Reference Trail by name.



747
748
749
# File 'lib/rubu.rb', line 747

def self.[]( name )
    @@trails[ name ]
end

.form(name = nil, &blk) ⇒ Object

Replacement (alias) for new method.



741
742
743
# File 'lib/rubu.rb', line 741

def self.form( name = nil, &blk )
    self.new( name, &blk )
end

.listObject

Return list of trails.



752
753
754
# File 'lib/rubu.rb', line 752

def self.list
    @@trails.keys
end

.load_setup(setup_file) ⇒ Object

Load a setup file.



785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
# File 'lib/rubu.rb', line 785

def Trail.load_setup( setup_file )

    if File.exist? setup_file

        conf = YAML.load_file( setup_file )

        conf.each do |k,v|

            scope = nil

            case k
            when :var; scope = Var
            when :order; scope = Order
            when :info; scope = Info
            end

            v.each do |k2,v2|
                scope[ k2 ] = v2
            end
        end
    end
end

.run(trails = 'default') ⇒ Object

Run selected trail(s).

Parameters:

  • trails (defaults to: 'default')

    List of Trails to run.



842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
# File 'lib/rubu.rb', line 842

def Trail.run( trails = 'default' )

    unless trails.kind_of? Array
        trails = [ trails ]
    end

    trails.each do |name|

        begin

            ret = Trail[ name ].run
            if ret.status == :error
                STDERR.puts "Rubu FAILURE..."
                exit false
            end

        rescue

            STDERR.puts "Broken trail: \"#{name}\"..."
            exit false

        end

    end

    State.save

    exit true
end

.setup(spec) ⇒ Object

Apply configuration options and command parameters, if any, to Rubu.

Parameters:

  • spec

    Hash of options for setup.



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/rubu.rb', line 813

def Trail.setup( spec )

    Trail.load_setup( "#{ENV['HOME']}/.rubu.yml" )
    Trail.load_setup( ENV['RUBU_CONF'] ) if ENV['RUBU_CONF']
    Trail.load_setup( ".rubu.yml" )

    State.load

    # Apply options from Como.
    if spec[ :como ]
        como = spec[ :como ]
        if Opt[ como ].given
            Opt[ como ].value.each do |conf|
                name, value = conf.split( '=' )
                value = case value
                        when 'true'; true
                        when 'false'; false
                        else value
                        end
                Var[ name.to_sym ] = value
            end
        end
    end

end

Instance Method Details

#pick(trail) ⇒ Object

Take trail into use.



774
775
776
# File 'lib/rubu.rb', line 774

def pick( trail )
    Trail[ trail ].use
end

#runObject

Default run style for Trail.



780
781
782
# File 'lib/rubu.rb', line 780

def run
    serial_run
end