Sha256: b2a439aeb1dd0d2375839435517c7bfacc548560e920b1de61182295eced4391

Contents?: true

Size: 903 Bytes

Versions: 1

Compression:

Stored size: 903 Bytes

Contents

module YSI
  class Assertion
    attr_reader :error
    attr_accessor :engine

    def self.class_for_name(name)
      class_name = name.split("_").map { |n| n.capitalize }.join
      begin
        Object.const_get("YSI::" + class_name)
      rescue NameError
        raise YSI::Error.new("Error: Unknown assertion '#{name}'")
      end
    end

    def self.needs(dependency)
      @dependency_names ||= []
      # Classes might not all be loaded yet, so delay class name lookup to
      # first invocation of #needs
      @dependency_names << dependency
    end

    def self.dependency_names
      @dependency_names || []
    end

    def initialize(engine)
      @engine = engine
    end

    def needs
      @dependencies ||= self.class.dependency_names.map do |d|
        Assertion.class_for_name(d)
      end
    end

    def needs?(dependency)
      needs.include?(dependency)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yes_ship_it-0.0.2 lib/yes_ship_it/assertion.rb