Class: AssetSync::Config

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/asset_sync/config.rb

Defined Under Namespace

Classes: FileExtToMimeTypeOverrides, FogPublicValue, Invalid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/asset_sync/config.rb', line 93

def initialize
  self.fog_region = nil
  self.fog_public = true
  self.existing_remote_files = 'keep'
  self.compression = nil
  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
  self.remote_file_list_remote_path = nil
  @additional_local_file_paths_procs = []

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

Instance Attribute Details

#always_uploadObject

Returns the value of attribute always_upload.



18
19
20
# File 'lib/asset_sync/config.rb', line 18

def always_upload
  @always_upload
end

#aws_access_key_idObject

Amazon AWS



41
42
43
# File 'lib/asset_sync/config.rb', line 41

def aws_access_key_id
  @aws_access_key_id
end

#aws_aclObject

Returns the value of attribute aws_acl.



47
48
49
# File 'lib/asset_sync/config.rb', line 47

def aws_acl
  @aws_acl
end

#aws_iam_rolesObject

Returns the value of attribute aws_iam_roles.



45
46
47
# File 'lib/asset_sync/config.rb', line 45

def aws_iam_roles
  @aws_iam_roles
end

#aws_reduced_redundancyObject

Returns the value of attribute aws_reduced_redundancy.



44
45
46
# File 'lib/asset_sync/config.rb', line 44

def aws_reduced_redundancy
  @aws_reduced_redundancy
end

#aws_secret_access_keyObject

Returns the value of attribute aws_secret_access_key.



42
43
44
# File 'lib/asset_sync/config.rb', line 42

def aws_secret_access_key
  @aws_secret_access_key
end

#aws_session_tokenObject

Returns the value of attribute aws_session_token.



43
44
45
# File 'lib/asset_sync/config.rb', line 43

def aws_session_token
  @aws_session_token
end

#aws_signature_versionObject

Returns the value of attribute aws_signature_version.



46
47
48
# File 'lib/asset_sync/config.rb', line 46

def aws_signature_version
  @aws_signature_version
end

#azure_storage_access_keyObject

Returns the value of attribute azure_storage_access_key.



67
68
69
# File 'lib/asset_sync/config.rb', line 67

def azure_storage_access_key
  @azure_storage_access_key
end

#azure_storage_account_nameObject

Azure Blob with Fog::AzureRM



66
67
68
# File 'lib/asset_sync/config.rb', line 66

def 
  @azure_storage_account_name
end

#b2_bucket_idObject

Returns the value of attribute b2_bucket_id.



72
73
74
# File 'lib/asset_sync/config.rb', line 72

def b2_bucket_id
  @b2_bucket_id
end

#b2_key_idObject

Backblaze B2 with Fog::Backblaze



70
71
72
# File 'lib/asset_sync/config.rb', line 70

def b2_key_id
  @b2_key_id
end

#b2_key_tokenObject

Returns the value of attribute b2_key_token.



71
72
73
# File 'lib/asset_sync/config.rb', line 71

def b2_key_token
  @b2_key_token
end

#cache_asset_regexpsObject

Returns the value of attribute cache_asset_regexps.



26
27
28
# File 'lib/asset_sync/config.rb', line 26

def cache_asset_regexps
  @cache_asset_regexps
end

#cdn_distribution_idObject

Returns the value of attribute cdn_distribution_id.



25
26
27
# File 'lib/asset_sync/config.rb', line 25

def cdn_distribution_id
  @cdn_distribution_id
end

#compressionObject

Returns the value of attribute compression.



14
15
16
# File 'lib/asset_sync/config.rb', line 14

def compression
  @compression
end

#concurrent_uploadsObject

Returns the value of attribute concurrent_uploads.



28
29
30
# File 'lib/asset_sync/config.rb', line 28

def concurrent_uploads
  @concurrent_uploads
end

#concurrent_uploads_max_threadsObject

Returns the value of attribute concurrent_uploads_max_threads.



29
30
31
# File 'lib/asset_sync/config.rb', line 29

def concurrent_uploads_max_threads
  @concurrent_uploads_max_threads
end

#custom_headersObject

Returns the value of attribute custom_headers.



22
23
24
# File 'lib/asset_sync/config.rb', line 22

def custom_headers
  @custom_headers
end

#enabledObject

Returns the value of attribute enabled.



21
22
23
# File 'lib/asset_sync/config.rb', line 21

def enabled
  @enabled
end

#existing_remote_filesObject

AssetSync



13
14
15
# File 'lib/asset_sync/config.rb', line 13

def existing_remote_files
  @existing_remote_files
end

#fail_silentlyObject

Returns the value of attribute fail_silently.



