Sha256: 95990dc66fb698f05507d1c805ff305a1adc68a37b08ca2a21d0ef07cb342597

Contents?: true

Size: 1 KB

Versions: 15

Compression:

Stored size: 1 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

  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

15 entries across 15 versions & 2 rubygems

Version Path
dolores_rpm-3.2.0.6 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
dolores_rpm-3.2.0.5 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
dolores_rpm-3.2.0.4 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
dolores_rpm-3.2.0.3 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
dolores_rpm-3.2.0.2 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.3.2.beta1 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.3.1 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.3.1.beta2 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.3.1.beta1 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.3.0 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.3.0.beta1 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.2.0.1 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.2.0 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.2.0.beta2 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
newrelic_rpm-3.2.0.beta1 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb