Class: Necropsy::Resolution

Inherits:
Data
  • Object
show all
Defined in:
lib/necropsy/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(call_site_id:, target_definition_ids:, status:, unknown_scope: nil, rejected_targets: [], evidence_ids: []) ⇒ Resolution

Returns a new instance of Resolution.

Raises:

  • (ArgumentError)


166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/necropsy/models.rb', line 166

def initialize(call_site_id:, target_definition_ids:, status:, unknown_scope: nil, rejected_targets: [],
               evidence_ids: [])
  call_site_id = ModelNormalization.identifier(call_site_id, 'call_site_id')
  target_definition_ids = ModelNormalization.string_list(target_definition_ids, 'target_definition_id')
  status = status.to_sym if status.respond_to?(:to_sym)
  raise ArgumentError, "invalid resolution status: #{status.inspect}" unless RESOLUTION_STATUSES.include?(status)

  unknown_scope = normalize_unknown_scope(unknown_scope)
  rejected_targets = normalize_rejected_targets(rejected_targets)
  evidence_ids = ModelNormalization.string_list(evidence_ids, 'evidence_id')
  validate_state!(status, target_definition_ids, unknown_scope)
  super
end

Instance Attribute Details

#call_site_idObject (readonly)

Returns the value of attribute call_site_id

Returns:

  • (Object)

    the current value of call_site_id



158
159
160
# File 'lib/necropsy/models.rb', line 158

def call_site_id
  @call_site_id
end

#evidence_idsObject (readonly)

Returns the value of attribute evidence_ids

Returns:

  • (Object)

    the current value of evidence_ids



158
159
160
# File 'lib/necropsy/models.rb', line 158

def evidence_ids
  @evidence_ids
end

#rejected_targetsObject (readonly)

Returns the value of attribute rejected_targets

Returns:

  • (Object)

    the current value of rejected_targets



158
159
160
# File 'lib/necropsy/models.rb', line 158

def rejected_targets
  @rejected_targets
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



158
159
160
# File 'lib/necropsy/models.rb', line 158

def status
  @status
end

#target_definition_idsObject (readonly)

Returns the value of attribute target_definition_ids

Returns:

  • (Object)

    the current value of target_definition_ids



158
159
160
# File 'lib/necropsy/models.rb', line 158

def target_definition_ids
  @target_definition_ids
end

#unknown_scopeObject (readonly)

Returns the value of attribute unknown_scope

Returns:

  • (Object)

    the current value of unknown_scope



158
159
160
# File 'lib/necropsy/models.rb', line 158

def unknown_scope
  @unknown_scope
end

Class Method Details

.from_h(attributes) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/necropsy/models.rb', line 180

def self.from_h(attributes)
  data = ModelNormalization.attributes(attributes, name)
  new(
    call_site_id: data.fetch('call_site_id'),
    target_definition_ids: data.fetch('target_definition_ids', []),
    status: data.fetch('status'),
    unknown_scope: data['unknown_scope'],
    rejected_targets: data.fetch('rejected_targets', []),
    evidence_ids: data.fetch('evidence_ids', [])
  )
end

Instance Method Details

#to_hObject



192
193
194
195
196
197
198
199
200
201
# File 'lib/necropsy/models.rb', line 192

def to_h
  {
    'call_site_id' => call_site_id,
    'target_definition_ids' => target_definition_ids,
    'status' => status.to_s,
    'unknown_scope' => unknown_scope&.to_h,
    'rejected_targets' => rejected_targets.map(&:to_h),
    'evidence_ids' => evidence_ids
  }
end