anaconda 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.markdown +26 -12
- data/lib/anaconda/anaconda_for.rb +17 -4
- data/lib/anaconda/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 727ecb3cc6b44aed50ca4c56b309a0e0bf6846dc
|
4
|
+
data.tar.gz: 2192a007591dc147975a90346e3cb5ed9ef9bd94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fba2e3e944129fdee8ba065d3ab95af61949418bbf2f5a24b9367011f15fcf7e48d23bb1860649fc109382f46d20ce3113211b6469037d286d7c5231ff8b9615
|
7
|
+
data.tar.gz: 14a384f8e00452993c1db28e3177b4d126a77ef224eae4de628ca5d6029a956f6d5f406564d4d973cf0c09150b8013c3c5323e49b6b155f31976e75bab634136
|
data/README.markdown
CHANGED
@@ -94,18 +94,29 @@ We highly recommend the `figaro` gem [https://github.com/laserlemon/figaro](http
|
|
94
94
|
$ rails g anaconda:migration PostMedia asset
|
95
95
|
|
96
96
|
* Model setup
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
97
|
+
|
98
|
+
class PostMedia < ActiveRecord::Base
|
99
|
+
belongs_to :post
|
100
|
+
|
101
|
+
anaconda_for :asset, base_key: :asset_key
|
102
|
+
|
103
|
+
def asset_key
|
104
|
+
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
|
105
|
+
s = (0...24).map { o[rand(o.length)] }.join
|
106
|
+
"post_media/#{s}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
At this time the available options on anaconda_for are:
|
111
|
+
* `base_key` default: _%{plural model}/%{plural column}/%{random string}_
|
112
|
+
* `aws_access_key_id` default: _aws_access_key_ specified in Anaconda config
|
113
|
+
* `aws_secret_access_key` default: _aws_secret_key_ specified in Anaconda config
|
114
|
+
* `bucket` default: _aws_bucket_ specified in Anaconda config
|
115
|
+
* `acl` default _public-read_
|
116
|
+
* `max_file_size` default: `500.megabytes`
|
117
|
+
* `allowed_file_types` default: _all_
|
118
|
+
* `host` String. If specified, this will be used to access publically stored objects instead of the S3 bucket. Useful for CloudFront integration. Note: At this time privately stored objects will still be requested via S3. Default: _false_
|
119
|
+
* `protocol` `https`, `http`, or `:auto`. If `:auto`, `//` will be used as the protocol. Note: At this time, all privately stored objects are requested over https. Default: `http`
|
109
120
|
|
110
121
|
|
111
122
|
* Form setup
|
@@ -140,6 +151,9 @@ We highly recommend the `figaro` gem [https://github.com/laserlemon/figaro](http
|
|
140
151
|
The magic method is asset_url which will return a signed S3 URL if the file is stored with an ACL of `private` and will return a non-signed URL if the file is stored with public access.
|
141
152
|
|
142
153
|
## Changelog
|
154
|
+
* 0.9.5
|
155
|
+
* add `host` and `protocol` options to `anaconda_for`
|
156
|
+
|
143
157
|
* 0.9.4
|
144
158
|
* Fix uploads. Previous version broke them completely.
|
145
159
|
|
@@ -36,7 +36,9 @@ module Anaconda
|
|
36
36
|
acl: "public-read",
|
37
37
|
max_file_size: 500.megabytes,
|
38
38
|
allowed_file_types: [],
|
39
|
-
base_key: "#{self.to_s.pluralize.downcase}/#{anaconda_column.to_s.pluralize}/#{(0...32).map{(65+rand(26)).chr}.join.downcase}"
|
39
|
+
base_key: "#{self.to_s.pluralize.downcase}/#{anaconda_column.to_s.pluralize}/#{(0...32).map{(65+rand(26)).chr}.join.downcase}",
|
40
|
+
host: false,
|
41
|
+
protocol: "http"
|
40
42
|
)
|
41
43
|
end
|
42
44
|
end
|
@@ -52,7 +54,7 @@ module Anaconda
|
|
52
54
|
end
|
53
55
|
case checking_method
|
54
56
|
when :url
|
55
|
-
|
57
|
+
anaconda_url(checking_column)
|
56
58
|
else
|
57
59
|
super
|
58
60
|
end
|
@@ -62,14 +64,25 @@ module Anaconda
|
|
62
64
|
end
|
63
65
|
|
64
66
|
private
|
65
|
-
def
|
67
|
+
def anaconda_url(column_name)
|
66
68
|
return nil unless send("#{column_name}_file_path").present?
|
67
69
|
|
68
70
|
if send("#{column_name}_stored_privately")
|
69
71
|
aws = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => Anaconda.aws[:aws_access_key], :aws_secret_access_key => Anaconda.aws[:aws_secret_key]})
|
70
72
|
aws.get_object_https_url(Anaconda.aws[:aws_bucket], send("#{column_name}_file_path"), 1.hour.from_now)
|
73
|
+
elsif self.anaconda_options[column_name.to_sym][:host]
|
74
|
+
"#{anaconda_protocol(column_name)}#{self.anaconda_options[column_name.to_sym][:host]}/#{send("#{column_name}_file_path")}"
|
71
75
|
else
|
72
|
-
"
|
76
|
+
"#{anaconda_protocol(column_name)}s3.amazonaws.com/#{Anaconda.aws[:aws_bucket]}/#{send("#{column_name}_file_path")}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def anaconda_protocol(column_name)
|
81
|
+
case self.anaconda_options[column_name.to_sym][:protocol]
|
82
|
+
when :auto
|
83
|
+
"//"
|
84
|
+
else
|
85
|
+
"#{self.anaconda_options[column_name.to_sym][:protocol]}://"
|
73
86
|
end
|
74
87
|
end
|
75
88
|
end
|
data/lib/anaconda/version.rb
CHANGED