Module: Asgard

Defined in:
lib/asgard.rb,
lib/asgard/base.rb,
lib/asgard/shell.rb,
lib/asgard/version.rb

Defined Under Namespace

Modules: Shell Classes: Base, CircularDependencyError, Error

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.find_task_fileObject

Search the current directory and its ancestors for a .loki task file. Returns the path string, or nil if not found.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/asgard.rb', line 14

def self.find_task_file
  dir = Dir.pwd
  loop do
    candidate = File.join(dir, ".loki")
    return candidate if File.exist?(candidate)
    parent = File.dirname(dir)
    break if parent == dir
    dir = parent
  end
  nil
end

.load_loki(dir) ⇒ Object

Load all *.loki files from dir in alphabetical order. Each file typically reopens class Tasks to add recipes. The .loki entry point is excluded — it is loaded separately by run!.



29
30
31
# File 'lib/asgard.rb', line 29

def self.load_loki(dir)
  Dir.glob(File.join(dir, "*.loki")).sort.each { |f| load f }
end

.run!(argv) ⇒ Object

Main entry point invoked by the asgard executable.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/asgard.rb', line 34

def self.run!(argv)
  task_file = find_task_file or (warn "asgard: no .loki file found in #{Dir.pwd}"; exit 1)
  load_loki(File.dirname(task_file))
  load task_file
  Tasks.validate_deps!
  Tasks._reset_ran!
  Tasks.start(argv)
rescue CircularDependencyError => e
  warn "asgard: circular dependency — #{e.message}"
  exit 1
end