Class: Middleman::S3Sync::Options
- Inherits:
-
Object
- Object
- Middleman::S3Sync::Options
show all
- Defined in:
- lib/middleman/s3_sync/options.rb
Defined Under Namespace
Classes: BrowserCachePolicy
Constant Summary
collapse
- OPTIONS =
[
:prefix,
:http_prefix,
:acl,
:bucket,
:region,
:aws_access_key_id,
:aws_secret_access_key,
:after_build,
:delete,
:encryption,
:existing_remote_file,
:build_dir,
:force,
:prefer_gzip,
:reduced_redundancy_storage,
:path_style,
:version_bucket,
:verbose,
:content_types
]
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Options.
27
28
29
30
|
# File 'lib/middleman/s3_sync/options.rb', line 27
def initialize
self.read_config
end
|
Instance Method Details
#acl ⇒ Object
32
33
34
|
# File 'lib/middleman/s3_sync/options.rb', line 32
def acl
@acl || 'public-read'
end
|
#add_caching_policy(content_type, options) ⇒ Object
36
37
38
|
# File 'lib/middleman/s3_sync/options.rb', line 36
def add_caching_policy(content_type, options)
caching_policies[content_type.to_s] = BrowserCachePolicy.new(options)
end
|
#after_build ⇒ Object
76
77
78
|
# File 'lib/middleman/s3_sync/options.rb', line 76
def after_build
@after_build.nil? ? false : @after_build
end
|
#aws_access_key_id ⇒ Object
56
57
58
|
# File 'lib/middleman/s3_sync/options.rb', line 56
def aws_access_key_id
@aws_access_key_id || ENV['AWS_ACCESS_KEY_ID']
end
|
#aws_access_key_id=(aws_access_key_id) ⇒ Object
52
53
54
|
# File 'lib/middleman/s3_sync/options.rb', line 52
def aws_access_key_id=(aws_access_key_id)
@aws_access_key_id = aws_access_key_id if aws_access_key_id
end
|
#aws_secret_access_key ⇒ Object
64
65
66
|
# File 'lib/middleman/s3_sync/options.rb', line 64
def aws_secret_access_key
@aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY']
end
|
#aws_secret_access_key=(aws_secret_access_key) ⇒ Object
60
61
62
|
# File 'lib/middleman/s3_sync/options.rb', line 60
def aws_secret_access_key=(aws_secret_access_key)
@aws_secret_access_key = aws_secret_access_key if aws_secret_access_key
end
|
#caching_policies ⇒ Object
48
49
50
|
# File 'lib/middleman/s3_sync/options.rb', line 48
def caching_policies
@caching_policies ||= Map.new
end
|
#caching_policy_for(content_type) ⇒ Object
40
41
42
|
# File 'lib/middleman/s3_sync/options.rb', line 40
def caching_policy_for(content_type)
caching_policies.fetch(content_type.to_s, caching_policies[:default])
end
|
#content_types ⇒ Object
105
106
107
|
# File 'lib/middleman/s3_sync/options.rb', line 105
def content_types
@content_types || {}
end
|
#default_caching_policy ⇒ Object
44
45
46
|
# File 'lib/middleman/s3_sync/options.rb', line 44
def default_caching_policy
caching_policies[:default]
end
|
#delete ⇒ Object
72
73
74
|
# File 'lib/middleman/s3_sync/options.rb', line 72
def delete
@delete.nil? ? true : @delete
end
|
#encryption ⇒ Object
68
69
70
|
# File 'lib/middleman/s3_sync/options.rb', line 68
def encryption
@encryption.nil? ? false : @encryption
end
|
#path_style ⇒ Object
84
85
86
|
# File 'lib/middleman/s3_sync/options.rb', line 84
def path_style
(@path_style.nil? ? true : @path_style)
end
|
#prefer_gzip ⇒ Object
80
81
82
|
# File 'lib/middleman/s3_sync/options.rb', line 80
def prefer_gzip
(@prefer_gzip.nil? ? true : @prefer_gzip)
end
|
#prefix ⇒ Object
97
98
99
|
# File 'lib/middleman/s3_sync/options.rb', line 97
def prefix
@prefix.blank? ? "" : "#{@prefix}/"
end
|
#prefix=(prefix) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/middleman/s3_sync/options.rb', line 88
def prefix=(prefix)
http_prefix = @http_prefix ? @http_prefix.sub(%r{^/}, "") : ""
if http_prefix.split("/").first == prefix
@prefix = ""
else
@prefix = prefix
end
end
|
#read_config(io = nil) ⇒ void
This method returns an undefined value.
Read config options from an IO stream and set them on ‘self`. Defaults to reading from the `.s3_sync` file in the MM project root if it exists.
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/middleman/s3_sync/options.rb', line 114
def read_config(io = nil)
unless io
root_path = ::Middleman::Application.root
config_file_path = File.join(root_path, ".s3_sync")
return unless File.exists?(config_file_path)
io = File.open(config_file_path, "r")
end
config = YAML.load(io).symbolize_keys
OPTIONS.each do |config_option|
self.send("#{config_option}=".to_sym, config[config_option]) if config[config_option]
end
end
|
#version_bucket ⇒ Object
101
102
103
|
# File 'lib/middleman/s3_sync/options.rb', line 101
def version_bucket
@version_bucket.nil? ? false : @version_bucket
end
|