Sha256: ede5d211ccaa87971c348fb6e16a0a4e78ef0f981211b7a948e17203caf6168a

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module TargetLoader
  class NoTargets    < Exception; end
  class NoDirectory  < Exception; end
  class NoDefault    < Exception; end
  class NoSuchTarget < Exception; end

  class RequestReload < Exception; end

  def self.inspect(config, target_name=nil)
    unless config[:targets]
      raise NoTargets
    end

    targets = config[:targets]
    unless targets[:targets_directory]
      raise NoDirectory.new("No targets directory specified.")
    end
    unless targets[:default_target]
      raise NoDefault.new("No default target specified.")
    end

    target_path = lambda {|name| File.join(targets[:targets_directory], name + ".yml")}

    target = if target_name
               target_path.call(target_name)
             else
               target_path.call(targets[:default_target])
             end

    unless File.exists? target
      raise NoSuchTarget.new("No such target: #{target}")
    end

    ENV['CEEDLING_MAIN_PROJECT_FILE'] = target

    raise RequestReload
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ceedling-0.29.1 lib/ceedling/target_loader.rb
ceedling-0.29.0 lib/ceedling/target_loader.rb