Sha256: a5e0df59c5a6001d825b771e2b3e04671309b53f9e7f5ce138a32722112cd286

Contents?: true

Size: 967 Bytes

Versions: 2

Compression:

Stored size: 967 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

  # Create a new emotive and emotionnal model
  def followable_and_follower(klass_name, &block)
    spawn_model klass_name, ActiveRecord::Base do
      acts_as_followable
      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

2 entries across 2 versions & 1 rubygems

Version Path
partisan-0.2.3 spec/support/macros/model_macros.rb
partisan-0.2.2 spec/support/macros/model_macros.rb