Class: AssetSync::Config
- Inherits:
-
Object
- Object
- AssetSync::Config
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/asset_sync/config.rb
Defined Under Namespace
Classes: FileExtToMimeTypeOverrides, FogPublicValue, Invalid
Instance Attribute Summary collapse
-
#always_upload ⇒ Object
Returns the value of attribute always_upload.
-
#aws_access_key_id ⇒ Object
Amazon AWS.
-
#aws_iam_roles ⇒ Object
Amazon AWS.
-
#aws_reduced_redundancy ⇒ Object
Amazon AWS.
-
#aws_secret_access_key ⇒ Object
Amazon AWS.
-
#aws_signature_version ⇒ Object
Amazon AWS.
-
#azure_storage_access_key ⇒ Object
Returns the value of attribute azure_storage_access_key.
-
#azure_storage_account_name ⇒ Object
Azure Blob with Fog::AzureRM.
-
#cache_asset_regexps ⇒ Object
Returns the value of attribute cache_asset_regexps.
-
#cdn_distribution_id ⇒ Object
Returns the value of attribute cdn_distribution_id.
-
#custom_headers ⇒ Object
Returns the value of attribute custom_headers.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#existing_remote_files ⇒ Object
AssetSync.
-
#fail_silently ⇒ Object
Returns the value of attribute fail_silently.
-
#fog_directory ⇒ Object
e.g.
-
#fog_host ⇒ Object
e.g.
-
#fog_path_style ⇒ Object
e.g.
-
#fog_port ⇒ Object
e.g.
-
#fog_provider ⇒ Object
FOG configuration.
-
#fog_public ⇒ Object
e.g.
-
#fog_region ⇒ Object
e.g.
-
#fog_scheme ⇒ Object
e.g.
-
#google_json_key_location ⇒ Object
when using service accounts.
-
#google_project ⇒ Object
when using service accounts.
-
#google_storage_access_key_id ⇒ Object
Google Storage.
-
#google_storage_secret_access_key ⇒ Object
Google Storage.
-
#gzip_compression ⇒ Object
Returns the value of attribute gzip_compression.
-
#ignored_files ⇒ Object
Returns the value of attribute ignored_files.
-
#include_manifest ⇒ Object
Returns the value of attribute include_manifest.
-
#invalidate ⇒ Object
Returns the value of attribute invalidate.
-
#log_silently ⇒ Object
Returns the value of attribute log_silently.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
- #public_path ⇒ Object
-
#rackspace_api_key ⇒ Object
Rackspace.
-
#rackspace_auth_url ⇒ Object
Rackspace.
-
#rackspace_username ⇒ Object
Rackspace.
-
#run_on_precompile ⇒ Object
Returns the value of attribute run_on_precompile.
Instance Method Summary collapse
- #add_local_file_paths(&block) ⇒ Object
- #additional_local_file_paths ⇒ Object
- #assets_prefix ⇒ Object
- #aws? ⇒ Boolean
- #aws_iam? ⇒ Boolean
- #aws_rrs? ⇒ Boolean
- #azure_rm? ⇒ Boolean
- #cache_asset_regexp=(cache_asset_regexp) ⇒ Object
- #enabled? ⇒ Boolean
- #existing_remote_files? ⇒ Boolean
- #fail_silently? ⇒ Boolean
- #file_ext_to_mime_type_overrides ⇒ Object
- #fog_options ⇒ Object
- #google? ⇒ Boolean
- #google_interop? ⇒ Boolean
- #google_service_account? ⇒ Boolean
- #gzip? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_yml! ⇒ Object
- #log_silently? ⇒ Boolean
- #manifest_path ⇒ Object
- #rackspace? ⇒ Boolean
- #yml ⇒ Object
- #yml_exists? ⇒ Boolean
- #yml_path ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/asset_sync/config.rb', line 70 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 @additional_local_file_paths_procs = [] load_yml! if defined?(::Rails) && yml_exists? end |
Instance Attribute Details
#always_upload ⇒ Object
Returns the value of attribute always_upload.
19 20 21 |
# File 'lib/asset_sync/config.rb', line 19 def always_upload @always_upload end |
#aws_access_key_id ⇒ Object
Amazon AWS
38 39 40 |
# File 'lib/asset_sync/config.rb', line 38 def aws_access_key_id @aws_access_key_id end |
#aws_iam_roles ⇒ Object
Amazon AWS
38 39 40 |
# File 'lib/asset_sync/config.rb', line 38 def aws_iam_roles @aws_iam_roles end |
#aws_reduced_redundancy ⇒ Object
Amazon AWS
38 39 40 |
# File 'lib/asset_sync/config.rb', line 38 def aws_reduced_redundancy @aws_reduced_redundancy end |
#aws_secret_access_key ⇒ Object
Amazon AWS
38 39 40 |
# File 'lib/asset_sync/config.rb', line 38 def aws_secret_access_key @aws_secret_access_key end |
#aws_signature_version ⇒ Object
Amazon AWS
38 39 40 |
# File 'lib/asset_sync/config.rb', line 38 def aws_signature_version @aws_signature_version end |
#azure_storage_access_key ⇒ Object
Returns the value of attribute azure_storage_access_key.
54 55 56 |
# File 'lib/asset_sync/config.rb', line 54 def azure_storage_access_key @azure_storage_access_key end |
#azure_storage_account_name ⇒ Object
Azure Blob with Fog::AzureRM
53 54 55 |
# File 'lib/asset_sync/config.rb', line 53 def azure_storage_account_name @azure_storage_account_name end |
#cache_asset_regexps ⇒ Object
Returns the value of attribute cache_asset_regexps.
27 28 29 |
# File 'lib/asset_sync/config.rb', line 27 def cache_asset_regexps @cache_asset_regexps end |
#cdn_distribution_id ⇒ Object
Returns the value of attribute cdn_distribution_id.
26 27 28 |
# File 'lib/asset_sync/config.rb', line 26 def cdn_distribution_id @cdn_distribution_id end |
#custom_headers ⇒ Object
Returns the value of attribute custom_headers.
23 24 25 |
# File 'lib/asset_sync/config.rb', line 23 def custom_headers @custom_headers end |
#enabled ⇒ Object
Returns the value of attribute enabled.
22 23 24 |
# File 'lib/asset_sync/config.rb', line 22 def enabled @enabled end |
#existing_remote_files ⇒ Object
AssetSync
14 15 16 |
# File 'lib/asset_sync/config.rb', line 14 def existing_remote_files @existing_remote_files end |
#fail_silently ⇒ Object
Returns the value of attribute fail_silently.
17 18 19 |
# File 'lib/asset_sync/config.rb', line 17 def fail_silently @fail_silently end |
#fog_directory ⇒ Object
e.g. ‘the-bucket-name’
33 34 35 |
# File 'lib/asset_sync/config.rb', line 33 def fog_directory @fog_directory end |
#fog_host ⇒ Object
e.g. ‘s3.amazonaws.com’
39 40 41 |
# File 'lib/asset_sync/config.rb', line 39 def fog_host @fog_host end |
#fog_path_style ⇒ Object
e.g. true
41 42 43 |
# File 'lib/asset_sync/config.rb', line 41 def fog_path_style @fog_path_style end |
#fog_port ⇒ Object
e.g. ‘9000’
40 41 42 |
# File 'lib/asset_sync/config.rb', line 40 def fog_port @fog_port end |
#fog_provider ⇒ Object
FOG configuration
32 33 34 |
# File 'lib/asset_sync/config.rb', line 32 def fog_provider @fog_provider end |
#fog_public ⇒ Object
e.g. true, false, “default”
35 36 37 |
# File 'lib/asset_sync/config.rb', line 35 def fog_public @fog_public end |
#fog_region ⇒ Object
e.g. ‘eu-west-1’
34 35 36 |
# File 'lib/asset_sync/config.rb', line 34 def fog_region @fog_region end |
#fog_scheme ⇒ Object
e.g. ‘http’
42 43 44 |
# File 'lib/asset_sync/config.rb', line 42 def fog_scheme @fog_scheme end |
#google_json_key_location ⇒ Object
when using service accounts
49 50 51 |
# File 'lib/asset_sync/config.rb', line 49 def google_json_key_location @google_json_key_location end |
#google_project ⇒ Object
when using service accounts
50 51 52 |
# File 'lib/asset_sync/config.rb', line 50 def google_project @google_project end |
#google_storage_access_key_id ⇒ Object
Google Storage
48 49 50 |
# File 'lib/asset_sync/config.rb', line 48 def google_storage_access_key_id @google_storage_access_key_id end |
#google_storage_secret_access_key ⇒ Object
Google Storage
48 49 50 |
# File 'lib/asset_sync/config.rb', line 48 def google_storage_secret_access_key @google_storage_secret_access_key end |
#gzip_compression ⇒ Object
Returns the value of attribute gzip_compression.
15 16 17 |
# File 'lib/asset_sync/config.rb', line 15 def gzip_compression @gzip_compression end |
#ignored_files ⇒ Object
Returns the value of attribute ignored_files.
20 21 22 |
# File 'lib/asset_sync/config.rb', line 20 def ignored_files @ignored_files end |
#include_manifest ⇒ Object
Returns the value of attribute include_manifest.
28 29 30 |
# File 'lib/asset_sync/config.rb', line 28 def include_manifest @include_manifest end |
#invalidate ⇒ Object
Returns the value of attribute invalidate.
25 26 27 |
# File 'lib/asset_sync/config.rb', line 25 def invalidate @invalidate end |
#log_silently ⇒ Object
Returns the value of attribute log_silently.
18 19 20 |
# File 'lib/asset_sync/config.rb', line 18 def log_silently @log_silently end |
#manifest ⇒ Object
Returns the value of attribute manifest.
16 17 18 |
# File 'lib/asset_sync/config.rb', line 16 def manifest @manifest end |
#prefix ⇒ Object
Returns the value of attribute prefix.
21 22 23 |
# File 'lib/asset_sync/config.rb', line 21 def prefix @prefix end |
#public_path ⇒ Object
171 172 173 |
# File 'lib/asset_sync/config.rb', line 171 def public_path @public_path || ::Rails.public_path end |
#rackspace_api_key ⇒ Object
Rackspace
45 46 47 |
# File 'lib/asset_sync/config.rb', line 45 def rackspace_api_key @rackspace_api_key end |
#rackspace_auth_url ⇒ Object
Rackspace
45 46 47 |
# File 'lib/asset_sync/config.rb', line 45 def rackspace_auth_url @rackspace_auth_url end |
#rackspace_username ⇒ Object
Rackspace
45 46 47 |
# File 'lib/asset_sync/config.rb', line 45 def rackspace_username @rackspace_username end |
#run_on_precompile ⇒ Object
Returns the value of attribute run_on_precompile.
24 25 26 |
# File 'lib/asset_sync/config.rb', line 24 def run_on_precompile @run_on_precompile end |
Instance Method Details
#add_local_file_paths(&block) ⇒ Object
280 281 282 283 |
# File 'lib/asset_sync/config.rb', line 280 def add_local_file_paths(&block) @additional_local_file_paths_procs = additional_local_file_paths_procs + [block] end |
#additional_local_file_paths ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'lib/asset_sync/config.rb', line 288 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 ⇒ Object
166 167 168 169 |
# File 'lib/asset_sync/config.rb', line 166 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
106 107 108 |
# File 'lib/asset_sync/config.rb', line 106 def aws? fog_provider =~ /aws/i end |
#aws_iam? ⇒ Boolean
114 115 116 |
# File 'lib/asset_sync/config.rb', line 114 def aws_iam? aws_iam_roles == true end |
#aws_rrs? ⇒ Boolean
110 111 112 |
# File 'lib/asset_sync/config.rb', line 110 def aws_rrs? aws_reduced_redundancy == true end |
#azure_rm? ⇒ Boolean
146 147 148 |
# File 'lib/asset_sync/config.rb', line 146 def azure_rm? fog_provider =~ /azurerm/i end |
#cache_asset_regexp=(cache_asset_regexp) ⇒ Object
150 151 152 |
# File 'lib/asset_sync/config.rb', line 150 def cache_asset_regexp=(cache_asset_regexp) self.cache_asset_regexps = [cache_asset_regexp] end |
#enabled? ⇒ Boolean
126 127 128 |
# File 'lib/asset_sync/config.rb', line 126 def enabled? enabled == true end |
#existing_remote_files? ⇒ Boolean
102 103 104 |
# File 'lib/asset_sync/config.rb', line 102 def existing_remote_files? ['keep', 'ignore'].include?(self.existing_remote_files) end |
#fail_silently? ⇒ Boolean
118 119 120 |
# File 'lib/asset_sync/config.rb', line 118 def fail_silently? fail_silently || !enabled? end |
#file_ext_to_mime_type_overrides ⇒ Object
298 299 300 |
# File 'lib/asset_sync/config.rb', line 298 def file_ext_to_mime_type_overrides @file_ext_to_mime_type_overrides ||= FileExtToMimeTypeOverrides.new end |
#fog_options ⇒ Object
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 |
# File 'lib/asset_sync/config.rb', line 229 def = { :provider => fog_provider } if aws? if aws_iam? .merge!({ :use_iam_profile => true }) else .merge!({ :aws_access_key_id => aws_access_key_id, :aws_secret_access_key => aws_secret_access_key }) end .merge!({:host => fog_host}) if fog_host .merge!({:port => fog_port}) if fog_port .merge!({:scheme => fog_scheme}) if fog_scheme .merge!({:aws_signature_version => aws_signature_version}) if aws_signature_version .merge!({:path_style => fog_path_style}) if fog_path_style .merge!({:region => fog_region}) if fog_region elsif rackspace? .merge!({ :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key }) .merge!({ :rackspace_region => fog_region }) if fog_region .merge!({ :rackspace_auth_url => rackspace_auth_url }) if rackspace_auth_url elsif google? if google_json_key_location .merge!({:google_json_key_location => google_json_key_location, :google_project => google_project}) else .merge!({ :google_storage_secret_access_key => google_storage_secret_access_key, :google_storage_access_key_id => google_storage_access_key_id }) end .merge!({:region => fog_region}) if fog_region elsif azure_rm? require 'fog/azurerm' .merge!({ :azure_storage_account_name => azure_storage_account_name, :azure_storage_access_key => azure_storage_access_key, }) .merge!({:environment => fog_region}) if fog_region else raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently." end end |
#google? ⇒ Boolean
134 135 136 |
# File 'lib/asset_sync/config.rb', line 134 def google? fog_provider =~ /google/i end |
#google_interop? ⇒ Boolean
138 139 140 |
# File 'lib/asset_sync/config.rb', line 138 def google_interop? google? && google_json_key_location.nil? end |
#google_service_account? ⇒ Boolean
142 143 144 |
# File 'lib/asset_sync/config.rb', line 142 def google_service_account? google? && google_json_key_location end |
#gzip? ⇒ Boolean
98 99 100 |
# File 'lib/asset_sync/config.rb', line 98 def gzip? self.gzip_compression end |
#load_yml! ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/asset_sync/config.rb', line 175 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_reduced_redundancy = yml["aws_reduced_redundancy"] self.aws_iam_roles = yml["aws_iam_roles"] self.aws_signature_version = yml["aws_signature_version"] 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.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.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.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") # 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
122 123 124 |
# File 'lib/asset_sync/config.rb', line 122 def log_silently? !!self.log_silently end |
#manifest_path ⇒ Object
92 93 94 95 96 |
# File 'lib/asset_sync/config.rb', line 92 def manifest_path directory = ::Rails.application.config.assets.manifest || default_manifest_directory File.join(directory, "manifest.yml") end |
#rackspace? ⇒ Boolean
130 131 132 |
# File 'lib/asset_sync/config.rb', line 130 def rackspace? fog_provider =~ /rackspace/i end |
#yml ⇒ Object
158 159 160 |
# File 'lib/asset_sync/config.rb', line 158 def yml @yml ||= ::YAML.load(::ERB.new(IO.read(yml_path)).result)[::Rails.env] || {} end |
#yml_exists? ⇒ Boolean
154 155 156 |
# File 'lib/asset_sync/config.rb', line 154 def yml_exists? defined?(::Rails.root) ? File.exist?(self.yml_path) : false end |
#yml_path ⇒ Object
162 163 164 |
# File 'lib/asset_sync/config.rb', line 162 def yml_path ::Rails.root.join("config", "asset_sync.yml").to_s end |