Class: FieldInfo
- Inherits:
 - 
      Object
      
        
- Object
 - FieldInfo
 
 
- Includes:
 - ActiveModel::Model
 
- Defined in:
 - app/models/field_info.rb
 
Overview
There no subclasses at the moment, because we want to keep things simple
(especially no need to use a factory)
Defined Under Namespace
Modules: NullFieldInfo
Constant Summary collapse
- SELECTION =
 'Selection'- TEXT =
 'Text'- BOOLEAN =
 'Boolean'- NUMERIC =
 'Numeric'- KIND =
          
Sorted in order of least restrictiveness
 [TEXT, NUMERIC, SELECTION, BOOLEAN].freeze
Instance Attribute Summary collapse
- 
  
    
      #default_value  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute default_value.
 - 
  
    
      #display_name  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute display_name.
 - 
  
    
      #key  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute key.
 - 
  
    
      #kind  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute kind.
 - 
  
    
      #max  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute max.
 - 
  
    
      #min  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute min.
 - 
  
    
      #required  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute required.
 - 
  
    
      #selection  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute selection.
 - 
  
    
      #step  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute step.
 
Class Method Summary collapse
Instance Method Summary collapse
- 
  
    
      #&(other)  ⇒ FieldInfo 
    
    
  
  
  
  
  
  
  
  
  
    
Combine two field infos to one with the most limited options.
 - #==(other) ⇒ Object
 - #kind_priority ⇒ Object
 - #parameters ⇒ Object
 - 
  
    
      #parameters=(parameters)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Parameters were only ever used to hold selection This provides legacy support for a handful of serialized field infos in the database.
 - #value ⇒ Object
 
Instance Attribute Details
#default_value ⇒ Object
Returns the value of attribute default_value.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def default_value @default_value end  | 
  
#display_name ⇒ Object
Returns the value of attribute display_name.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def display_name @display_name end  | 
  
#key ⇒ Object
Returns the value of attribute key.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def key @key end  | 
  
#kind ⇒ Object
Returns the value of attribute kind.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def kind @kind end  | 
  
#max ⇒ Object
Returns the value of attribute max.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def max @max end  | 
  
#min ⇒ Object
Returns the value of attribute min.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def min @min end  | 
  
#required ⇒ Object
Returns the value of attribute required.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def required @required end  | 
  
#selection ⇒ Object
Returns the value of attribute selection.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def selection @selection end  | 
  
#step ⇒ Object
Returns the value of attribute step.
      24 25 26  | 
    
      # File 'app/models/field_info.rb', line 24 def step @step end  | 
  
Class Method Details
.for_request_types(request_types) ⇒ Object
      26 27 28 29 30 31 32 33 34  | 
    
      # File 'app/models/field_info.rb', line 26 def self.for_request_types(request_types) attributes = Hash.new(NullFieldInfo) request_types.each do |request_type| request_type.request_attributes.each { |att| attributes[att.name] &= att.to_field_info(request_type) } end attributes.values end  | 
  
Instance Method Details
#&(other) ⇒ FieldInfo
Combine two field infos to one with the most limited options
      57 58 59 60 61 62 63 64 65 66 67 68 69  | 
    
      # File 'app/models/field_info.rb', line 57 def &(other) # rubocop:todo Metrics/AbcSize raise StandardError, "Attempted to combine #{key} with #{other.key} FieldInfos" unless key == other.key dup.tap do |combined| # Use set selector to filter to those common to all attributes combined.selection = [combined.selection, other.selection].compact.reduce(&:&) combined.required ||= other.required # If kinds differ, we want to select the most restrictive (eg. selection over numeric) combined.kind = other.kind if combined.kind_priority < other.kind_priority combined.default_value ||= other.default_value end end  | 
  
#==(other) ⇒ Object
      71 72 73 74  | 
    
      # File 'app/models/field_info.rb', line 71 def ==(other) display_name == other.display_name && key == other.key && kind == other.kind && default_value == other.default_value && selection == other.selection end  | 
  
#kind_priority ⇒ Object
      76 77 78  | 
    
      # File 'app/models/field_info.rb', line 76 def kind_priority KIND.index(kind) end  | 
  
#parameters ⇒ Object
      44 45 46  | 
    
      # File 'app/models/field_info.rb', line 44 def parameters { min:, max:, step: } end  | 
  
#parameters=(parameters) ⇒ Object
Parameters were only ever used to hold selection This provides legacy support for a handful of serialized field infos in the database
      39 40 41  | 
    
      # File 'app/models/field_info.rb', line 39 def parameters=(parameters) self.selection = parameters&.fetch(:selection, []) end  | 
  
#value ⇒ Object
      48 49 50  | 
    
      # File 'app/models/field_info.rb', line 48 def value default_value || '' end  |