lib/kitchen/driver/base.rb in test-kitchen-1.0.0.beta.4 vs lib/kitchen/driver/base.rb in test-kitchen-1.0.0.rc.1

- old
+ new

@@ -16,10 +16,12 @@ # See the License for the specific language governing permissions and # limitations under the License. require 'thor/util' +require 'kitchen/lazy_hash' + module Kitchen module Driver # Base class for a driver. @@ -35,11 +37,11 @@ class << self attr_reader :serial_actions end def initialize(config = {}) - @config = LazyDriverHash.new(config, self) + @config = LazyHash.new(config, self) self.class.defaults.each do |attr, value| @config[attr] = value unless @config.has_key?(attr) end end @@ -160,12 +162,11 @@ end def busser @busser ||= begin raise ClientError, "Instance must be set for Driver" if instance.nil? - - Busser.new(instance.suite.name, config) + instance.busser end end def self.defaults @defaults ||= Hash.new.merge(super_defaults) @@ -210,37 +211,9 @@ end end @serial_actions ||= [] @serial_actions += methods - end - - # A modifed Hash object that may contain procs as a value which must be - # executed in the context of a Driver object. - # - # @author Fletcher Nichol <fnichol@nichol.ca> - class LazyDriverHash < SimpleDelegator - - def initialize(obj, driver) - @driver = driver - super(obj) - end - - def [](key) - proc_or_val = __getobj__[key] - - if proc_or_val.respond_to?(:call) - proc_or_val.call(@driver) - else - proc_or_val - end - end - - def to_hash - hash = Hash.new - __getobj__.keys.each { |key| hash[key] = self[key] } - hash - end end end end end