Module: CdnUrl
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/app/models/concerns/cdn_url.rb
Overview
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 original.amazon.com/account_report/id/report.xlsx
will be transposed to: 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.
Constant Summary collapse
- STYLE_S3_FILE_PATH =
Constants
':class/:attachment/:id/:style.:extension'
- STYLE_FILE_PATH =
'public/system/:class/:attachment/:id/:style.:extension'
- STYLE_S3_FILE_URL =
':s3_domain_url'
- STYLE_FILE_URL =
':rails_root/public/system/:class/:attachment/:id/:style.:extension'
Instance Method Summary collapse
- #method_missing(method, *args) ⇒ Object
- #respond_to?(method, include_private = false) ⇒ Boolean
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/app/models/concerns/cdn_url.rb', line 28 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 |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
56 57 58 |
# File 'lib/app/models/concerns/cdn_url.rb', line 56 def respond_to?(method, include_private = false) super || method.to_s.start_with?('cdn_') end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
52 53 54 |
# File 'lib/app/models/concerns/cdn_url.rb', line 52 def respond_to_missing?(method_name, include_private = false) super || method_name.to_s.start_with?('cdn_') end |