Class: ERBLint::Linters::ArgumentMappers::SystemArguments
- Inherits:
 - 
      Object
      
        
- Object
 - ERBLint::Linters::ArgumentMappers::SystemArguments
 
 
- Defined in:
 - lib/primer/view_components/linters/argument_mappers/system_arguments.rb
 
Overview
Maps element attributes to system arguments.
Constant Summary collapse
- STRING_PARAMETERS =
 %w[aria- data-].freeze
- TEST_SELECTOR_REGEX =
 /test_selector\((?<selector>.+)\)$/.freeze
Instance Attribute Summary collapse
- 
  
    
      #attribute  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute attribute.
 - 
  
    
      #erb_helper  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute erb_helper.
 
Instance Method Summary collapse
- #attr_name ⇒ Object
 - 
  
    
      #initialize(attribute)  ⇒ SystemArguments 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of SystemArguments.
 - #to_args ⇒ Object
 
Constructor Details
#initialize(attribute) ⇒ SystemArguments
Returns a new instance of SystemArguments.
      16 17 18 19  | 
    
      # File 'lib/primer/view_components/linters/argument_mappers/system_arguments.rb', line 16 def initialize(attribute) @attribute = attribute @erb_helper = Helpers::ErbBlock.new end  | 
  
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
      14 15 16  | 
    
      # File 'lib/primer/view_components/linters/argument_mappers/system_arguments.rb', line 14 def attribute @attribute end  | 
  
#erb_helper ⇒ Object (readonly)
Returns the value of attribute erb_helper.
      14 15 16  | 
    
      # File 'lib/primer/view_components/linters/argument_mappers/system_arguments.rb', line 14 def erb_helper @erb_helper end  | 
  
Instance Method Details
#attr_name ⇒ Object
      42 43 44  | 
    
      # File 'lib/primer/view_components/linters/argument_mappers/system_arguments.rb', line 42 def attr_name attribute.name end  | 
  
#to_args ⇒ Object
      21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  | 
    
      # File 'lib/primer/view_components/linters/argument_mappers/system_arguments.rb', line 21 def to_args if attribute.erb? _, _, code_node = *attribute.node raise ConversionError, "Cannot convert erb block" if code_node.nil? code = code_node.loc.source.strip m = code.match(TEST_SELECTOR_REGEX) raise ConversionError, "Cannot convert erb block" if m.blank? { test_selector: m[:selector].tr("'", '"') } elsif attr_name == "data-test-selector" { test_selector: erb_helper.convert(attribute) } elsif attr_name.start_with?(*STRING_PARAMETERS) { "\"#{attr_name}\"" => erb_helper.convert(attribute) } else raise ConversionError, "Cannot convert attribute \"#{attr_name}\"" end end  |