Sha256: 3a364b120281bd78393467da64a758cea1f12ba1e7c1c662cf052b42e84372a0

Contents?: true

Size: 599 Bytes

Versions: 9

Compression:

Stored size: 599 Bytes

Contents

module WithModel
  class ConstantStubber
    def initialize const_name
      @const_name = const_name.to_sym
      @original_value = nil
    end

    def stub_const value
      if Object.const_defined?(@const_name)
        @original_value = Object.const_get(@const_name)
        Object.send :remove_const, @const_name
      end

      Object.const_set @const_name, value
    end

    def unstub_const
      Object.send :remove_const, @const_name
      Object.const_set @const_name, @original_value if @original_value
      @original_value = nil
    end
  end
  private_constant :ConstantStubber
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
with_model-2.0.0 lib/with_model/constant_stubber.rb
with_model-1.2.2 lib/with_model/constant_stubber.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/with_model-1.2.1/lib/with_model/constant_stubber.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/with_model-1.2.1/lib/with_model/constant_stubber.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/with_model-1.2.1/lib/with_model/constant_stubber.rb
with_model-1.2.1 lib/with_model/constant_stubber.rb
with_model-1.2.0 lib/with_model/constant_stubber.rb
with_model-1.1.0 lib/with_model/constant_stubber.rb
with_model-1.0.0 lib/with_model/constant_stubber.rb