Class: Rumodule

Inherits:
RumoduleCommon show all
Includes:
Utility
Defined in:
bin/rumodule

Overview

Prefined Rumodule commands.

Direct Known Subclasses

CmdAdd, CmdDisplay, CmdHelp, CmdList, CmdRm, CmdSlist, CmdWhich

Constant Summary

@@outputlist =

List of output command lines to shell. Must be separeted with semicolon and newline.

[]
@@varcache =

Cache variables from env to Hash. All updated values are visible to subsequent commands.

{}

Constants included from Utility

Utility::LOADED, Utility::MODULEDIRS, Utility::RUMODULE_PUSH, Utility::SUBLOADED, Utility::SYSLOADED

Constants inherited from RumoduleCommon

RumoduleCommon::SHELL

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Utility

#abort, #all_loaded, #commonHelp, #error, #findModule, #help, #loadModule, #loaded, #registerModule, #sys_loaded, #unregisterModule, #usage, #warning

Methods included from RumoduleMod

#home

Class Method Details

+ (Object) flush

Flush all pending shell output.



729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'bin/rumodule', line 729

def Rumodule.flush

    # Check for changed env varibles and perform update.
    @@varcache.values.each do |v|
        if v.dirty
            @@outputlist.push v.export
        end
    end

    # Output updates.
    if @@outputlist.length > 0
        puts @@outputlist.join( ";\n" )
    end
end

+ (Object) run(cmd, mods)

Map rumodule cmd to internal class method.

Parameters:

  • cmd (String)

    Rumodule user command.

  • mods (Array)

    List of modules.



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'bin/rumodule', line 641

def Rumodule.run( cmd, mods )

    # Internal class name.
    cmdClass = "Cmd#{cmd.capitalize}"

    if Module.const_defined?( cmdClass )

        # Create instance of the class.
        obj = Object::const_get( cmdClass ).new

        # Execute rumodule method.
        obj.action( mods )

    else

        error "Unknown command: \"#{cmd}\"!"
    end
end

Instance Method Details

- (Boolean) _is_loaded(mod)

Is module(s) loaded?

Parameters:

  • mod (String)

    Module name.

Returns:

  • (Boolean)

    True if loaded.



707
708
709
710
711
712
713
714
715
716
717
# File 'bin/rumodule', line 707

def _is_loaded( mod )
    mod = [ mod ] if mod.class != Array

    mod.each do |i|
        if all_loaded.index( i )
            return true
        end
    end

    false
end

- (Object) _output(str)

Place str to output buffer (shell output).

Parameters:

  • str (String)

    String for output.



723
724
725
# File 'bin/rumodule', line 723

def _output( str )
    @@outputlist.push str
end

- (String) getenvar(var, create = false)

Fetch env varible from env. Conditionally create the env var.

Parameters:

  • var (String)

    Env var name.

  • create (Boolean) (defaults to: false)

    Create if not existing.

Returns:

  • (String)

    Env var value.



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'bin/rumodule', line 676

def getenvar( var, create = false )

    if @@varcache[ var ]
        # In cache.
        @@varcache[ var ]
    else

        # Not in cache.
        if ENV[ var ]

            # In env.
            v = EnvVar.new( var )
            @@varcache[ var ] = v

        elsif create

            # Create as new.
            v = EnvVar.new( var, [] )
            @@varcache[ var ] = v

        else
            nil
        end
    end
end