Sha256: b40a85f7802bfac36be883cf1991984fc5b433f69440771848e7126da2a282d7

Contents?: true

Size: 1.24 KB

Versions: 46

Compression:

Stored size: 1.24 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 = nil)
      return false if @options[:only] && !@options[:only].include?(action.to_sym)
      return false if @options[:except] && @options[:except].include?(action.to_sym)
      if @options[:if]
        symbol_or_proc = @options[:if]
        return case symbol_or_proc
        when Symbol, String
          render_context ? render_context.send(symbol_or_proc) : self.send(symbol_or_proc)
        when Proc
          render_context ? render_context.instance_exec(&symbol_or_proc) : instance_exec(&symbol_or_proc)
        else symbol_or_proc
        end
      end
      true
    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

46 entries across 46 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/helpers/optional_display.rb