Class: Babushka::Base

Inherits:
Object show all
Defined in:
lib/babushka/base.rb

Constant Summary collapse

@@start_time =

The time at which babushka was loaded. This is used in LogHelpers to print profiling information via the ‘–profile’ commandline option.

Time.now

Class Method Summary collapse

Class Method Details

.cmdlineObject

cmdline is an instance of Cmdline::Parser that represents the arguments that were passed via the commandline. It handles parsing those arguments, and choosing the task to perform based on the ‘verb’ supplied - e.g. ‘meet’, ‘list’, etc.



41
42
43
# File 'lib/babushka/base.rb', line 41

def cmdline
  @cmdline ||= Cmdline::Parser.for(ARGV)
end

.exit_on_interrupt!Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/babushka/base.rb', line 78

def exit_on_interrupt!
  if $stdin.tty?
    stty_save = `stty -g`.chomp
    trap("INT") {
      system "stty", stty_save
      unless Base.task.callstack.empty?
        puts "\n#{Logging.closing_log_message("#{Base.task.callstack.first.contextual_name} (cancelled)", false, :closing_status => true)}"
      end
      exit false
    }
  end
end

.hostObject



45
46
47
# File 'lib/babushka/base.rb', line 45

def host
  Babushka::LogHelpers.removed! :method_name => 'Babushka::Base.host', :instead => "Babushka.host"
end

.in_thread(&block) ⇒ Object



65
66
67
# File 'lib/babushka/base.rb', line 65

def in_thread &block
  threads.push Thread.new(&block)
end

.program_nameObject



102
103
104
# File 'lib/babushka/base.rb', line 102

def program_name
  @program_name ||= ENV['PATH'].split(':').include?(File.dirname($0)) ? File.basename($0) : $0
end

.refObject



95
96
97
98
99
100
# File 'lib/babushka/base.rb', line 95

def ref
  @ref ||= begin
    repo = GitRepo.new(Path.path)
    repo.current_head if repo.exists?
  end
end

.runObject

The top-level entry point for babushka runs invoked at the command line. When the ‘babushka` command is run, bin/babushka.rb first triggers a load via lib/babushka.rb, and then calls this method.



72
73
74
75
76
# File 'lib/babushka/base.rb', line 72

def run
  cmdline.run
ensure
  threads.each(&:join)
end

.runtime_infoObject



91
92
93
# File 'lib/babushka/base.rb', line 91

def runtime_info
  @runtime_info ||= "babushka@#{ref} | #{ShellHelpers.which('ruby')}@#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
end

.sourcesObject

sources is an instance of Babushka::SourcePool, contains all the sources that babushka can currently load deps from. This means all the sources found in ~/.babushka/sources, plus the default sources:

- anonymous (no source file; i.e. deps defined in an +irb+ session,
  or similar)
- core (the builtin deps that babushka uses to install itself)
- current dir (the contents of ./babushka-deps)
- personal (the contents of ~/.babushka/deps)


57
58
59
# File 'lib/babushka/base.rb', line 57

def sources
  SourcePool.instance
end

.start_timeObject



26
27
28
# File 'lib/babushka/base.rb', line 26

def start_time
  @@start_time
end

.taskObject

task represents the overall job that is being run, and the parts that are external to running the corresponding dep tree itself - logging, and var loading and saving in particular.



33
34
35
# File 'lib/babushka/base.rb', line 33

def task
  Task.instance
end

.threadsObject



61
62
63
# File 'lib/babushka/base.rb', line 61

def threads
  @threads ||= []
end