Skip to content

Commit

Permalink
Merge branch 'release-4.8.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomarrocoli committed Mar 22, 2022
2 parents ba44179 + 58bcef3 commit 8d16c69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 4.8.7

- Use constants to select S3 bucket for data download

### 4.8.6

- Chore: March 2022 WDPA Release
Expand Down
15 changes: 13 additions & 2 deletions lib/modules/wdpa/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ def current_wdpa_identifier
private

def current_wdpa
# This uses the release date constants in config/initializers/constants.rb to
# find the S3 bucket associated with the current release, and return it.
# If it doesn't find a bucket with the constant dates it falls back on
# the previous method to fetch the most recent bucket
wdpa_from_constants = available_wdpa_databases.find {|object| object.key.include?("#{WDPA_UPDATE_MONTH.first(3)}#{WDPA_UPDATE_YEAR}") }
wdpa_from_constants ? wdpa_from_constants.object : latest_wdpa
end

def latest_wdpa
latest = available_wdpa_databases.max_by do |object|
filename = object.key # e.g. "WDPA_WDOECM_Sep2020_Public.gdb.zip"

Expand All @@ -47,7 +56,9 @@ def current_wdpa
end

def available_wdpa_databases
bucket_name = Rails.application.secrets.aws_bucket
@s3.bucket(bucket_name).objects
@_available_wdpa_databases ||= begin
bucket_name = Rails.application.secrets.aws_bucket
@s3.bucket(bucket_name).objects
end
end
end

0 comments on commit 8d16c69

Please sign in to comment.