Sha256: cf1a166c9c183db032cedcc0662f8e372e64a658838f6d717db147437b016a6d
Contents?: true
Size: 1.51 KB
Versions: 88
Compression:
Stored size: 1.51 KB
Contents
# frozen_string_literal: true # # Take an existing either paperclip object or database field and return # a fully qualified cdn url for that file. # # If the system configuration parameter for the url is not set, then simply return the value. # # If it is set, then replace the prefix of the URL defined by the boundry of class name, so account_report will be # https://original.amazon.com/account_report/id/report.xlsx # # will be transposed to: # https://cnd.apazon.com/account_report/id/report.xlsx # # To use this, first include CdnUrl in your class and then when you want the URL of an object call # report.cdn_file_url instead of report.file_url. # module CdnUrl extend ActiveSupport::Concern def method_missing(method, *args) if method.to_s.start_with? 'cdn_' url = if args.blank? send method.to_s.sub(/^cdn_/, '').to_sym else send method.to_s.sub(/^cdn_/, '').to_sym, *args end cdn_url = SystemConfiguration.cdn_url if [cdn_url.present?, url.present?].all? model_name = "#{self.class.to_s.underscore}s" if url.include? "/#{model_name}/" "#{cdn_url}/#{model_name}/#{url.split("/#{model_name}/").last}" else url end else url end else super end end def respond_to_missing?(method_name, include_private = false) super || method_name.to_s.start_with?('cdn_') end def respond_to?(method, include_private = false) super || method.to_s.start_with?('cdn_') end end
Version data entries
88 entries across 88 versions & 1 rubygems