Sha256: f2ad8705b9c4e3b751c9e29373bec8113b7e6bb94c450ef6e75a640dea238c03

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

module ActiveMocker

  class LoadedMocks
    
    class << self

      def add(mocks_to_add)
        mocks.merge!({mocks_to_add.name => mocks_to_add})
      end

      def add_subclass(subclass)
        subclasses.merge!({subclass.mocked_class => subclass})
      end

      def subclasses
        @subclasses ||= {}
      end

      def clear_subclasses
        subclasses.clear
      end

      def mocks
        @mocks ||= {}
      end

      def find(klass)
        class_name_to_mock[klass]
      end

      def all
        mocks
      end

      def clear_all
        all_mocks.each { |m| m.clear_mock }
        clear_subclasses
      end

      def delete_all
        all_mocks.each { |m| m.delete_all }
      end

      def reload_all
        all_mocks.each { |m| m.send(:reload) }
      end

      def undefine_all
        all_mocks_as_str.each do |n|
          Object.send(:remove_const, n) if Object.const_defined?(n)
        end
      end

      def all_mocks_as_str
        mocks.keys + subclasses.keys
      end

      def class_name_to_mock
        hash = mocks.values.each_with_object({}) do |mock_constant, hash|
          hash[mock_constant.mocked_class] = mock_constant
        end
        hash.merge(subclasses)
      end

      private

      def internal_clear
        clear_subclasses
        mocks.clear
      end


      def all_mocks
        mocks.values + subclasses.values
      end
      
    end
   
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_mocker-1.5.2 lib/active_mocker/loaded_mocks.rb
active_mocker-1.5.1 lib/active_mocker/loaded_mocks.rb
active_mocker-1.5 lib/active_mocker/loaded_mocks.rb