Files
BikeShed-1/app/models/bike_csv_importer/cache.rb
T

27 lines
735 B
Ruby

class BikeCsvImporter
module Cache
def cached_bike_purpose(purpose)
@bike_purpose_cache ||= {}
@bike_purpose_cache[purpose] ||= BikePurpose.find_by_purpose purpose
end
def cached_bike_brand(brand)
@bike_brand_cache ||= {}
if @bike_brand_cache.has_key? brand
@bike_brand_cache[brand]
else
@bike_brand_cache[brand] = BikeBrand.where('lower(brand) = ?', brand.downcase).first
end
end
def cached_bike_model(model)
@bike_model_cache ||= {}
if @bike_model_cache.has_key? model
@bike_model_cache[model]
else
@bike_model_cache[model] = BikeModel.where('lower(model) = ?', model.downcase).first
end
end
end
end