Sha256: cecb15aa34803f91fa59cb841a218fbb46bd7905e570c59f4b0be90650e4fddc

Contents?: true

Size: 690 Bytes

Versions: 1

Compression:

Stored size: 690 Bytes

Contents

require 'activity_engine/exceptions'
module ActivityEngine
  class Activity < ActiveRecord::Base
    def self.call(data)
      create! do |activity|
        activity.subject = data.subject
        activity.user = data.current_user
        activity.message = data.message
        activity.activity_type = data.activity_type
      end
    end

    belongs_to :user

    def subject
      subject_type.constantize.find(subject_id)
    end

    def subject=(object)
      if object.persisted?
        write_attribute(:subject_type, object.class.to_s)
        write_attribute(:subject_id, object.to_param)
      else
        raise UnpersistedSubjectError.new(object)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activity_engine-0.0.2 app/models/activity_engine/activity.rb