Sha256: a53ae6eab663b06f36bdad2cc90233197e1f362ec943e58a18c136df74301a67

Contents?: true

Size: 1.18 KB

Versions: 25

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

# Copyright (c) 2016 Andy Pike - The MIT license
#
# This file has been copied from https://github.com/andypike/rectify/blob/master/lib/rectify/controller_helpers.rb
# We have done this so we can decouple Decidim from any Virtus dependency, which is a dead project
# Please follow Decidim discussion to understand more https://github.com/decidim/decidim/discussions/7234
module Decidim
  module ControllerHelpers
    def self.included(base_class)
      base_class.helper_method(:presenter)
    end

    def present(presenter, options = {})
      presenter_type = options.fetch(:for, :template)

      presenter.attach_controller(self)
      rectify_presenters[presenter_type] = presenter
    end

    def presenter(presenter_type = :template)
      rectify_presenters[presenter_type]
    end

    def expose(presentation_data)
      presentation_data.each do |attribute, value|
        if presenter.respond_to?("#{attribute}=")
          presenter.public_send("#{attribute}=", value)
        else
          instance_variable_set("@#{attribute}", value)
        end
      end
    end

    private

    def rectify_presenters
      @rectify_presenters ||= {}
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-core-0.27.2 lib/decidim/controller_helpers.rb
decidim-core-0.27.1 lib/decidim/controller_helpers.rb
decidim-core-0.27.0 lib/decidim/controller_helpers.rb
decidim-core-0.27.0.rc2 lib/decidim/controller_helpers.rb
decidim-core-0.27.0.rc1 lib/decidim/controller_helpers.rb