Sha256: e7bfe98111f06646bd7ad1ae2b0d6456d4262b90b1d5c02636f2df4d63d0c6c2

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module Ros
  class Dsl
    attr_reader :package
    
    def initialize package
      @package = package
    end
    
    def applied? &b        
      package.applied = b
    end
  
    def apply &b
      package.apply = b
    end
  end
  
  class Package
    attr_accessor :applied, :apply, :name
    
    def initialize name
      @name = name
    end
    
    def configure_with &b
      dsl = Dsl.new self
      dsl.instance_eval &b
    end
    
    def apply_to box
      unless applied and applied.call(box)
        print "applying '#{name}' to '#{box.options[:host]}'\n"
        apply.call box
        print "done\n"
      end
    end
  end
  
  class << self
    def each_box_cached &b
      unless @each_box_cached
        unless Object.private_instance_methods(false).include?(:each_box)
          raise "you must define 'each_box' method!"
        end
        
        @each_box_cached = []
        each_box do |box| 
          @each_box_cached << box
          
          # cache ssh connection
          box.open_connection
        end
      end
      @each_box_cached.each &b
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rsh2-0.0.4 lib/ros/ros.rb
rsh2-0.0.3 lib/ros/ros.rb