Sha256: 29eee9bc1783d53083a854b26e98bbd75497a192c883d522ec3cd93a04df1bd3

Contents?: true

Size: 1017 Bytes

Versions: 6

Compression:

Stored size: 1017 Bytes

Contents

module Tap
  module Support
    
    # Constrains an Executable to only _execute once, and provides several
    # methods making the Executable behave like a Dependency.
    module Dependency
      
      # The audited result of self
      attr_accessor :_result
      
      def self.extended(base) # :nodoc:
        base.instance_variable_set(:@_result, nil)
      end
      
      # Conditional _execute; only calls method_name if
      # resolved? is false (thus assuring self will only
      # be executed once).
      #
      # Returns _result.
      def _execute(*args)
        app.dependencies.resolve(self) do
          @_result = super
        end unless resolved?
        _result
      end
      
      # Alias for _execute().
      def resolve
        _execute
      end
      
      # True if _result is non-nil.
      def resolved?
        @_result != nil
      end
      
      # Resets the dependency by setting _result to nil.
      def reset
        @_result = nil
      end
      
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
bahuvrihi-tap-0.12.0 lib/tap/support/dependency.rb
tap-0.12.4 lib/tap/support/dependency.rb
tap-0.12.2 lib/tap/support/dependency.rb
tap-0.12.3 lib/tap/support/dependency.rb
tap-0.12.1 lib/tap/support/dependency.rb
tap-0.12.0 lib/tap/support/dependency.rb