16
17
18
# File 'lib/asset_sync/config.rb', line 16

def fail_silently
  @fail_silently
end

#fog_directoryObject

e.g. ‘the-bucket-name’



35
36
37
# File 'lib/asset_sync/config.rb', line 35

def fog_directory
  @fog_directory
end

#fog_hostObject

Fog



50
51
52
# File 'lib/asset_sync/config.rb', line 50

def fog_host
  @fog_host
end

#fog_optionsObject

e.g. { enable_signature_v4_streaming: true }



38
39
40
# File 'lib/asset_sync/config.rb', line 38

def fog_options
  @fog_options
end

#fog_path_styleObject

e.g. true



52
53
54
# File 'lib/asset_sync/config.rb', line 52

def fog_path_style
  @fog_path_style
end

#fog_portObject

e.g. ‘9000’



51
52
53
# File 'lib/asset_sync/config.rb', line 51

def fog_port
  @fog_port
end

#fog_providerObject

FOG configuration



34
35
36
# File 'lib/asset_sync/config.rb', line 34

def fog_provider
  @fog_provider
end

#fog_publicObject

e.g. true, false, “default”



37
38
39
# File 'lib/asset_sync/config.rb', line 37

def fog_public
  @fog_public
end

#fog_regionObject

e.g. ‘eu-west-1’



36
37
38
# File 'lib/asset_sync/config.rb', line 36

def fog_region
  @fog_region
end

#fog_schemeObject

e.g. ‘http’



53
54
55
# File 'lib/asset_sync/config.rb', line 53

def fog_scheme
  @fog_scheme
end

#google_authObject

Google Storage



59
60
61
# File 'lib/asset_sync/config.rb', line 59

def google_auth
  @google_auth
end

#google_json_key_locationObject

when using service accounts



61
62
63
# File 'lib/asset_sync/config.rb', line 61

def google_json_key_location
  @google_json_key_location
end

#google_json_key_stringObject

when using service accounts



62
63
64
# File 'lib/asset_sync/config.rb', line 62

def google_json_key_string
  @google_json_key_string
end

#google_projectObject

when using service accounts



63
64
65
# File 'lib/asset_sync/config.rb', line 63

def google_project
  @google_project
end

#google_storage_access_key_idObject

when using S3 interop



60
61
62
# File 'lib/asset_sync/config.rb', line 60

def google_storage_access_key_id
  @google_storage_access_key_id
end

#google_storage_secret_access_keyObject

when using S3 interop



60
61
62
# File 'lib/asset_sync/config.rb', line 60

def google_storage_secret_access_key
  @google_storage_secret_access_key
end

#ignored_filesObject

Returns the value of attribute ignored_files.



19
20
21
# File 'lib/asset_sync/config.rb', line 19

def ignored_files
  @ignored_files
end

#include_manifestObject

Returns the value of attribute include_manifest.



27
28
29
# File 'lib/asset_sync/config.rb', line 27

def include_manifest
  @include_manifest
end

#invalidateObject

Returns the value of attribute invalidate.



24
25
26
# File 'lib/asset_sync/config.rb', line 24

def invalidate
  @invalidate
end

#log_silentlyObject

Returns the value of attribute log_silently.



17
18
19
# File 'lib/asset_sync/config.rb', line 17

def log_silently
  @log_silently
end

#manifestObject

Returns the value of attribute manifest.



15
16
17
# File 'lib/asset_sync/config.rb', line 15

def manifest
  @manifest
end

#prefixObject

Returns the value of attribute prefix.



20
21
22
# File 'lib/asset_sync/config.rb', line 20

def prefix
  @prefix
end

#rackspace_api_keyObject

Rackspace



56
57
58
# File 'lib/asset_sync/config.rb', line 56

def rackspace_api_key
  @rackspace_api_key
end

#rackspace_auth_urlObject

Rackspace



56
57
58
# File 'lib/asset_sync/config.rb', line 56

def rackspace_auth_url
  @rackspace_auth_url
end

#rackspace_usernameObject

Rackspace



56
57
58
# File 'lib/asset_sync/config.rb', line 56

def rackspace_username
  @rackspace_username
end

#remote_file_list_cache_file_pathObject

Returns the value of attribute remote_file_list_cache_file_path.



30
31
32
# File 'lib/asset_sync/config.rb', line 30

def remote_file_list_cache_file_path
  @remote_file_list_cache_file_path
end

#remote_file_list_remote_pathObject

Returns the value of attribute remote_file_list_remote_path.



31
32
33
# File 'lib/asset_sync/config.rb', line 31

def remote_file_list_remote_path
  @remote_file_list_remote_path
end

#run_on_precompileObject

