anaconda 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41b78076d96d6575112497147272ed19f16fbcc3
4
- data.tar.gz: 3078b8a288c4e51ba7cf345b2ec289411f99ecf8
3
+ metadata.gz: 727ecb3cc6b44aed50ca4c56b309a0e0bf6846dc
4
+ data.tar.gz: 2192a007591dc147975a90346e3cb5ed9ef9bd94
5
5
  SHA512:
6
- metadata.gz: 14237951c90193befe07b5a22aa123061712fec7045517050b9013dd6c35599060a6694c79d2af885fd6a0e5305617c1554b2eb3d0e2e08e5983093258c22a0c
7
- data.tar.gz: 85875e215787fcd52bc0dff686f167db259936efe2395d3531d62a050950294bb15243663ab30d352ac5f3275ac38099e8a0e13c11b1dcdf125e14773952d302
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
- 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
-
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
- magic_url(checking_column)
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 magic_url(column_name)
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
- "https://s3.amazonaws.com/#{Anaconda.aws[:aws_bucket]}/#{send("#{column_name}_file_path")}"
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
@@ -1,5 +1,5 @@
1
1
  module Anaconda
2
2
  module Rails
3
- VERSION = "0.9.4"
3
+ VERSION = "0.9.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anaconda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McFadden