Module: Dradis::Plugins::Mappings::Base::ClassMethods
- Defined in:
 - lib/dradis/plugins/mappings/base.rb
 
Instance Method Summary collapse
- #component ⇒ Object
 - #default_mapping(source) ⇒ Object
 - #default_mapping_fields(source) ⇒ Object
 - #field_names(source:, destination: nil, field_type: 'destination') ⇒ Object
 - 
  
    
      #get_mapping(source:, destination:)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
returns single matching mapping given source & destination or default.
 - #mapping_fields(source:, destination:) ⇒ Object
 - #mapping_sources ⇒ Object
 - 
  
    
      #mappings(source: nil, destination: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
given the params returns all matching mappings will accept source and/or destination or no args.
 - #source_fields(source) ⇒ Object
 
Instance Method Details
#component ⇒ Object
      18 19 20  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 18 def component [:name].to_s end  | 
  
#default_mapping(source) ⇒ Object
      36 37 38 39 40  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 36 def default_mapping(source) if mapping_sources.include?(source.to_sym) self::Mapping::DEFAULT_MAPPING[source.to_sym] end end  | 
  
#default_mapping_fields(source) ⇒ Object
      12 13 14 15 16  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 12 def default_mapping_fields(source) default_mapping(source).map do |destination_field, content| MappingField.new(destination_field: destination_field, content: content) end end  | 
  
#field_names(source:, destination: nil, field_type: 'destination') ⇒ Object
      22 23 24 25 26 27 28 29 30 31 32 33 34  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 22 def field_names(source:, destination: nil, field_type: 'destination') mappings = mappings(source: source, destination: destination) mapping_fields = if mappings.any? mappings.map(&:mapping_fields).flatten end if mapping_fields && mapping_fields.any? mapping_fields.pluck("#{field_type}_field").uniq else default_mapping(source).keys end end  | 
  
#get_mapping(source:, destination:) ⇒ Object
returns single matching mapping given source & destination or default
      54 55 56 57 58 59 60  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 54 def get_mapping(source:, destination:) mapping = Mapping.includes(:mapping_fields).find_by( component: component, source: source, destination: destination ) end  | 
  
#mapping_fields(source:, destination:) ⇒ Object
      62 63 64 65 66 67 68 69 70  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 62 def mapping_fields(source:, destination:) mapping = get_mapping(source: source, destination: destination) if mapping mapping.mapping_fields else default_mapping_fields(source) end end  | 
  
#mapping_sources ⇒ Object
      72 73 74  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 72 def mapping_sources self::Mapping::SOURCE_FIELDS.keys end  | 
  
#mappings(source: nil, destination: nil) ⇒ Object
given the params returns all matching mappings will accept source and/or destination or no args
      44 45 46 47 48 49 50 51  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 44 def mappings(source: nil, destination: nil) mappings = Mapping.includes(:mapping_fields).where( component: component ) mappings = mappings.where(source: source) if source mappings = mappings.where(destination: destination) if destination mappings end  | 
  
#source_fields(source) ⇒ Object
      76 77 78 79 80  | 
    
      # File 'lib/dradis/plugins/mappings/base.rb', line 76 def source_fields(source) if mapping_sources.include?(source.to_sym) self::Mapping::SOURCE_FIELDS[source.to_sym] end end  |