Skip to content

Commit

Permalink
Fix metadata, emit array
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Jan 30, 2024
1 parent 379bebf commit a08e23c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
25 changes: 12 additions & 13 deletions datasources/sources/geotrek.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,18 @@ def practice_slug(practice)
}][(practice&.dig('name', 'en') || practice&.dig('name', 'fr'))&.parameterize]
end

sig { returns(MetadataRow) }
def metadata
super.deep_merge_array({
data: @practices.to_h{ |practice_id, practice|
[
practice_slug(practice_id),
{
name: practice['name'],
attribution: @settings.attribution,
}.compact_blank
]
}.compact_blank
})
sig { returns(T::Array[MetadataRow]) }
def metadatas
super + @practices.collect{ |practice_id, practice|
MetadataRow.new({
data: {
practice_slug(practice_id) => Metadata.from_hash({
'name' => practice['name'],
'attribution' => @settings.attribution,
})
}.compact_blank
})
}
end

def map_destination_id(type_feat)
Expand Down
8 changes: 4 additions & 4 deletions datasources/sources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def load(urls)
}
end

sig { returns(MetadataRow) }
def metadata
super.deep_merge_array({
sig { returns(T::Array[MetadataRow]) }
def metadatas
[super[0].deep_merge_array({
'data' => load(@settings.meta)&.inject({}, &:deep_merge_array),
})
})]
end

sig { returns(SchemaRow) }
Expand Down
17 changes: 9 additions & 8 deletions datasources/sources/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ def initialize(job_id, destination_id, name, settings)
@settings = settings
end

sig { returns(MetadataRow) }
def metadata
MetadataRow.new(
destination_id: @destination_id,
sig { returns(T::Array[MetadataRow]) }
def metadatas
[MetadataRow.new(
data: {
@destination_id => Metadata.from_hash({
'name' => @name,
'attribution' => @settings.attribution
}).deep_merge_array(@settings.metadata)
}.compact_blank
)
)]
end

sig { returns(SchemaRow) }
Expand Down Expand Up @@ -219,15 +218,17 @@ def one(row, bad)
end

def each(raw)
metadata_data = metadata
yield [:metadata, metadata_data]
metadata_datas = metadatas
metadata_datas.each{ |metadata_data|
yield [:metadata, metadata_data]
}
schema_data = schema
yield [:schema, schema_data]
osm_tags_data = osm_tags
yield [:osm_tags, osm_tags_data]

log = " > #{self.class.name}, #{@destination_id.inspect}: #{raw.size}"
log += ' +metadata' if metadata_data.present?
log += ' +metadata' if metadata_datas.present?
log += ' +schema' if schema_data.schema.present?
log += ' +i18n' if schema_data.i18n.present?
log += ' +osm_tags' if osm_tags_data.data.present?
Expand Down

0 comments on commit a08e23c

Please sign in to comment.