class AssetSync::Config

Attributes

additional_local_file_paths_procs[R]

This is a proc to get additional local files paths Since this is a proc it won't be able to be configured by a YAML file

always_upload[RW]
aws_access_key_id[RW]

Amazon AWS

aws_acl[RW]
aws_iam_roles[RW]
aws_reduced_redundancy[RW]
aws_secret_access_key[RW]
aws_session_token[RW]
aws_signature_version[RW]
azure_storage_access_key[RW]
azure_storage_account_name[RW]

Azure Blob with Fog::AzureRM

b2_bucket_id[RW]
b2_key_id[RW]

Backblaze B2 with Fog::Backblaze

b2_key_token[RW]
cache_asset_regexps[RW]
cdn_distribution_id[RW]
concurrent_uploads[RW]
concurrent_uploads_max_threads[RW]
custom_headers[RW]
enabled[RW]
existing_remote_files[RW]
fail_silently[RW]
fog_directory[RW]
fog_host[RW]

Fog

fog_path_style[RW]
fog_port[RW]
fog_provider[RW]

FOG configuration

fog_public[R]
fog_region[RW]
fog_scheme[RW]
google_json_key_location[RW]
google_json_key_string[RW]
google_project[RW]
google_storage_access_key_id[RW]

Google Storage

google_storage_secret_access_key[RW]

Google Storage

gzip_compression[RW]
ignored_files[RW]
include_manifest[RW]
invalidate[RW]
log_silently[RW]
manifest[RW]
prefix[RW]
rackspace_api_key[RW]

Rackspace

rackspace_auth_url[RW]

Rackspace

rackspace_username[RW]

Rackspace

remote_file_list_cache_file_path[RW]
run_on_precompile[RW]

Public Class Methods

new() click to toggle source
# File lib/asset_sync/config.rb, line 91
def initialize
  self.fog_region = nil
  self.fog_public = true
  self.existing_remote_files = 'keep'
  self.gzip_compression = false
  self.manifest = false
  self.fail_silently = false
  self.log_silently = true
  self.always_upload = []
  self.ignored_files = []
  self.custom_headers = {}
  self.enabled = true
  self.run_on_precompile = true
  self.cdn_distribution_id = nil
  self.invalidate = []
  self.cache_asset_regexps = []
  self.include_manifest = false
  self.concurrent_uploads = false
  self.concurrent_uploads_max_threads = 10
  self.remote_file_list_cache_file_path = nil
  @additional_local_file_paths_procs = []

  load_yml! if defined?(::Rails) && yml_exists?
end

Public Instance Methods

add_local_file_paths(&block) click to toggle source

@api

# File lib/asset_sync/config.rb, line 342
def add_local_file_paths(&block)
  @additional_local_file_paths_procs =
    additional_local_file_paths_procs + [block]
end
additional_local_file_paths() click to toggle source

@api private

This is to be called in Storage
Not to be called by user
# File lib/asset_sync/config.rb, line 350
def additional_local_file_paths
  return [] if additional_local_file_paths_procs.empty?

  # Using `Array()` to ensure it works when single value is returned
  additional_local_file_paths_procs.each_with_object([]) do |proc, paths|
    paths.concat(Array(proc.call))
  end
