Sha256: 95ee757702a16d67234ca47604e87f1c6d4e976bdaca216d93894b4ef1644b10
Contents?: true
Size: 952 Bytes
Versions: 65
Compression:
Stored size: 952 Bytes
Contents
module Udongo class Form include ActiveModel::Model include Virtus.model def initialize(object) instance_var_name object init_attribute_values(object) end def init_attribute_values(object) attributes.keys.each { |k| send("#{k}=", object.send(k)) } end def init_object_values(object) attributes.each { |k, v| object.send("#{k}=", v) } end def persisted? false end def save(params) attributes.keys.each { |k| send("#{k}=", params[k]) } if valid? save_object true else false end end # This method only exists so the related factory tests pass def save! valid? end private # Written in the subclass def save_object end def instance_var_name(object) name = "@#{object.class.to_s.underscore.gsub('_decorator', '')}" instance_variable_set(name, object) end end end
Version data entries
65 entries across 65 versions & 1 rubygems