Class: SemgrepWebApp::Assistant
- Defined in:
- lib/semgrep_web_app/models/assistant.rb
Overview
Semgrep Assistant data. Only present if Assistant is enabled
Instance Attribute Summary collapse
-
#autofix ⇒ Autofix
Fix data generated by Semgrep Assistant.
-
#autotriage ⇒ Autotriage
Triage recommendation generated by Semgrep Assistant.
-
#component ⇒ Component
Semgrep Assistant's guess as for what the matched source code's purpose is.
-
#guidance ⇒ Guidance
Remediation guidance generated by Semgrep Assistant.
-
#rule_explanation ⇒ RuleExplanation
AI-generated explanation of why a rule flagged this specific code.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(autofix: SKIP, autotriage: SKIP, component: SKIP, guidance: SKIP, rule_explanation: SKIP, additional_properties: nil) ⇒ Assistant
constructor
A new instance of Assistant.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(autofix: SKIP, autotriage: SKIP, component: SKIP, guidance: SKIP, rule_explanation: SKIP, additional_properties: nil) ⇒ Assistant
Returns a new instance of Assistant.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 59 def initialize(autofix: SKIP, autotriage: SKIP, component: SKIP, guidance: SKIP, rule_explanation: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @autofix = autofix unless autofix == SKIP @autotriage = autotriage unless autotriage == SKIP @component = component unless component == SKIP @guidance = guidance unless guidance == SKIP @rule_explanation = rule_explanation unless rule_explanation == SKIP @additional_properties = additional_properties end |
Instance Attribute Details
#autofix ⇒ Autofix
Fix data generated by Semgrep Assistant
14 15 16 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 14 def autofix @autofix end |
#autotriage ⇒ Autotriage
Triage recommendation generated by Semgrep Assistant
18 19 20 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 18 def autotriage @autotriage end |
#component ⇒ Component
Semgrep Assistant's guess as for what the matched source code's purpose is
22 23 24 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 22 def component @component end |
#guidance ⇒ Guidance
Remediation guidance generated by Semgrep Assistant
26 27 28 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 26 def guidance @guidance end |
#rule_explanation ⇒ RuleExplanation
AI-generated explanation of why a rule flagged this specific code
30 31 32 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 30 def rule_explanation @rule_explanation end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 74 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. autofix = Autofix.from_hash(hash['autofix']) if hash['autofix'] autotriage = Autotriage.from_hash(hash['autotriage']) if hash['autotriage'] component = Component.from_hash(hash['component']) if hash['component'] guidance = Guidance.from_hash(hash['guidance']) if hash['guidance'] rule_explanation = RuleExplanation.from_hash(hash['rule_explanation']) if hash['rule_explanation'] # Create a new hash for additional properties, removing known properties. new_hash = hash.reject { |k, _| names.value?(k) } additional_properties = APIHelper.get_additional_properties( new_hash, proc { |value| value } ) # Create object from extracted values. Assistant.new(autofix: autofix, autotriage: autotriage, component: component, guidance: guidance, rule_explanation: rule_explanation, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
33 34 35 36 37 38 39 40 41 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 33 def self.names @_hash = {} if @_hash.nil? @_hash['autofix'] = 'autofix' @_hash['autotriage'] = 'autotriage' @_hash['component'] = 'component' @_hash['guidance'] = 'guidance' @_hash['rule_explanation'] = 'rule_explanation' @_hash end |
.nullables ⇒ Object
An array for nullable fields
55 56 57 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 55 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
44 45 46 47 48 49 50 51 52 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 44 def self.optionals %w[ autofix autotriage component guidance rule_explanation ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
103 104 105 106 107 108 109 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 103 def self.validate(value) return true if value.instance_of? self return false unless value.instance_of? Hash true end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
120 121 122 123 124 125 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 120 def inspect class_name = self.class.name.split('::').last "<#{class_name} autofix: #{@autofix.inspect}, autotriage: #{@autotriage.inspect},"\ " component: #{@component.inspect}, guidance: #{@guidance.inspect}, rule_explanation:"\ " #{@rule_explanation.inspect}, additional_properties: #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
112 113 114 115 116 117 |
# File 'lib/semgrep_web_app/models/assistant.rb', line 112 def to_s class_name = self.class.name.split('::').last "<#{class_name} autofix: #{@autofix}, autotriage: #{@autotriage}, component: #{@component},"\ " guidance: #{@guidance}, rule_explanation: #{@rule_explanation}, additional_properties:"\ " #{@additional_properties}>" end |