Class: SemgrepWebApp::Deployment

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/semgrep_web_app/models/deployment.rb

Overview

Deployment record, with relevant meta-data and further accesses.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id:, name:, slug:, findings: SKIP, additional_properties: nil) ⇒ Deployment

Returns a new instance of Deployment.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/semgrep_web_app/models/deployment.rb', line 51

def initialize(id:, name:, slug:, findings: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @findings = findings unless findings == SKIP
  @id = id
  @name = name
  @slug = slug
  @additional_properties = additional_properties
end

Instance Attribute Details

#findingsEndpointReference

TODO: Write general description for this method

Returns:



14
15
16
# File 'lib/semgrep_web_app/models/deployment.rb', line 14

def findings
  @findings
end

#idInteger

Unique numerical identifier of the deployment.

Returns:

  • (Integer)


18
19
20
# File 'lib/semgrep_web_app/models/deployment.rb', line 18

def id
  @id
end

#nameString

Human readable name.

Returns:

  • (String)


22
23
24
# File 'lib/semgrep_web_app/models/deployment.rb', line 22

def name
  @name
end

#slugString

Sanitized machine-readable name. Used as primary identifier through the web API.

Returns:

  • (String)


27
28
29
# File 'lib/semgrep_web_app/models/deployment.rb', line 27

def slug
  @slug
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/semgrep_web_app/models/deployment.rb', line 64

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  slug = hash.key?('slug') ? hash['slug'] : nil
  findings = EndpointReference.from_hash(hash['findings']) if hash['findings']

  # 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.
  Deployment.new(id: id,
                 name: name,
                 slug: slug,
                 findings: findings,
                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/semgrep_web_app/models/deployment.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['findings'] = 'findings'
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['slug'] = 'slug'
  @_hash
end

.nullablesObject

An array for nullable fields



47
48
49
# File 'lib/semgrep_web_app/models/deployment.rb', line 47

def self.nullables
  []
end

.optionalsObject

An array for optional fields



40
41
42
43
44
# File 'lib/semgrep_web_app/models/deployment.rb', line 40

def self.optionals
  %w[
    findings
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



96
97
98
99
100
# File 'lib/semgrep_web_app/models/deployment.rb', line 96

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} findings: #{@findings.inspect}, id: #{@id.inspect}, name: #{@name.inspect},"\
  " slug: #{@slug.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



89
90
91
92
93
# File 'lib/semgrep_web_app/models/deployment.rb', line 89

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} findings: #{@findings}, id: #{@id}, name: #{@name}, slug: #{@slug},"\
  " additional_properties: #{@additional_properties}>"
end