Sha256: 6aae80ae8c6442518d0b5521eb60d7f957e3a487220ef67fc968a67ed84eee92

Contents?: true

Size: 823 Bytes

Versions: 2

Compression:

Stored size: 823 Bytes

Contents

require 'dcr/history'

module Dcr
  class InstanceMethodHistory < History
    def self.ivar
      :@_dcr_im
    end

    def klass
      @object
    end

    def commit method_name, &decorator
      unbound_org_method = klass.instance_method method_name

      new_method = lambda do |*args|
        bound_method = unbound_org_method.bind self
        decorator.call bound_method, *args
      end

      klass.class_eval do
        define_method method_name, &new_method
      end

      add_to_track unbound_org_method
    end

    def rollback method_name
      org_method = pop_last_track method_name
      klass.send :define_method, method_name, org_method
    end

    def rollback_all method_name
      org_method = pop_all_track method_name
      klass.send :define_method, method_name, org_method
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dcr-0.1.2 lib/dcr/instance_method_history.rb
dcr-0.1.0 lib/dcr/instance_method_history.rb