Sha256: 7c7bed5f844362c2eb619673a8e5b35d52ce74a86690bc082ef67af7b01aefa3

Contents?: true

Size: 619 Bytes

Versions: 2

Compression:

Stored size: 619 Bytes

Contents

require 'active_support/concern'

module Samsara::ContextConcern
  extend ActiveSupport::Concern

  # t.string  :event_type
  # t.text    :event_attributes
  # t.string  :environment_name
  # t.string  :application_name
  # t.timestamps

  included do
    has_many :revisions, class_name: Samsara.revision_class_name

    serialize :event_attributes, Samsara::Serializer
  end

  def event_class
    event_type.constantize
  end

  def event
    @event ||= event_class.new(event_attributes)
  end

  def event=(event)
    self.event_type       = event.class.name
    self.event_attributes = event.attributes
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
samsara-0.0.3 lib/samsara/context_concern.rb
samsara-0.0.2 lib/samsara/context_concern.rb