scinote-web/app/models/concerns/activity_values_model.rb
aignatov-bio b1f9e7f1ca Fix global activities jsonb field [SCI-3830] (#2030)
* Fix global activities jsonb field

* Fix tests
2019-11-18 13:59:54 +01:00

33 lines
736 B
Ruby

# frozen_string_literal: true
module ActivityValuesModel
extend ActiveSupport::Concern
# rubocop:disable Style/ClassVars
@@default_values = HashWithIndifferentAccess.new
# rubocop:enable Style/ClassVars
included do
after_initialize :init_default_values, if: :new_record?
before_create :add_user
end
class_methods do
def default_values(dfs)
@@default_values.merge!(dfs)
end
end
protected
def init_default_values
self.values = @@default_values
end
def add_user
message_items.merge!(user: { id: owner.id,
value: owner.full_name,
type: 'User',
value_for: 'full_name' })
end
end