Sha256: a7d8a07b54b0ebecbe853ca310e2f08db2b33cf6d3b89f721b4fe4348337c9a7

Contents?: true

Size: 724 Bytes

Versions: 5

Compression:

Stored size: 724 Bytes

Contents

module ModelMacros
  # Create a new emotional model
  def followable(klass_name, &block)
    spawn_model klass_name, ActiveRecord::Base do
      acts_as_followable
      instance_exec(&block) if block
    end
  end

  # Create a new emotive model
  def follower(klass_name, &block)
    spawn_model klass_name, ActiveRecord::Base do
      acts_as_follower
      class_eval(&block) if block
    end
  end

  protected

  # Create a new model class
  def spawn_model(klass_name, parent_klass, &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

5 entries across 5 versions & 1 rubygems

Version Path
partisan-0.2.1 spec/support/macros/model_macros.rb
partisan-0.2 spec/support/macros/model_macros.rb
partisan-0.1.1 spec/support/macros/model_macros.rb
partisan-0.1 spec/support/macros/model_macros.rb
partisan-0.0.1 spec/support/macros/model_macros.rb