Sha256: 51f8adb974a16aed4124675b4050235419693fca74cabc7d075a9d4890dfbaf9

Contents?: true

Size: 1.09 KB

Versions: 65

Compression:

Stored size: 1.09 KB

Contents

require 'dependency_detection/version'
module DependencyDetection

  module_function
  @@items = []
  def defer(&block)
    item = Dependent.new
    item.instance_eval(&block)
    @@items << item
  end

  def detect!
    @@items.each do |item|
      if item.dependencies_satisfied?
        item.execute
      end
    end
  end

  def dependency_by_name(name)
    @@items.find {|i| i.name == name }
  end

  def installed?(name)
    item = dependency_by_name(name)
    item && item.executed
  end

  class Dependent
    attr_reader :executed
    attr_reader :name
    def executed!
      @executed = true
    end

    attr_reader :dependencies

    def initialize
      @dependencies = []
      @executes = []
    end

    def dependencies_satisfied?
      !executed and check_dependencies
    end

    def execute
      @executes.each do |x|
        x.call
      end
    ensure
      executed!
    end

    def check_dependencies
      dependencies && dependencies.all? { |d| d.call }
    end

    def depends_on
      @dependencies << Proc.new
    end

    def executes
      @executes << Proc.new
    end
  end
end

Version data entries

65 entries across 65 versions & 5 rubygems

Version Path
wd_newrelic_rpm-3.5.8 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
sundawg_newrelic_rpm-3.5.8.2 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
sundawg_newrelic_rpm-3.5.8.1 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.8.72 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.8.70 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.8.64.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.7.59 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.7.59.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.7.58.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
wd_newrelic_rpm-3.5.6 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.7.57.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.6.55 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.6.48.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.6.46.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.6.42.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.5.39.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
wd_newrelic_rpm-3.5.5 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.5.38 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.5.540.dev vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.5.4.35.beta vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb