Sha256: 7daad13410be1649990ed3eefd9c3e92d4f5ae51ff34d9b3bdc326f505cbc8be

Contents?: true

Size: 966 Bytes

Versions: 19

Compression:

Stored size: 966 Bytes

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)
      return @options[:only].include?(action.to_sym) if @options[:only]
      return !@options[:except].include?(action.to_sym) if @options[:except]
      true
    end

    private

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

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
activeadmin-0.4.0 lib/active_admin/helpers/optional_display.rb
andrewroth_activeadmin-0.3.4.4 lib/active_admin/helpers/optional_display.rb
andrewroth_activeadmin-0.3.4.3 lib/active_admin/helpers/optional_display.rb
andrewroth_activeadmin-0.3.4.2 lib/active_admin/helpers/optional_display.rb
andrewroth_activeadmin-0.3.4.1 lib/active_admin/helpers/optional_display.rb
andrewroth_activeadmin-0.3.4 lib/active_admin/helpers/optional_display.rb
activeadmin-0.3.4 lib/active_admin/helpers/optional_display.rb
activeadmin-0.3.3 lib/active_admin/helpers/optional_display.rb
activeadmin-0.3.2 lib/active_admin/helpers/optional_display.rb
activeadmin-0.3.1 lib/active_admin/helpers/optional_display.rb
activeadmin-0.3.0 lib/active_admin/helpers/optional_display.rb
nsm-activeadmin-0.2.2 lib/active_admin/helpers/optional_display.rb
saulolso-activeadmin-0.2.2.1 lib/active_admin/helpers/optional_display.rb
saulolso-activeadmin-0.2.2 lib/active_admin/helpers/optional_display.rb
activeadmin-0.2.2 lib/active_admin/helpers/optional_display.rb
activeadmin-0.2.1 lib/active_admin/helpers/optional_display.rb
activeadmin-0.2.0 lib/active_admin/helpers/optional_display.rb
activeadmin-0.1.1 lib/active_admin/helpers/optional_display.rb
activeadmin-0.1.0 lib/active_admin/helpers/optional_display.rb