Sha256: 7fe75b8c5bb0c5d667a79c1fa10c47e8a3aea0d71033b999a2975d359332a11d

Contents?: true

Size: 378 Bytes

Versions: 10

Compression:

Stored size: 378 Bytes

Contents

# frozen_string_literal: true

module ModelMacros
  # Create a new model class
  def spawn_model(klass_name, parent_klass = ActiveRecord::Base, &block)
    Object.instance_eval { remove_const klass_name } if Object.const_defined?(klass_name)
    Object.const_set(klass_name, Class.new(parent_klass))
    Object.const_get(klass_name).class_eval(&block) if block_given?
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activerecord_json_validator-3.0.0 spec/support/macros/model_macros.rb
activerecord_json_validator-2.1.5 spec/support/macros/model_macros.rb
activerecord_json_validator-2.1.4 spec/support/macros/model_macros.rb
activerecord_json_validator-2.1.3 spec/support/macros/model_macros.rb
activerecord_json_validator-2.1.2 spec/support/macros/model_macros.rb
activerecord_json_validator-2.1.1 spec/support/macros/model_macros.rb
activerecord_json_validator-2.1.0 spec/support/macros/model_macros.rb
activerecord_json_validator-2.0.1 spec/support/macros/model_macros.rb
activerecord_json_validator-2.0.0 spec/support/macros/model_macros.rb
activerecord_json_validator-1.3.0 spec/support/macros/model_macros.rb