Sha256: 15560c79550b0edf3f10f1de2a90e35298294259ae3125e3f3b40362fe64ed36

Contents?: true

Size: 601 Bytes

Versions: 2

Compression:

Stored size: 601 Bytes

Contents

module ModelMacros
  # Create a new microscope model
  def strict_model(klass_name, options = {}, &block)
    spawn_model klass_name do
      validates_strict_columns options
      instance_exec(&block) if block
    end
  end

  protected

  # 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?
    Object.const_get(klass_name)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord_mysql_strict-0.2.1 spec/support/macros/model_macros.rb
activerecord_mysql_strict-0.2 spec/support/macros/model_macros.rb