Module: AbAdmin::Config::OptionalDisplay
- Included in:
- ActionItem, CustomAction
- Defined in:
- lib/ab_admin/config/optional_display.rb
Overview
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
Instance Method Summary collapse
Instance Method Details
#for_action?(action) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/ab_admin/config/optional_display.rb', line 32 def for_action?(action) return false if @options[:only] && !@options[:only].include?(action.to_sym) return false if @options[:except] && @options[:except].include?(action.to_sym) true end |
#for_context?(render_context = nil, *args) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ab_admin/config/optional_display.rb', line 17 def for_context?(render_context = nil, *args) 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(*args, &symbol_or_proc) : instance_exec(*args, &symbol_or_proc) else symbol_or_proc end end true end |