Class: Middleman::S3SyncExtension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::S3SyncExtension
show all
- Defined in:
- lib/middleman-s3_sync/extension.rb
Instance Method Summary
collapse
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ S3SyncExtension
Returns a new instance of S3SyncExtension.
47
48
49
|
# File 'lib/middleman-s3_sync/extension.rb', line 47
def initialize(app, options_hash = {}, &block)
super
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegate option readers and writers to the options object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/middleman-s3_sync/extension.rb', line 94
def method_missing(method, *args, &block)
method_str = method.to_s
if method_str.end_with?('=')
option_name = method_str.chomp('=').to_sym
if options.respond_to?(option_name)
options[option_name] = args.first
return args.first
end
elsif options.respond_to?(method)
return options.send(method, *args, &block)
end
super
end
|
Instance Method Details
#acl_enabled? ⇒ Boolean
85
86
87
88
89
90
91
|
# File 'lib/middleman-s3_sync/extension.rb', line 85
def acl_enabled?
acl_value = options.acl
return false if acl_value.nil? || acl_value == '' || acl_value == false
true
end
|
#after_build ⇒ Object
66
67
68
|
# File 'lib/middleman-s3_sync/extension.rb', line 66
def after_build
::Middleman::S3Sync.sync() if options.after_build
end
|
#after_configuration ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/middleman-s3_sync/extension.rb', line 51
def after_configuration
read_config
options.aws_access_key_id ||= ENV['AWS_ACCESS_KEY_ID']
options.aws_secret_access_key ||= ENV['AWS_SECRET_ACCESS_KEY']
options.aws_session_token ||= ENV['AWS_SESSION_TOKEN'] || ENV['AWS_SECURITY_TOKEN']
options.bucket ||= ENV['AWS_BUCKET']
options.http_prefix = app.http_prefix if app.respond_to? :http_prefix
options.build_dir ||= app.build_dir if app.respond_to? :build_dir
if options.prefix
options.prefix = options.prefix.end_with?("/") ? options.prefix : options.prefix + "/"
options.prefix = "" if options.prefix == "/"
end
::Middleman::S3Sync.s3_sync_options = s3_sync_options
end
|
#caching_policy(content_type, policy = {}) ⇒ Object
147
148
149
|
# File 'lib/middleman-s3_sync/extension.rb', line 147
def caching_policy(content_type, policy = {})
::Middleman::S3Sync.add_caching_policy(content_type, policy)
end
|
#default_caching_policy(policy = {}) ⇒ Object
143
144
145
|
# File 'lib/middleman-s3_sync/extension.rb', line 143
def default_caching_policy(policy = {})
::Middleman::S3Sync.add_caching_policy(:default, policy)
end
|
#manipulate_resource_list(resources) ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/middleman-s3_sync/extension.rb', line 70
def manipulate_resource_list(resources)
::Middleman::S3Sync.mm_resources = resources.each_with_object([]) do |resource, list|
next if resource.ignored?
list << resource
list << resource.target_resource if resource.respond_to?(:target_resource)
end
resources
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.
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/middleman-s3_sync/extension.rb', line 125
def read_config(io = nil)
unless io
root_path = ::Middleman::Application.root
config_file_path = File.join(root_path, ".s3_sync")
return unless File.exist?(config_file_path)
io = File.open(config_file_path, "r")
end
config = (YAML.load(io) || {}).symbolize_keys
config.each do |key, value|
options[key.to_sym] = value
end
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
111
112
113
114
115
116
117
118
|
# File 'lib/middleman-s3_sync/extension.rb', line 111
def respond_to_missing?(method, include_private = false)
method_str = method.to_s
if method_str.end_with?('=')
option_name = method_str.chomp('=').to_sym
return options.respond_to?(option_name)
end
options.respond_to?(method) || super
end
|
#s3_sync_options ⇒ Object
81
82
83
|
# File 'lib/middleman-s3_sync/extension.rb', line 81
def s3_sync_options
self
end
|