lib/beerdb/reader.rb in beerdb-0.8.2 vs lib/beerdb/reader.rb in beerdb-0.9.0

- old
+ new

@@ -4,23 +4,23 @@ module Matcher def match_beers_for_country( name, &blk ) - match_xxx_for_country( name, 'beers', blk ) + match_xxx_for_country( name, 'beers', &blk ) end def match_beers_for_country_n_region( name, &blk ) - match_xxx_for_country_n_region( name, 'beers', blk ) + match_xxx_for_country_n_region( name, 'beers', &blk ) end def match_breweries_for_country( name, &blk ) - match_xxx_for_country( name, 'breweries', blk ) + match_xxx_for_country( name, 'breweries', &blk ) end def match_breweries_for_country_n_region( name, &blk ) - match_xxx_for_country_n_region( name, 'breweries', blk ) + match_xxx_for_country_n_region( name, 'breweries', &blk ) end end # module Matcher @@ -28,11 +28,11 @@ include LogUtils::Logging include BeerDb::Models - include WorldDb::Matcher + include WorldDb::Matcher ## fix: move to BeerDb::Matcher module ??? - cleaner?? why? why not? include BeerDb::Matcher # lets us use match_teams_for_country etc. attr_reader :include_path @@ -149,15 +149,20 @@ def load_breweries_for_country_n_region( country_key, region_key, name, more_attribs={} ) country = Country.find_by_key!( country_key ) logger.debug "Country #{country.key} >#{country.title} (#{country.code})<" - # NB: region lookup requires country id (region key only unique for country) - region = Region.find_by_key_and_country_id!( region_key, country.id ) - logger.debug "Region #{region.key} >#{region.title}<" - more_attribs[ :country_id ] = country.id - more_attribs[ :region_id ] = region.id + + # note: region lookup requires country id (region key only unique for country) + region = Region.find_by_key_and_country_id( region_key, country.id ) + if region.nil? + # note: allow unknown region keys; issue warning n skip region + logger.warn "Region w/ key >#{region_key}< not found; skip adding region" + else + logger.debug "Region #{region.key} >#{region.title}<" + more_attribs[ :region_id ] = region.id + end more_attribs[ :txt ] = name # store source ref load_breweries_worker( name, more_attribs ) end