Class: Blacklight::Configuration::Context
- Inherits:
 - 
      Object
      
        
- Object
 - Blacklight::Configuration::Context
 
 
- Defined in:
 - lib/blacklight/configuration/context.rb
 
Overview
This class helps determine whether a specific field/tool should display for a particular controller. This is used when the field/tool is configured with an if or unless argument.
e.g.
config.add_results_document_tool(:bookmark,
                                 partial: 'bookmark_control',
                                 if: :render_bookmarks_control?)
The context points at the scope for where to evaluate the method render_bookmarks_control?
Instance Attribute Summary collapse
- 
  
    
      #context  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute context.
 
Instance Method Summary collapse
- #evaluate_configuration_conditional(proc_helper_or_boolean, *args_for_procs_and_methods) ⇒ Object
 - 
  
    
      #evaluate_if_unless_configuration(config, *args)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Evaluate conditionals for a configuration with if/unless attributes.
 - 
  
    
      #initialize(context)  ⇒ Context 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Context.
 
Constructor Details
#initialize(context) ⇒ Context
Returns a new instance of Context.
      18 19 20  | 
    
      # File 'lib/blacklight/configuration/context.rb', line 18 def initialize(context) @context = context end  | 
  
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
      16 17 18  | 
    
      # File 'lib/blacklight/configuration/context.rb', line 16 def context @context end  | 
  
Instance Method Details
#evaluate_configuration_conditional(proc_helper_or_boolean, *args_for_procs_and_methods) ⇒ Object
      41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56  | 
    
      # File 'lib/blacklight/configuration/context.rb', line 41 def evaluate_configuration_conditional(proc_helper_or_boolean, *args_for_procs_and_methods) case proc_helper_or_boolean when Symbol arity = context.method(proc_helper_or_boolean).arity if arity.zero? context.send(proc_helper_or_boolean) else context.send(proc_helper_or_boolean, *args_for_procs_and_methods) end when Proc proc_helper_or_boolean.call context, *args_for_procs_and_methods else proc_helper_or_boolean end end  | 
  
#evaluate_if_unless_configuration(config, *args) ⇒ Boolean
Evaluate conditionals for a configuration with if/unless attributes
      27 28 29 30 31 32 33 34 35 36 37 38 39  | 
    
      # File 'lib/blacklight/configuration/context.rb', line 27 def evaluate_if_unless_configuration(config, *args) return config if config == true || config == false if_value = !config.respond_to?(:if) || config.if.nil? || evaluate_configuration_conditional(config.if, config, *args) unless_value = !config.respond_to?(:unless) || config.unless.nil? || !evaluate_configuration_conditional(config.unless, config, *args) if_value && unless_value end  |