end
assets_prefix() click to toggle source
# File lib/asset_sync/config.rb, line 194
def assets_prefix
  # Fix for Issue #38 when Rails.config.assets.prefix starts with a slash
  self.prefix || ::Rails.application.config.assets.prefix.sub(/^\//, '')
end
aws?() click to toggle source
# File lib/asset_sync/config.rb, line 130
def aws?
  fog_provider =~ /aws/i
end
aws_iam?() click to toggle source
# File lib/asset_sync/config.rb, line 138
def aws_iam?
  aws_iam_roles == true
end
aws_rrs?() click to toggle source
# File lib/asset_sync/config.rb, line 134
def aws_rrs?
  aws_reduced_redundancy == true
end
azure_rm?() click to toggle source
# File lib/asset_sync/config.rb, line 170
def azure_rm?
  fog_provider =~ /azurerm/i
end
backblaze?() click to toggle source
# File lib/asset_sync/config.rb, line 174
def backblaze?
  fog_provider =~ /backblaze/i
end
cache_asset_regexp=(cache_asset_regexp) click to toggle source
# File lib/asset_sync/config.rb, line 178
def cache_asset_regexp=(cache_asset_regexp)
  self.cache_asset_regexps = [cache_asset_regexp]
end
enabled?() click to toggle source
# File lib/asset_sync/config.rb, line 150
def enabled?
  enabled == true
end
existing_remote_files?() click to toggle source
# File lib/asset_sync/config.rb, line 126
def existing_remote_files?
  ['keep', 'ignore'].include?(self.existing_remote_files)
end
fail_silently?() click to toggle source
# File lib/asset_sync/config.rb, line 142
def fail_silently?
  fail_silently || !enabled?
end
file_ext_to_mime_type_overrides() click to toggle source

@api

# File lib/asset_sync/config.rb, line 360
def file_ext_to_mime_type_overrides
  @file_ext_to_mime_type_overrides ||= FileExtToMimeTypeOverrides.new
end
fog_options() click to toggle source
# File lib/asset_sync/config.rb, line 281
def fog_options
  options = { :provider => fog_provider }
  if aws?
    if aws_iam?
      options.merge!({
        :use_iam_profile => true
      })
    else
      options.merge!({
        :aws_access_key_id => aws_access_key_id,
        :aws_secret_access_key => aws_secret_access_key
      })
      options.merge!({:aws_session_token => aws_session_token}) if aws_session_token
    end
    options.merge!({:host => fog_host}) if fog_host
    options.merge!({:port => fog_port}) if fog_port
    options.merge!({:scheme => fog_scheme}) if fog_scheme
    options.merge!({:aws_signature_version => aws_signature_version}) if aws_signature_version
    options.merge!({:path_style => fog_path_style}) if fog_path_style
    options.merge!({:region => fog_region}) if fog_region
  elsif rackspace?
    options.merge!({
      :rackspace_username => rackspace_username,
      :rackspace_api_key => rackspace_api_key
    })
    options.merge!({ :rackspace_region => fog_region }) if fog_region
    options.merge!({ :rackspace_auth_url => rackspace_auth_url }) if rackspace_auth_url
  elsif google?
    if google_json_key_location
      options.merge!({:google_json_key_location => google_json_key_location, :google_project => google_project})
    elsif google_json_key_string
      options.merge!({:google_json_key_string => google_json_key_string, :google_project => google_project})
    else
      options.merge!({
        :google_storage_secret_access_key => google_storage_secret_access_key,
        :google_storage_access_key_id => google_storage_access_key_id
      })
    end
    options.merge!({:region => fog_region}) if fog_region
  elsif azure_rm?
    require 'fog/azurerm'
    options.merge!({
      :azure_storage_account_name => azure_storage_account_name,
      :azure_storage_access_key   => azure_storage_access_key,
    })
    options.merge!({:environment => fog_region}) if fog_region
  elsif backblaze?
    require 'fog/backblaze'
    options.merge!({
      :b2_key_id      => b2_key_id,
      :b2_key_token   => b2_key_token,
      :b2_bucket_id   => b2_bucket_id,
    })
  else
    raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
  end

  options
end
fog_public=(new_val) click to toggle source
# File lib/asset_sync/config.rb, line 364
def fog_public=(new_val)
  @fog_public = FogPublicValue.new(new_val)
end
google?() click to toggle source
# File lib/asset_sync/config.rb, line 158
def google?
  fog_provider =~ /google/i
end
google_interop?() click to toggle source
# File lib/asset_sync/config.rb, line 162
def google_interop?
  google? && google_json_key_location.nil? && google_json_key_string.nil?
end
google_service_account?() click to toggle source
# File lib/asset_sync/config.rb, line 166
def google_service_account?
  google? && (google_json_key_location || google_json_key_string)
end
gzip?() click to toggle source
# File lib/asset_sync/config.rb, line 122
def gzip?
  self.gzip_compression
end
load_yml!() click to toggle source
# File lib/asset_sync/config.rb, line 216
def load_yml!
  self.enabled                = yml["enabled"] if yml.has_key?('enabled')
  self.fog_provider           = yml["fog_provider"]
  self.fog_host               = yml["fog_host"]
  self.fog_port               = yml["fog_port"]
  self.fog_directory          = yml["fog_directory"]
  self.fog_region             = yml["fog_region"]
  self.fog_public             = yml["fog_public"] if yml.has_key?("fog_public")
  self.fog_path_style         = yml["fog_path_style"]
  self.fog_scheme             = yml["fog_scheme"]
  self.aws_access_key_id      = yml["aws_access_key_id"]
  self.aws_secret_access_key  = yml["aws_secret_access_key"]
  self.aws_session_token      = yml["aws_session_token"] if yml.has_key?("aws_session_token")
  self.aws_reduced_redundancy = yml["aws_reduced_redundancy"]
  self.aws_iam_roles          = yml["aws_iam_roles"]
  self.aws_signature_version  = yml["aws_signature_version"]
  self.aws_acl                = yml["aws_acl"]
  self.rackspace_username     = yml["rackspace_username"]
  self.rackspace_auth_url     = yml["rackspace_auth_url"] if yml.has_key?("rackspace_auth_url")
  self.rackspace_api_key      = yml["rackspace_api_key"]
  self.google_json_key_location = yml["google_json_key_location"] if yml.has_key?("google_json_key_location")
  self.google_project = yml["google_project"] if yml.has_key?("google_project")
  self.google_storage_secret_access_key = yml["google_storage_secret_access_key"] if yml.has_key?("google_storage_secret_access_key")
  self.google_storage_access_key_id     = yml["google_storage_access_key_id"] if yml.has_key?("google_storage_access_key_id")
  self.google_json_key_string           = yml["google_json_key_string"] if yml.has_key?("google_json_key_string")
  self.existing_remote_files  = yml["existing_remote_files"] if yml.has_key?("existing_remote_files")
  self.gzip_compression       = yml["gzip_compression"] if yml.has_key?("gzip_compression")
  self.manifest               = yml["manifest"] if yml.has_key?("manifest")
  self.fail_silently          = yml["fail_silently"] if yml.has_key?("fail_silently")
  self.log_silently           = yml["log_silently"] if yml.has_key?("log_silently")
  self.always_upload          = yml["always_upload"] if yml.has_key?("always_upload")
  self.ignored_files          = yml["ignored_files"] if yml.has_key?("ignored_files")
  self.custom_headers         = yml["custom_headers"] if yml.has_key?("custom_headers")
  self.run_on_precompile      = yml["run_on_precompile"] if yml.has_key?("run_on_precompile")
  self.invalidate             = yml["invalidate"] if yml.has_key?("invalidate")
  self.cdn_distribution_id    = yml['cdn_distribution_id'] if yml.has_key?("cdn_distribution_id")
  self.cache_asset_regexps    = yml['cache_asset_regexps'] if yml.has_key?("cache_asset_regexps")
  self.include_manifest       = yml['include_manifest'] if yml.has_key?("include_manifest")
  self.concurrent_uploads     = yml['concurrent_uploads'] if yml.has_key?('concurrent_uploads')
  self.concurrent_uploads_max_threads = yml['concurrent_uploads_max_threads'] if yml.has_key?('concurrent_uploads_max_threads')
  self.remote_file_list_cache_file_path = yml['remote_file_list_cache_file_path'] if yml.has_key?('remote_file_list_cache_file_path')

  self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
  self.azure_storage_access_key   = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")

  self.b2_key_id      = yml['b2_key_id']    if yml.has_key?("b2_key_id")
  self.b2_key_token   = yml['b2_key_token'] if yml.has_key?("b2_key_token")
  self.b2_bucket_id   = yml['b2_bucket_id'] if yml.has_key?("b2_bucket_id")

  # TODO deprecate the other old style config settings. FML.
  self.aws_access_key_id      = yml["aws_access_key"] if yml.has_key?("aws_access_key")
  self.aws_secret_access_key  = yml["aws_access_secret"] if yml.has_key?("aws_access_secret")
  self.fog_directory          = yml["aws_bucket"] if yml.has_key?("aws_bucket")
  self.fog_region             = yml["aws_region"] if yml.has_key?("aws_region")

  # TODO deprecate old style config settings
  self.aws_access_key_id      = yml["access_key_id"] if yml.has_key?("access_key_id")
  self.aws_secret_access_key  = yml["secret_access_key"] if yml.has_key?("secret_access_key")
  self.fog_directory          = yml["bucket"] if yml.has_key?("bucket")
  self.fog_region             = yml["region"] if yml.has_key?("region")

  self.public_path            = yml["public_path"] if yml.has_key?("public_path")
end
log_silently?() click to toggle source
# File lib/asset_sync/config.rb, line 146
def log_silently?
  !!self.log_silently
end
manifest_path() click to toggle source
# File lib/asset_sync/config.rb, line 116
def manifest_path
  directory =
    ::Rails.application.config.assets.manifest || default_manifest_directory
  File.join(directory, "manifest.yml")
end
public_path() click to toggle source
# File lib/asset_sync/config.rb, line 199
def public_path
  @public_path || ::Rails.public_path
end
public_path=(path) click to toggle source
# File lib/asset_sync/config.rb, line 203
def public_path=(path)
  # Generate absolute path even when relative path passed in
  # Required for generating relative sprockets manifest path
  pathname = Pathname(path)
  @public_path = if pathname.absolute?
    pathname
  elsif defined?(::Rails.root)
    ::Rails.root.join(pathname)
  else
    Pathname(::Dir.pwd).join(pathname)
  end
end
rackspace?() click to toggle source
# File lib/asset_sync/config.rb, line 154
def rackspace?
  fog_provider =~ /rackspace/i
end
yml() click to toggle source
# File lib/asset_sync/config.rb, line 186
def yml
  @yml ||= ::YAML.load(::ERB.new(IO.read(yml_path)).result)[::Rails.env] || {}
end
yml_exists?() click to toggle source
# File lib/asset_sync/config.rb, line 182
def yml_exists?
  defined?(::Rails.root) ? File.exist?(self.yml_path) : false
end
yml_path() click to toggle source
# File lib/asset_sync/config.rb, line 190
def yml_path
  ::Rails.root.join("config", "asset_sync.yml").to_s
end

Private Instance Methods

default_manifest_directory() click to toggle source
# File lib/asset_sync/config.rb, line 374
def default_manifest_directory
  File.join(::Rails.public_path, assets_prefix)
end