Sha256: da4701fb1f1390edfe81ba109d17dbcd9044afb6631e14f41503132bbc969fc1

Contents?: true

Size: 582 Bytes

Versions: 16

Compression:

Stored size: 582 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Plans
    # Updater for nested models.
    module NestedUpdater
      private

      def update_nested_model(form, attributes, parent_association)
        record = parent_association.find_by(id: form.id) || parent_association.build(attributes)

        yield record if block_given?

        if record.persisted?
          if form.deleted?
            record.destroy!
          else
            record.update!(attributes)
          end
        elsif !form.deleted?
          record.save!
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-plans-0.18.2 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.18.1 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.18.0 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.17.0 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.9 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.8 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.7 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.6 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.5 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.4 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.3 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.2 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.1 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.16.0 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.15.1 app/commands/decidim/plans/nested_updater.rb
decidim-plans-0.15.0 app/commands/decidim/plans/nested_updater.rb