Class: ReleaseHx::RHYML::Adapter
- Inherits:
-
Object
- Object
- ReleaseHx::RHYML::Adapter
- Defined in:
- lib/releasehx/rhyml/adapter.rb
Overview
Transforms raw API payloads into structured RHYML Release objects.
Uses RHYML mapping definitions to extract, transform, and normalize
data from various issue management systems into a consistent Release structure.
Constant Summary collapse
- SCHEMA_PATH =
File.('../../../specs/data/rhyml-mapping-schema.yaml', __dir__)
- MAPPING_SCHEMA =
SchemaGraphy::Loader.(SCHEMA_PATH)['$schema']
- SKIP_KEYS =
%w[$meta $config changes_array_path].freeze
Instance Method Summary collapse
-
#initialize(mapping:, config:) ⇒ Adapter
constructor
Initializes a new adapter instance with mapping configuration and runtime config.
-
#to_release(payload, release_code:, release_date: nil, release_hash: nil, release_memo: nil, scan: false) ⇒ Release
Transforms a raw data payload into a Release object with mapped changes.
Constructor Details
#initialize(mapping:, config:) ⇒ Adapter
Initializes a new adapter instance with mapping configuration and runtime config.
28 29 30 31 32 |
# File 'lib/releasehx/rhyml/adapter.rb', line 28 def initialize mapping:, config: @mapping = mapping @config = config @defaults = load_defaults end |
Instance Method Details
#to_release(payload, release_code:, release_date: nil, release_hash: nil, release_memo: nil, scan: false) ⇒ Release
Transforms a raw data payload into a Release object with mapped changes.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/releasehx/rhyml/adapter.rb', line 43 def to_release payload, release_code:, release_date: nil, release_hash: nil, release_memo: nil, scan: false ReleaseHx.logger.debug "Adapter.to_release called (scan = #{scan})" array_path = mapping['changes_array_path'] raw_items = resolve_path(array_path, payload) if raw_items.nil? payload_info = payload.is_a?(Hash) ? payload.keys.inspect : payload.class.name ReleaseHx.logger.error "Failed to extract items from path '#{array_path}'. Payload: #{payload_info}" raw_items = [] end ReleaseHx.logger.debug "Extracted raw_items (#{raw_items.size}) from path '#{array_path}'" ReleaseHx.logger.dump "First raw item: #{raw_items.first.inspect}" release = Release.new( code: release_code, date: release_date, hash: release_hash, memo: release_memo, changes: []) ReleaseHx.logger.debug "Mapping #{raw_items.size} raw items..." changes = raw_items.map { |raw| transform_change(raw, release: release, scan: scan) }.compact if changes.empty? ReleaseHx.logger.warn( 'All mapped changes were nil after transformation. ' \ "No changes attached to release #{release_code}.") else with_notes = changes.count { |c| c.note.to_s.strip != '' } ReleaseHx.logger.info( "Transformed #{changes.size} changes for release #{release_code} (#{with_notes} with notes)") end ReleaseHx.logger.debug "Adding #{changes.size} changes to release" if scan ReleaseHx.logger.debug "First change keys: #{changes.first.to_h.keys.inspect}" if scan && changes.any? release.instance_variable_set(:@changes, changes) release end |