Sha256: 6ea9e3f3076dd8a6085fba641f1006728c5a65189e164f849b228c19961581c8

Contents?: true

Size: 845 Bytes

Versions: 12

Compression:

Stored size: 845 Bytes

Contents

require 'digest'
require 'mime/types'

module Ustyle

  def self.production?
    ENV['RACK_ENV'] == 'production' || ENV['RAILS_ENV'] == 'production' || ENV['NODE_ENV'] == 'production' || false
  end

  def self.cloudfront_url path, type
    File.join "https://assets0.uswitch.com/s3/uswitch-assets-eu/ustyle/", Ustyle::VERSION, folder_by_type(type), asset_digest(path)
  end

  def self.asset_digest path
    path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
  end

  def self.mime_type_for asset
    MIME::Types.type_for( asset ).first.content_type
  end

  def self.versioned_path file
    File.join "ustyle", Ustyle::VERSION, file
  end

  def self.digest
    Digest::SHA1.hexdigest Ustyle::VERSION
  end

  def self.folder_by_type type
    case type
    when :image
      "images"
    when :font
      "fonts"
    else ""
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ustyle-1.11.1 lib/ustyle/utils.rb
ustyle-1.10.0 lib/ustyle/utils.rb
ustyle-1.8.7 lib/ustyle/utils.rb
ustyle-1.8.1 lib/ustyle/utils.rb
ustyle-1.8.0 lib/ustyle/utils.rb
ustyle-1.7.0 lib/ustyle/utils.rb
ustyle-1.6.1 lib/ustyle/utils.rb
ustyle-1.5.8 lib/ustyle/utils.rb
ustyle-1.4.1 lib/ustyle/utils.rb
ustyle-1.4.0 lib/ustyle/utils.rb
ustyle-1.3.12 lib/ustyle/utils.rb
ustyle-1.3.6 lib/ustyle/utils.rb