Sha256: 5706481dc8be1ee003970066669dfd1bfa1fac4a6c4f2c1ebd28b73f80edb9f6

Contents?: true

Size: 1.07 KB

Versions: 31

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true
module ActiveAdmin

  # Shareable module to give a #display_on?(action) method
  # which returns true or false depending on an options hash.
  #
  # The options hash accepts:
  #
  # only: :index
  # only: [:index, :show]
  # except: :index
  # except: [:index, :show]
  #
  # call #normalize_display_options! after @options has been set
  # to ensure that the display options are setup correctly

  module OptionalDisplay
    def display_on?(action, render_context = self)
      return false if @options[:only] && !@options[:only].include?(action.to_sym)
      return false if @options[:except] && @options[:except].include?(action.to_sym)

      case condition = @options[:if]
      when Symbol, String
        render_context.public_send condition
      when Proc
        render_context.instance_exec &condition
      else
        true
      end
    end

    private

    def normalize_display_options!
      @options[:only] = Array(@options[:only]) if @options[:only]
      @options[:except] = Array(@options[:except]) if @options[:except]
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
activeadmin-4.0.0.beta14 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta13 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta12 lib/active_admin/helpers/optional_display.rb
activeadmin-3.2.5 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta11 lib/active_admin/helpers/optional_display.rb
activeadmin-3.2.4 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta10 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta9 lib/active_admin/helpers/optional_display.rb
activeadmin-3.2.3 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta8 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta7 lib/active_admin/helpers/optional_display.rb
activeadmin-3.2.2 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta6 lib/active_admin/helpers/optional_display.rb
activeadmin-3.2.1 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta5 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta4 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta3 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta2 lib/active_admin/helpers/optional_display.rb
activeadmin-4.0.0.beta1 lib/active_admin/helpers/optional_display.rb
activeadmin-3.2.0 lib/active_admin/helpers/optional_display.rb