52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/voynich/active_model/model.rb', line 52
def voynich_attribute(name, options = {})
options = VOYNICH_DEFAULT_OPTIONS.merge(options)
voynich_targets[name.to_sym] = options
asoc_options = options.
merge(class_name: "::Voynich::ActiveRecord::Value").
reject{|k| VOYNICH_DEFAULT_OPTIONS.keys.include? k}
belongs_to :"#{voynich_column_name(name)}", asoc_options
private :"#{voynich_column_name(name)}="
define_method(name) do
value = send(voynich_column_name(name))
iv = instance_variable_get(:"@#{name}")
return iv unless iv.nil?
return nil if value.nil?
value.context = voynich_context(name)
instance_variable_set(:"@#{name}", value.decrypt)
end
define_method("#{name}=") do |val|
instance_variable_set(:"@#{name}", val)
end
define_method("#{name}?") do
value = send(name)
value.respond_to?(:empty?) ? !value.empty? : !!value
end
end
|