target_loader.rb 988 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. module TargetLoader
  2. class NoTargets < Exception; end
  3. class NoDirectory < Exception; end
  4. class NoDefault < Exception; end
  5. class NoSuchTarget < Exception; end
  6. class RequestReload < Exception; end
  7. def self.inspect(config, target_name=nil)
  8. unless config[:targets]
  9. raise NoTargets
  10. end
  11. targets = config[:targets]
  12. unless targets[:targets_directory]
  13. raise NoDirectory("No targets directory specified.")
  14. end
  15. unless targets[:default_target]
  16. raise NoDefault("No default target specified.")
  17. end
  18. target_path = lambda {|name| File.join(targets[:targets_directory], name + ".yml")}
  19. target = if target_name
  20. target_path.call(target_name)
  21. else
  22. target_path.call(targets[:default_target])
  23. end
  24. unless File.exists? target
  25. raise NoSuchTarget.new("No such target: #{target}")
  26. end
  27. ENV['CEEDLING_MAIN_PROJECT_FILE'] = target
  28. raise RequestReload
  29. end
  30. end