Sha256: 8c8a673053fba0f5e74266f8c40dd5f43022de74c1e9be7bde908a13e6e547de

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

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

5 entries across 5 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/helpers/optional_display.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/helpers/optional_display.rb
activeadmin-2.9.0 lib/active_admin/helpers/optional_display.rb
activeadmin-2.8.1 lib/active_admin/helpers/optional_display.rb
activeadmin-2.8.0 lib/active_admin/helpers/optional_display.rb