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.29.1 lib/decidim/controller_helpers.rb
decidim-core-0.28.4 lib/decidim/controller_helpers.rb
decidim-core-0.27.9 lib/decidim/controller_helpers.rb
decidim-core-0.29.0 lib/decidim/controller_helpers.rb
decidim-core-0.28.3 lib/decidim/controller_helpers.rb
decidim-core-0.27.8 lib/decidim/controller_helpers.rb
decidim-core-0.29.0.rc4 lib/decidim/controller_helpers.rb
decidim-core-0.29.0.rc3 lib/decidim/controller_helpers.rb
decidim-core-0.29.0.rc2 lib/decidim/controller_helpers.rb
decidim-core-0.29.0.rc1 lib/decidim/controller_helpers.rb
decidim-core-0.28.2 lib/decidim/controller_helpers.rb
decidim-core-0.27.7 lib/decidim/controller_helpers.rb
decidim-core-0.28.1 lib/decidim/controller_helpers.rb
decidim-core-0.27.6 lib/decidim/controller_helpers.rb
decidim-core-0.28.0 lib/decidim/controller_helpers.rb
decidim-core-0.27.5 lib/decidim/controller_helpers.rb
decidim-core-0.28.0.rc5 lib/decidim/controller_helpers.rb
decidim-core-0.28.0.rc4 lib/decidim/controller_helpers.rb
decidim-core-0.27.4 lib/decidim/controller_helpers.rb
decidim-core-0.27.3 lib/decidim/controller_helpers.rb