Module: EzLogsAgent::ResourceExtractor
- Defined in:
- lib/ez_logs_agent/resource_extractor.rb
Overview
ResourceExtractor provides explicit, opt-in helpers for extracting resource_ids from objects.
This module is a small, boring utility that:
-
Converts ActiveRecord model instances to resource_id hashes
-
Extracts resource_ids from arrays of models
-
Passes through existing resource_ids from hashes
-
Returns empty array for unsupported inputs (defensive)
ResourceExtractor does NOT:
-
Automatically hook into anything
-
Infer resources from SQL or context
-
Guess actor or ownership
-
Read RequestStore or global state
-
Modify EventBuilder or other components
-
Raise exceptions for unsupported input
Missing resource_ids is acceptable. Wrong or guessed resource_ids is NOT acceptable.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Array<Hash>
Extracts resource_ids from a hash containing a :resource_ids key.
-
.from_record(record) ⇒ Array<Hash>
Extracts resource_id from a single ActiveRecord model instance.
-
.from_records(records) ⇒ Array<Hash>
Extracts resource_ids from an array of ActiveRecord model instances.
Class Method Details
.from_hash(hash) ⇒ Array<Hash>
Extracts resource_ids from a hash containing a :resource_ids key
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ez_logs_agent/resource_extractor.rb', line 125 def self.from_hash(hash) return [] unless hash.is_a?(Hash) return [] unless hash.key?(:resource_ids) resource_ids = hash[:resource_ids] return [] unless resource_ids.is_a?(Array) resource_ids rescue => e # Defensive: never raise exceptions, return empty array [] end |
.from_record(record) ⇒ Array<Hash>
Extracts resource_id from a single ActiveRecord model instance
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ez_logs_agent/resource_extractor.rb', line 64 def self.from_record(record) return [] if record.nil? return [] unless active_record_model?(record) [{ resource_type: resource_type_from_class(record.class), resource_id: record.id.to_s }] rescue => e # Defensive: never raise exceptions, return empty array [] end |
.from_records(records) ⇒ Array<Hash>
Extracts resource_ids from an array of ActiveRecord model instances
98 99 100 101 102 103 104 105 |
# File 'lib/ez_logs_agent/resource_extractor.rb', line 98 def self.from_records(records) return [] unless records.is_a?(Array) records.flat_map { |record| from_record(record) }.compact rescue => e # Defensive: never raise exceptions, return empty array [] end |