Class: SemgrepWebApp::Policy

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

Overview

Policy Model.

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: SKIP, is_default: SKIP, name: SKIP, product_type: SKIP, slug: SKIP, additional_properties: nil) ⇒ Policy

Returns a new instance of Policy.



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/semgrep_web_app/models/policy.rb', line 63

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

  @id = id unless id == SKIP
  @is_default = is_default unless is_default == SKIP
  @name = name unless name == SKIP
  @product_type = product_type unless product_type == SKIP
  @slug = slug unless slug == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#idString

ID of the Policy.

Returns:

  • (String)


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

def id
  @id
end

#is_defaultTrueClass | FalseClass

When True, the Policy applies to all repositories.

Returns:

  • (TrueClass | FalseClass)


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

def is_default
  @is_default
end

#nameString

Name of the Policy.

Returns:

  • (String)


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

def name
  @name
end

#product_typeProductType

Product type the Policy applies to.

value description
PRODUCT_TYPE_SAST The product type for Code rules.
PRODUCT_TYPE_SECRETS The product type for Secrets rules.

Returns:



30
31
32
# File 'lib/semgrep_web_app/models/policy.rb', line 30

def product_type
  @product_type
end

#slugString

Sanitized machine-readable name of the Policy.

Returns:

  • (String)


34
35
36
# File 'lib/semgrep_web_app/models/policy.rb', line 34

def slug
  @slug
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/semgrep_web_app/models/policy.rb', line 77

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  is_default = hash.key?('isDefault') ? hash['isDefault'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  product_type = hash.key?('productType') ? hash['productType'] : SKIP
  slug = hash.key?('slug') ? hash['slug'] : SKIP

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

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
# File 'lib/semgrep_web_app/models/policy.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['is_default'] = 'isDefault'
  @_hash['name'] = 'name'
  @_hash['product_type'] = 'productType'
  @_hash['slug'] = 'slug'
  @_hash
end

.nullablesObject

An array for nullable fields



59
60
61
# File 'lib/semgrep_web_app/models/policy.rb', line 59

def self.nullables
  []
end

.optionalsObject

An array for optional fields



48
49
50
51
52
53
54
55
56
# File 'lib/semgrep_web_app/models/policy.rb', line 48

def self.optionals
  %w[
    id
    is_default
    name
    product_type
    slug
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



111
112
113
114
115
116
# File 'lib/semgrep_web_app/models/policy.rb', line 111

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

#to_sObject

Provides a human-readable string representation of the object.



104
105
106
107
108
# File 'lib/semgrep_web_app/models/policy.rb', line 104

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