10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/anaconda/anaconda_for.rb', line 10
def anaconda_for( anaconda_column, options = {})
send :include, InstanceMethods
begin
self.anaconda_columns.present?
rescue NoMethodError
class_attribute :anaconda_columns
end
self.anaconda_columns = Array.new unless self.anaconda_columns.kind_of? Array
if self.anaconda_columns.include? anaconda_column.to_sym
raise AnacondaError, "anaconda_for cannot be called multiple times for the same field"
end
self.anaconda_columns << anaconda_column.to_sym
class_attribute
begin
self.anaconda_options.present?
rescue NoMethodError
class_attribute :anaconda_options
end
self.anaconda_options = Hash.new unless self.anaconda_options.kind_of? Hash
self.anaconda_options[anaconda_column.to_sym] = options.reverse_merge(
aws_access_key: Anaconda.aws[:aws_access_key],
aws_secret_key: Anaconda.aws[:aws_secret_key],
aws_bucket: Anaconda.aws[:aws_bucket],
aws_endpoint: Anaconda.aws[:aws_endpoint],
aws_use_path_style: Anaconda.aws[:path_style],
acl: "public-read",
max_file_size: 500.megabytes,
allowed_file_types: [],
base_key: "#{anaconda_column}_anaconda_default_base_key".to_sym,
host: false,
protocol: "http",
expiry_length: 1.hour,
remove_previous_s3_files_on_change: true,
remove_previous_s3_files_on_destroy: true
)
self.after_commit :anaconda_remove_previous_s3_files_on_change_or_destroy
end
|