Sha256: f47fc80d7a59ac95316bcac90a3e0948c41c2969323c5ad5621eeb036a632a43

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

class CounterAdapter < DataMapper::Adapters::AbstractAdapter
  instance_methods.each do |method|
    next if method =~ /\A__/ ||
      %w[ send class dup object_id kind_of? instance_of? respond_to? equal? freeze frozen? should should_not instance_variables instance_variable_set instance_variable_get instance_variable_defined? remove_instance_variable extend inspect copy_object ].include?(method.to_s)
    undef_method method
  end

  attr_reader :counts

  def kind_of?(klass)
    super || @adapter.kind_of?(klass)
  end

  def instance_of?(klass)
    super || @adapter.instance_of?(klass)
  end

  def respond_to?(method, include_private = false)
    super || @adapter.respond_to?(method, include_private)
  end

  private

  def initialize(adapter)
    @counts  = Hash.new { |hash, key| hash[key] = 0 }
    @adapter = adapter
    @count   = 0
  end

  def increment_count_for(method)
    @counts[method] += 1
  end

  def method_missing(method, *args, &block)
    increment_count_for(method)
    @adapter.send(method, *args, &block)
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
sbf-dm-core-1.4.0 lib/dm-core/spec/lib/counter_adapter.rb
sbf-dm-core-1.3.0 lib/dm-core/spec/lib/counter_adapter.rb
sbf-dm-core-1.3.0.beta lib/dm-core/spec/lib/counter_adapter.rb
ardm-core-1.3.0 lib/dm-core/spec/lib/counter_adapter.rb
ardm-core-1.2.1 lib/dm-core/spec/lib/counter_adapter.rb
dm-core-1.2.1 lib/dm-core/spec/lib/counter_adapter.rb
ghost_dm-core-1.3.0.beta lib/dm-core/spec/lib/counter_adapter.rb
dm-core-1.2.0 lib/dm-core/spec/lib/counter_adapter.rb
dm-core-1.2.0.rc2 lib/dm-core/spec/lib/counter_adapter.rb
dm-core-1.2.0.rc1 lib/dm-core/spec/lib/counter_adapter.rb
dm-core-1.1.0 lib/dm-core/spec/lib/counter_adapter.rb
dm-core-1.1.0.rc3 lib/dm-core/spec/lib/counter_adapter.rb