scinote-web/app/models/concerns/variables_model.rb

25 lines
467 B
Ruby
Raw Normal View History

2018-10-12 06:56:48 +08:00
# frozen_string_literal: true
2018-10-12 06:48:12 +08:00
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