scinote-web/app/models/concerns/variables_model.rb
2018-10-16 11:00:38 +02:00

24 lines
467 B
Ruby

# frozen_string_literal: true
module VariablesModel
extend ActiveSupport::Concern
@@default_variables = HashWithIndifferentAccess.new
included do
serialize :variables, JsonbHashSerializer
after_initialize :init_default_variables, if: :new_record?
end
class_methods do
def default_variables(dfs)
@@default_variables.merge!(dfs)
end
end
protected
def init_default_variables
self.variables = @@default_variables
end
end