Returns the value of attribute run_on_precompile.



23
24
25
# File 'lib/asset_sync/config.rb', line 23

def run_on_precompile
  @run_on_precompile
end

Instance Method Details

#add_local_file_paths(&block) ⇒ Object



359
360
361
362
# File 'lib/asset_sync/config.rb', line 359

def add_local_file_paths(&block)
  @additional_local_file_paths_procs =
    additional_local_file_paths_procs + [block]
end

#additional_local_file_pathsObject



367
368
369
370
371
372
373
374
# File 'lib/asset_sync/config.rb', line 367

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_prefixObject



205
206
207
208
# File 'lib/asset_sync/config.rb', line 205

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?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/asset_sync/config.rb', line 141

def aws?
  fog_provider =~ /aws/i
end

#aws_iam?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/asset_sync/config.rb', line 149

def aws_iam?
  aws_iam_roles == true
end

#aws_rrs?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/asset_sync/config.rb', line 145

def aws_rrs?
  aws_reduced_redundancy == true
end

#azure_rm?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/asset_sync/config.rb', line 181

def azure_rm?
  fog_provider =~ /azurerm/i
end

#backblaze?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/asset_sync/config.rb', line 185

def backblaze?
  fog_provider =~ /backblaze/i
end

#cache_asset_regexp=(cache_asset_regexp) ⇒ Object



189
190
191
# File 'lib/asset_sync/config.rb', line 189

def cache_asset_regexp=(cache_asset_regexp)
  self.cache_asset_regexps = [cache_asset_regexp]
end

#enabled?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/asset_sync/config.rb', line 161

def enabled?
  enabled == true
end

#existing_remote_files?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/asset_sync/config.rb', line 137

def existing_remote_files?
  ['keep', 'ignore'].include?(self.existing_remote_files)
end

#fail_silently?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/asset_sync/config.rb', line 153

def fail_silently?
  fail_silently || !enabled?
end

#file_ext_to_mime_type_overridesObject



377
378
379
# File 'lib/asset_sync/config.rb', line 377

def file_ext_to_mime_type_overrides
  @file_ext_to_mime_type_overrides ||= FileExtToMimeTypeOverrides.new
end

#google?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/asset_sync/config.rb', line 169

def google?
  fog_provider =~ /google/i
end

#google_interop?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/asset_sync/config.rb', line 173

def google_interop?
  google? && google_auth.nil? && google_json_key_location.nil? && google_json_key_string.nil?
end

#google_service_account?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/asset_sync/config.rb', line 177

def google_service_account?
  google? && (google_json_key_location || google_json_key_string)
end

#gzip_compression=(bool) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/asset_sync/config.rb', line 129

def gzip_compression= bool
  if bool
    self.compression = 'gz'
  else
    self.compression = nil
  end
end

#load_yml!Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/asset_sync/config.rb', line 227

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.compression            = 'gz' if yml.has_key?("gzip_compression")
  self.compression            = yml["compression"] if yml.has_key?("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.prefix                 = yml["prefix"] if yml.has_key?("prefix")
  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.remote_file_list_remote_path = yml['remote_file_list_remote_path'] if yml.has_key?('remote_file_list_remote_path')

  self. = 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?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/asset_sync/config.rb', line 157

def log_silently?
  !!self.log_silently
end

#manifest_pathObject



119
120
121
122
123
124
125
126
127
# File 'lib/asset_sync/config.rb', line 119

def manifest_path
  if defined?(ActionView) && ActionView::Base.respond_to?(:assets_manifest)
    ::Rails.application.config.assets.manifest
  else
    directory =
    ::Rails.application.config.assets.manifest || default_manifest_directory
    File.join(directory, "manifest.yml")
  end
end

#public_pathObject



210
211
212
# File 'lib/asset_sync/config.rb', line 210

def public_path
  @public_path || ::Rails.public_path
end

#public_path=(path) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/asset_sync/config.rb', line 214

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?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/asset_sync/config.rb', line 165

def rackspace?
  fog_provider =~ /rackspace/i
end

#ymlObject



197
198
199
# File 'lib/asset_sync/config.rb', line 197

def yml
  @yml ||= ::AssetSync.load_yaml(::ERB.new(IO.read(yml_path)).result)[::Rails.env] || {}
end

#yml_exists?Boolean

Returns:

  • (Boolean)


193
194
195
# File 'lib/asset_sync/config.rb', line 193

def yml_exists?
  defined?(::Rails.root) ? File.exist?(self.yml_path) : false
end

#yml_pathObject



201
202
203
# File 'lib/asset_sync/config.rb', line 201

def yml_path
  ::Rails.root.join("config", "asset_sync.yml").to_s
end