Sha256: 6d5c51a051538ffa412b841c58eafd0d823bc44024ef1d6ef1204fe9389a8ea6
Contents?: true
Size: 1.64 KB
Versions: 27
Compression:
Stored size: 1.64 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 # @abstract Catch methods started with `cdn_` and respond to those requests if there is a # matching method ending in `_url` 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
27 entries across 27 versions & 1 rubygems