Sha256: d410ad495222426b2ecb60d6eb7ee8ffc67be1da7b5d271fa4d64b2b26284bf2

Contents?: true

Size: 608 Bytes

Versions: 45

Compression:

Stored size: 608 Bytes

Contents

require 'active_support/core_ext/string/inflections'

module DefineClass
  def define_class(name, parent_class=nil, &block)
    before(:each) do
      Thread.current[:"#{name}_scopes"] = nil
      Object.send(:remove_const, name) if Object.const_defined?(name)
      
      case parent_class
      when Class
        klass = Class.new(parent_class)
      when String, Symbol
        klass = Class.new(parent_class.to_s.constantize)
      when nil
        klass = Class.new
      end
      
      Object.const_set(name, klass)
    
      klass.class_eval(&block) if block_given?
      klass
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
mongomodel-0.5.0 spec/support/helpers/define_class.rb
mongomodel-0.4.9 spec/support/helpers/define_class.rb
mongomodel-0.4.8 spec/support/helpers/define_class.rb
mongomodel-0.4.7 spec/support/helpers/define_class.rb
mongomodel-0.4.6 spec/support/helpers/define_class.rb
mongomodel-0.4.5 spec/support/helpers/define_class.rb
mongomodel-0.4.4 spec/support/helpers/define_class.rb
mongomodel-0.4.3 spec/support/helpers/define_class.rb
mongomodel-0.4.2 spec/support/helpers/define_class.rb
mongomodel-0.4.1 spec/support/helpers/define_class.rb
mongomodel-0.4.0 spec/support/helpers/define_class.rb
mongomodel-0.3.6 spec/support/helpers/define_class.rb
mongomodel-0.3.5 spec/support/helpers/define_class.rb
mongomodel-0.3.4 spec/support/helpers/define_class.rb
mongomodel-0.3.3 spec/support/helpers/define_class.rb
mongomodel-0.3.2 spec/support/helpers/define_class.rb
mongomodel-0.3.1 spec/support/helpers/define_class.rb
mongomodel-0.3.0 spec/support/helpers/define_class.rb
mongomodel-0.2.20 spec/support/helpers/define_class.rb
mongomodel-0.2.19 spec/support/helpers/define_class.rb