Sha256: 5f8f9bf0d38433a3f94635f711c8b1969a1366ad146c7808387e5b2400a845ce

Contents?: true

Size: 551 Bytes

Versions: 2

Compression:

Stored size: 551 Bytes

Contents

require_relative 'serializers/indifferent_json'

module Sojourn
  class Event < ActiveRecord::Base
    DEFAULT_FIELDS = %i(id sojourner_uuid name properties user_id created_at)

    belongs_to :user

    serialize :properties, Serializers::IndifferentJSON

    before_save do
      properties.keys.map(&:to_sym).each do |key|
        send("#{key}=", properties[key]) if self.class.available_fields.include?(key)
      end
    end

    def self.available_fields
      @available_fields ||= column_names.map(&:to_sym) - DEFAULT_FIELDS
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sojourn-0.1.1 lib/sojourn/event.rb
sojourn-0.1.0 lib/sojourn/event.rb