Sha256: f0853dad18200c5d5e599f41281844854932253ccddd15901caa99c0cf124a1e

Contents?: true

Size: 649 Bytes

Versions: 6

Compression:

Stored size: 649 Bytes

Contents

module ClassBuilder
  def self.included example_group
    example_group.class_eval do
      after do
        teardown_defined_constants
      end
    end
  end

  def define_class class_name, base = Object, &block
    Object.const_set class_name, Class.new(base)
    
    Object.const_get(class_name).tap do |constant_class|
      constant_class.unloadable

      if block_given?
        constant_class.class_eval(&block)
      end

      if constant_class.respond_to?(:reset_column_information)
        constant_class.reset_column_information
      end
    end
  end

  def teardown_defined_constants
    ActiveSupport::Dependencies.clear
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shoulda-callback-matchers-1.1.4 spec/support/class_builder.rb
shoulda-callback-matchers-1.1.3 spec/support/class_builder.rb
shoulda-callback-matchers-1.1.2 spec/support/class_builder.rb
shoulda-callback-matchers-1.1.1 spec/support/class_builder.rb
shoulda-callback-matchers-1.1.0 spec/support/class_builder.rb
shoulda-callback-matchers-1.0.0 spec/support/class_builder.rb