class Frigate::Form::Synchronizer::Basic::ModelSynchronizer

A class for synchronization model with params

Public Instance Methods

sync_with_model(opts={}) click to toggle source

Synchronizes given model with form properties and associations:properties @param [Hash] ops

# File lib/frigate/form/synchronizer/basic.rb, line 11
def sync_with_model(opts={})
        sync_properties
        sync_associations
        save_model if opts[:save]
end

Private Instance Methods

_sync_associations(f_ctx, m_ctx) click to toggle source
# File lib/frigate/form/synchronizer/basic.rb, line 31
def _sync_associations(f_ctx, m_ctx)
        f_ctx.associations.each do |_assoc|
                n_m_ctx = m_ctx.send(_assoc.name.to_sym)
                if m_ctx.is_a?(ActiveRecord::Base) and n_m_ctx.nil?
                        m_ctx.send("build_#{_assoc.name}")
                end
                _assoc.properties.each do |_prop|
                        _sync_properties(_assoc, n_m_ctx)
                end
                _sync_associations(_assoc, n_m_ctx)
        end
end
_sync_properties(f_ctx, m_ctx) click to toggle source
# File lib/frigate/form/synchronizer/basic.rb, line 44
def _sync_properties(f_ctx, m_ctx)
        f_ctx.properties.each do |_prop|
                m_ctx.send("#{_prop.name}=", _prop.value) unless _prop.value.nil?
        end
end
save_model() click to toggle source
# File lib/frigate/form/synchronizer/basic.rb, line 19
def save_model
        form.model.save!
end
sync_associations() click to toggle source
# File lib/frigate/form/synchronizer/basic.rb, line 23
def sync_associations
        _sync_associations(form, form.model)
end
sync_properties() click to toggle source
# File lib/frigate/form/synchronizer/basic.rb, line 27
def sync_properties
        _sync_properties(form, form.model)
end