Module: App47CdnUrl

Included in:
AppActiveBuild, ProductApp
Defined in:
lib/models/concerns/app47_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 internal_build will be original.amazon.com/internal_builds/id/original.ipa

will be transposed to: cnd.apazon.com/intenral_builds/id/original.ipa

To use this, first include App47::CdnUrl in your class and then when you want the URL of an object call app.cdn_file_url or ubild.cdn_file_url instead of app.file_url or build.file_url.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Handle the call to cdn_whatever



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/models/concerns/app47_cdn_url.rb', line 23

def method_missing(method, *args)
  if method.to_s.start_with? 'cdn_'
    url = send method.to_s.sub(/^cdn_/, '')
    cdn_url = SystemConfiguration.cdn_url
    unless cdn_url.blank? || url.blank?
      model_name = "#{self.class.to_s.underscore}s"
      url = "#{cdn_url}/#{model_name}/#{url.split("/#{model_name}/").last}" if url.include? "/#{model_name}/"
    end
    url
  else
    super
  end
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Look for matches on cdn_

Returns:

  • (Boolean)


47
48
49
# File 'lib/models/concerns/app47_cdn_url.rb', line 47

def respond_to?(method, include_private = false)
  super unless method.to_s.start_with? 'cdn_'
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Look for matches on cdn_

Returns:

  • (Boolean)


40
41
42
# File 'lib/models/concerns/app47_cdn_url.rb', line 40

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.start_with?('cdn_') ? true : super
end