Module: Voynich::ActiveModel::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/voynich/active_model/model.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VOYNICH_DEFAULT_OPTIONS =
{
  column_prefix: 'voynich_',
  column_suffix: '_value',
  context: nil
}

Instance Method Summary collapse

Instance Method Details

#voynich_context(name) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/voynich/active_model/model.rb', line 14

def voynich_context(name)
  context_proc = voynich_targets[name.to_sym][:context]
  if context_proc
    context_proc.call(self)
  else
    {}
  end
end

#voynich_store_attributesObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/voynich/active_model/model.rb', line 23

def voynich_store_attributes
  voynich_targets.each do |name, options|
    iv = instance_variable_get(:"@#{name}")
    next if iv.nil?

    column_name = voynich_column_name(name)
    value = send(column_name) || send("build_#{column_name}")
    value.context = voynich_context(name)
    value.plain_value = iv
    value.save!
  end
end